From d2f4ba5e8eacc42152fc31d13ea9e52a61d60149 Mon Sep 17 00:00:00 2001 From: Erik van Konijnenburg Date: Sat, 22 Jun 2013 14:24:57 +0200 Subject: [PATCH] HttpComponentsMessageSender inintuitive constructor HttpComponentsMessageSender has two constructors, with and without HttpClient, and the one with HttpClient omits adding a SoapRemoveHeaderInterceptor. This breaks in org.apache.http.protocol.RequestContent with new ProtocolException("Content-Length header already present"), but only in some containers (oc4j) and not in others (jetty, eclipe); this makes the issue hard to debug. Adding a note to the javadoc would help the developer pick the proper constructor to avoid this issue. Issue: SWS-835 --- .../http/HttpComponentsMessageSender.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/springframework/ws/transport/http/HttpComponentsMessageSender.java b/core/src/main/java/org/springframework/ws/transport/http/HttpComponentsMessageSender.java index e0ed6555..df579cf7 100644 --- a/core/src/main/java/org/springframework/ws/transport/http/HttpComponentsMessageSender.java +++ b/core/src/main/java/org/springframework/ws/transport/http/HttpComponentsMessageSender.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,11 +21,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Map; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.util.Assert; -import org.springframework.ws.transport.WebServiceConnection; - import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpException; import org.apache.http.HttpHost; @@ -45,6 +40,11 @@ import org.apache.http.params.HttpConnectionParams; import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HttpContext; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; +import org.springframework.ws.transport.WebServiceConnection; + /** * {@code WebServiceMessageSender} implementation that uses Apache * HttpClient to execute POST requests. @@ -86,7 +86,13 @@ public class HttpComponentsMessageSender extends AbstractHttpWebServiceMessageSe } /** - * Create a new instance of the HttpClientMessageSender with the given {@link HttpClient} instance. + * Create a new instance of the {@code HttpClientMessageSender} with the given + * {@link HttpClient} instance. + *

+ * This constructor does not change the given {@code HttpClient} in any way. As such, + * it does not set timeouts, nor does it + * {@linkplain DefaultHttpClient#addRequestInterceptor(org.apache.http.HttpRequestInterceptor) add} + * the {@link RemoveSoapHeadersInterceptor}. * * @param httpClient the HttpClient instance to use for this sender */ @@ -242,10 +248,10 @@ public class HttpComponentsMessageSender extends AbstractHttpWebServiceMessageSe /** * HttpClient {@link org.apache.http.HttpRequestInterceptor} implementation that removes {@code Content-Length} and - * {@code Transfer-Encoding} headers from the request. Necessary, because SAAJ and other SOAP implementations set these + * {@code Transfer-Encoding} headers from the request. Necessary, because some SAAJ and other SOAP implementations set these * headers themselves, and HttpClient throws an exception if they have been set. */ - private static class RemoveSoapHeadersInterceptor implements HttpRequestInterceptor { + public static class RemoveSoapHeadersInterceptor implements HttpRequestInterceptor { public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { if (request instanceof HttpEntityEnclosingRequest) {