42
42
import org .apache .http .impl .conn .SingleClientConnManager ;
43
43
import org .apache .http .impl .conn .tsccm .ThreadSafeClientConnManager ;
44
44
import org .apache .http .params .HttpConnectionParams ;
45
- import org .apache .http .protocol .BasicHttpProcessor ;
46
45
import org .apache .http .protocol .HTTP ;
47
46
import org .apache .http .protocol .HttpContext ;
48
47
@@ -78,14 +77,10 @@ public class HttpComponentsMessageSender extends AbstractHttpWebServiceMessageSe
78
77
* default {@link SingleClientConnManager}.
79
78
*/
80
79
public HttpComponentsMessageSender () {
81
- httpClient = new DefaultHttpClient (new ThreadSafeClientConnManager ()) {
82
- @ Override
83
- protected BasicHttpProcessor createHttpProcessor () {
84
- BasicHttpProcessor processor = super .createHttpProcessor ();
85
- processor .addInterceptor (new ProtocolExceptionOverrideInterceptor (), 0 );
86
- return processor ;
87
- }
88
- };
80
+ DefaultHttpClient defaultClient = new DefaultHttpClient (new ThreadSafeClientConnManager ());
81
+ defaultClient .addRequestInterceptor (new RemoveSoapHeadersInterceptor (), 0 );
82
+
83
+ this .httpClient = defaultClient ;
89
84
setConnectionTimeout (DEFAULT_CONNECTION_TIMEOUT_MILLISECONDS );
90
85
setReadTimeout (DEFAULT_READ_TIMEOUT_MILLISECONDS );
91
86
}
@@ -226,7 +221,19 @@ public WebServiceConnection createConnection(URI uri) throws IOException {
226
221
httpPost .addHeader (HttpTransportConstants .HEADER_ACCEPT_ENCODING ,
227
222
HttpTransportConstants .CONTENT_ENCODING_GZIP );
228
223
}
229
- return new HttpComponentsConnection (getHttpClient (), httpPost );
224
+ HttpContext httpContext = createContext (uri );
225
+ return new HttpComponentsConnection (getHttpClient (), httpPost , httpContext );
226
+ }
227
+
228
+ /**
229
+ * Template method that allows for creation of a {@link HttpContext} for the given uri. Default implementation
230
+ * returns {@code null}.
231
+ *
232
+ * @param uri the URI to create the context for
233
+ * @return the context, or {@code null}
234
+ */
235
+ protected HttpContext createContext (URI uri ) {
236
+ return null ;
230
237
}
231
238
232
239
public void destroy () throws Exception {
@@ -238,7 +245,7 @@ public void destroy() throws Exception {
238
245
* {@code Transfer-Encoding} headers from the request. Necessary, because SAAJ and other SOAP implementations set these
239
246
* headers themselves, and HttpClient throws an exception if they have been set.
240
247
*/
241
- private static class ProtocolExceptionOverrideInterceptor implements HttpRequestInterceptor {
248
+ private static class RemoveSoapHeadersInterceptor implements HttpRequestInterceptor {
242
249
243
250
public void process (HttpRequest request , HttpContext context ) throws HttpException , IOException {
244
251
if (request instanceof HttpEntityEnclosingRequest ) {
0 commit comments