Spring Invalid WS Content Type

I have a Spring WS client. I created WSDL stubs through wsimport.

When I try to send a request, I get an Invalid Content-type exception:

SEVERE: SAAJ0537: Invalid content type. There may be an error message instead of a SOAP message. Exception in the stream "main" org.springframework.ws.soap.SoapMessageCreationException: could not create a message from InputStream: Invalid Content-Type: text / html. Is this an error message instead of a SOAP response ?; The nested exception is com.sun.xml.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type: text / html. Is this an error message instead of a SOAP response?

Is this a sign that the sent message has an invalid content type or is the response I receive an invalid content type? If this is client-side, how do I customize the content type?

I tried to taunt the web service through the Soap interface. I can send and receive the correct answer.

Edit:

My log shows that the request has been sent:

DEBUG [org.springframework.ws.client.MessageTracing.sent] - sent request

Then I get this exception:

Exception in thread "main" org.springframework.ws.soap.SoapMessageCreationException:

+4
source share
1 answer

The problem is resolved.

Turns out I did NOT post SOAP content. The SOAP header is configured correctly. But the SOAP body is empty. To solve this problem, I had to attach the content I am requesting.

Before:

GetDeletedRequest request = new GetDeletedRequest(); JAXBElement res = (JAXBElement) webServiceTemplate.marshalSendAndReceive(request, new WebServiceMessageCallback() {...} 

After:

 GetDeletedRequest request = new GetDeletedRequest(); request.setGetDeletedFilter(deleteFilter); // This is the content that I'm missing! JAXBElement res = (JAXBElement) webServiceTemplate.marshalSendAndReceive(request, new WebServiceMessageCallback() {...} 

This error was missed by me because I focused on porting the implementation of the AXIS 1.x client to the Spring WS implementation.

Some people, including Arien Pustma, have suggested using tcpmon to sniff what is sent. I was unable to configure and run it correctly (this is another unrelated issue). But it gave me an idea to first check what was sent by my application.

I looked around and saw a similar problem in the Spring forums about invalid content type in WS Client using JAXB for sorting . The last poster suggested using CommonsHttpMessageSender, like the example that he provided in the web service client with Spring -WS (which is good). With CommonsHttpMessageSender, he was able to print the entire SOAP envelope:

 <property name="messageSender"> <bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender" /> </property> 

I am documenting my experiences here because one day I know that there will be a guy like me who will have the same problem.

+5
source

All Articles