Mercurial > dive4elements > http-client
comparison src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java @ 90:8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 25 Sep 2013 10:30:12 +0200 |
parents | 133281653904 |
children | fcbfc6c597b1 |
comparison
equal
deleted
inserted
replaced
89:1866aa3a3bfc | 90:8bd13f10d555 |
---|---|
8 package org.dive4elements.artifacts.httpclient.http; | 8 package org.dive4elements.artifacts.httpclient.http; |
9 | 9 |
10 import java.io.InputStream; | 10 import java.io.InputStream; |
11 import java.io.IOException; | 11 import java.io.IOException; |
12 import java.io.OutputStream; | 12 import java.io.OutputStream; |
13 import java.io.OutputStreamWriter; | |
14 | |
15 import java.nio.charset.Charset; | |
16 | |
13 import java.util.ArrayList; | 17 import java.util.ArrayList; |
14 import java.util.List; | 18 import java.util.List; |
15 | 19 |
16 import org.apache.log4j.Logger; | 20 import org.apache.log4j.Logger; |
17 | 21 |
39 import org.dive4elements.artifacts.httpclient.utils.ArtifactProtocolUtils; | 43 import org.dive4elements.artifacts.httpclient.utils.ArtifactProtocolUtils; |
40 import org.dive4elements.artifacts.httpclient.utils.ArtifactCreator; | 44 import org.dive4elements.artifacts.httpclient.utils.ArtifactCreator; |
41 | 45 |
42 | 46 |
43 /** | 47 /** |
48 * Client to artifact-server. | |
44 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 49 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
45 */ | 50 */ |
46 public class HttpClientImpl implements HttpClient { | 51 public class HttpClientImpl implements HttpClient { |
47 | 52 |
48 private static final Logger logger = Logger.getLogger(HttpClient.class); | 53 private static final Logger logger = Logger.getLogger(HttpClient.class); |
73 public static final String PATH_OUT_COLLECTION = "/collection"; | 78 public static final String PATH_OUT_COLLECTION = "/collection"; |
74 | 79 |
75 private String serverUrl; | 80 private String serverUrl; |
76 | 81 |
77 private String localeString; | 82 private String localeString; |
83 | |
84 /** | |
85 * The Charset used for encoding the collectionOut output. | |
86 * If not set, the system/java default will be used (UTF-8). | |
87 */ | |
88 private Charset charset; | |
78 | 89 |
79 private static final ThreadLocal<Client> CLIENT = | 90 private static final ThreadLocal<Client> CLIENT = |
80 new ThreadLocal<Client>() { | 91 new ThreadLocal<Client>() { |
81 @Override | 92 @Override |
82 protected Client initialValue() { | 93 protected Client initialValue() { |
85 } | 96 } |
86 }; | 97 }; |
87 | 98 |
88 public HttpClientImpl(String serverUrl) { | 99 public HttpClientImpl(String serverUrl) { |
89 this.serverUrl = serverUrl; | 100 this.serverUrl = serverUrl; |
101 setEncoding(null); | |
102 } | |
103 | |
104 | |
105 /** | |
106 * Sets the encoding. | |
107 * | |
108 * Currently the encoding is only | |
109 * respected in the collectionOut-method! | |
110 * | |
111 * It was implemented to allow csv export to be in another than the | |
112 * sensible default (UTF-8) and allow easier integration | |
113 * e.g. in proprietary products. | |
114 */ | |
115 public void setEncoding(Charset charset) { | |
116 this.charset = charset; | |
90 } | 117 } |
91 | 118 |
92 | 119 |
93 /** | 120 /** |
94 * This constructor might be used to modify the request's locale manually. | 121 * This constructor might be used to modify the request's locale manually. |
407 } | 434 } |
408 } | 435 } |
409 | 436 |
410 | 437 |
411 /** | 438 /** |
412 * This method triggers the out() operation of a Collection. The result of | 439 * Write out() operation of a Collection to <i>out</i>. |
413 * this operation is written to <i>out</i> directly - there is no return | |
414 * value. | |
415 * | 440 * |
416 * @param doc The request document for the out() operation. | 441 * @param doc The request document for the out() operation. |
417 * @param uuid The identifier of the Collection. | 442 * @param uuid The identifier of the Collection. |
418 * @param type The name of the output type. | 443 * @param type The name of the output type. |
419 * @param out The OutputStream. | 444 * @param out The OutputStream. |