Announcement Announcement Module
Collapse
No announcement yet.
Spring WS - HttpClient4 - getting org.apache.http.client.ClientProtocolException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring WS - HttpClient4 - getting org.apache.http.client.ClientProtocolException

    Hi,

    I am trying to invoke a Spring webservice using Spring WS and HttpClient 4 API. Though my code works fine with httpClient 3, with 4, I am getting org.apache.http.client.ClientProtocolException. Below is the code that creates the HttpClient and uses the client object in WebserviceTemplate object.

    Any pointers on this would be highly appreciated.

    <code>
    private HttpClient buildHttpClient() {
    HttpClientBuilder builder = HttpClientBuilder.create();
    HttpRequestRetryHandler retryHandler = new StandardHttpRequestRetryHandler(2, true);
    builder.setRetryHandler(retryHandler);

    Credentials creds = new UsernamePasswordCredentials("prasun", "prasun");
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, creds);
    builder.setDefaultCredentialsProvider(credentialsP rovider);
    return builder.build();
    }
    </code> Am I missing anything in the above method?
    in my caller:

    <code>
    final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
    webServiceTemplate.setDefaultUri(poolableService.g etEndpointURL());
    final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    HashMap<String, Object> prop = new HashMap<String, Object>();
    prop.put(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.setMarshallerProperties(prop);
    marshaller.setContextPath(poolableService.getConte xtPath());
    webServiceTemplate.setMarshaller(marshaller);
    webServiceTemplate.setUnmarshaller(marshaller);

    HttpClient httpClient = buildHttpClient();
    HttpComponentsMessageSender messageSender = new HttpComponentsMessageSender(httpClient);
    webServiceTemplate.setMessageSender(messageSender) ;
    webServiceTemplate.setCheckConnectionForFault(true );
    </code>

    then,
    <code>
    element = (JAXBElement<AddressResponse>) template.marshalSendAndReceive(request);
    </code>

    error trace:
    <code>
    org.springframework.ws.client.WebServiceIOExceptio n: I/O error: null; nested exception is org.apache.http.client.ClientProtocolException
    at org.springframework.ws.client.core.WebServiceTempl ate.sendAndReceive(WebServiceTemplate.java:543)
    at org.springframework.ws.client.core.WebServiceTempl ate.marshalSendAndReceive(WebServiceTemplate.java: 384)
    at org.springframework.ws.client.core.WebServiceTempl ate.marshalSendAndReceive(WebServiceTemplate.java: 378)
    at org.springframework.ws.client.core.WebServiceTempl ate.marshalSendAndReceive(WebServiceTemplate.java: 370)
    at com.prasun.webservice.client.service.QueryAddressS ervice.<init>(QueryAddressService.java:35)
    at com.prasun.webservice.client.main.ServiceClient.ex ecuteQueryAddressServiceClient(ServiceClient.java: 53)
    at com.prasun.webservice.client.main.ServiceClient.ma in(ServiceClient.java:70)
    Caused by: org.apache.http.client.ClientProtocolException
    at org.apache.http.impl.client.InternalHttpClient.doE xecute(InternalHttpClient.java:188)
    at org.apache.http.impl.client.CloseableHttpClient.ex ecute(CloseableHttpClient.java:82)
    at org.apache.http.impl.client.CloseableHttpClient.ex ecute(CloseableHttpClient.java:106)
    at org.apache.http.impl.client.CloseableHttpClient.ex ecute(CloseableHttpClient.java:57)
    at org.springframework.ws.transport.http.HttpComponen tsConnection.onSendAfterWrite(HttpComponentsConnec tion.java:119)
    at org.springframework.ws.transport.AbstractWebServic eConnection.send(AbstractWebServiceConnection.java :47)
    at org.springframework.ws.client.core.WebServiceTempl ate.sendRequest(WebServiceTemplate.java:622)
    at org.springframework.ws.client.core.WebServiceTempl ate.doSendAndReceive(WebServiceTemplate.java:585)
    at org.springframework.ws.client.core.WebServiceTempl ate.sendAndReceive(WebServiceTemplate.java:537)
    ... 6 more
    Caused by: org.apache.http.ProtocolException: Content-Length header already present
    at org.apache.http.protocol.RequestContent.process(Re questContent.java:95)
    at org.apache.http.protocol.ImmutableHttpProcessor.pr ocess(ImmutableHttpProcessor.java:131)
    at org.apache.http.impl.execchain.ProtocolExec.execut e(ProtocolExec.java:192)
    at org.apache.http.impl.execchain.RetryExec.execute(R etryExec.java:85)
    at org.apache.http.impl.execchain.RedirectExec.execut e(RedirectExec.java:108)
    at org.apache.http.impl.client.InternalHttpClient.doE xecute(InternalHttpClient.java:186)
    ... 14 more
    </code>

  • #2
    Sorry for not getting to this sooner. We are in the process of moving to StackOverflow for our forums.

    This question is probably a better candidate for StackOverflow, perhaps against the #spring-ws tag.
    If you do post it there, please reply here with the link.
    Thanks!

    Comment

    Working...
    X