4242import org .apache .http .impl .conn .SingleClientConnManager ;
4343import org .apache .http .impl .conn .tsccm .ThreadSafeClientConnManager ;
4444import org .apache .http .params .HttpConnectionParams ;
45- import org .apache .http .protocol .BasicHttpProcessor ;
4645import org .apache .http .protocol .HTTP ;
4746import org .apache .http .protocol .HttpContext ;
4847
@@ -78,14 +77,10 @@ public class HttpComponentsMessageSender extends AbstractHttpWebServiceMessageSe
7877 * default {@link SingleClientConnManager}.
7978 */
8079 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 ;
8984 setConnectionTimeout (DEFAULT_CONNECTION_TIMEOUT_MILLISECONDS );
9085 setReadTimeout (DEFAULT_READ_TIMEOUT_MILLISECONDS );
9186 }
@@ -226,7 +221,19 @@ public WebServiceConnection createConnection(URI uri) throws IOException {
226221 httpPost .addHeader (HttpTransportConstants .HEADER_ACCEPT_ENCODING ,
227222 HttpTransportConstants .CONTENT_ENCODING_GZIP );
228223 }
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 ;
230237 }
231238
232239 public void destroy () throws Exception {
@@ -238,7 +245,7 @@ public void destroy() throws Exception {
238245 * {@code Transfer-Encoding} headers from the request. Necessary, because SAAJ and other SOAP implementations set these
239246 * headers themselves, and HttpClient throws an exception if they have been set.
240247 */
241- private static class ProtocolExceptionOverrideInterceptor implements HttpRequestInterceptor {
248+ private static class RemoveSoapHeadersInterceptor implements HttpRequestInterceptor {
242249
243250 public void process (HttpRequest request , HttpContext context ) throws HttpException , IOException {
244251 if (request instanceof HttpEntityEnclosingRequest ) {
0 commit comments