How can I make jaxws parse response without checking Content-Type header
Asked Answered
O

1

2

I am calling a soap webservice via jax ws client code (generated from wsdl). But the service sends response with "Content-Type:text/html" where as the jax-ws implementation requires "text/xml" type. The webservice folk won't change the response header.

Exception is :

com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 200: OK at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:266) ~[?:1.8.0_171] at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:217) ~[?:1.8.0_171] at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:130) ~[?:1.8.0_171] at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:124) ~[?:1.8.0_171]

Also tried with Saaj Implementation. It also mandates response Content-Type header to be text/xml. Here is the exception with saaj :

Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response? at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(MessageImpl.java:655) ~[?:1.8.0_171] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

Is there a way to make jaxws ignore response header and continue parsing?

Overactive answered 13/6, 2018 at 16:18 Comment(7)
What type of application server are you running on and whats the version? E.g. websphere, glassfish, JBoss or Tomcat?Woody
spring boot with embedded tomcat. I can't parse response from a webservice I call in the code because it's returning wrong soap content type : test/htmlOveractive
Whats the tomcat version?Woody
tomcat-embed-core-8.5.29.jar:8.5.29Overactive
You should be able to use an CXF interceptor or JAX-WS handler though I know overly complicated for your needs but likely your only choice how do i modify http headers for a jax-ws response in cxf if you go the JAX-WS route, I have more experience with it as currently using it in project!Woody
Thanks @JGlass. Will try that option and get backOveractive
Thanks @JGlass. I checked CXF. Wrote as an answer what made it work. ThanksOveractive
O
2

Didn't exactly find a solution with jax-ws but thanks to @JGlass found a pleasantly simple solution with apache cfx. Very flexible implementation of jax-ws. In love with it. Here is the simple code that made it work :

    Client client = ClientProxy.getClient(port);
    client.getInInterceptors().add(new AbstractPhaseInterceptor<org.apache.cxf.message.Message>(Phase.RECEIVE) {
        public void handleMessage(org.apache.cxf.message.Message message) {
            message.put(org.apache.cxf.message.Message.CONTENT_TYPE, "text/xml");
        }
    });
Overactive answered 14/6, 2018 at 18:4 Comment(3)
Awesome you got it working - glad I could help point you in the right direction!Woody
@Woody this looks like a very clean solution! I have taken the liberty to include this in my write-up on this subject, and created a fully working example client on my github: github.com/s-lindenau/SoapContentTypeDemo/tree/master/…Implicate
@slindenau, nice write up and good job contributing on GIT, I am sure it may help many with similar problems!!Woody

© 2022 - 2024 — McMap. All rights reserved.