1
votes

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?

1
What type of application server are you running on and whats the version? E.g. websphere, glassfish, JBoss or Tomcat?JGlass
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/htmlDavid John
Whats the tomcat version?JGlass
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!JGlass
Thanks @JGlass. I checked CXF. Wrote as an answer what made it work. ThanksDavid John

1 Answers

1
votes

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");
        }
    });