Search code examples
soapjax-ws

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


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?


Solution

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