Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring WS Invalid Content Type

Tags:

types

spring

I have a Spring WS client. I generated the WSDL stubs via wsimport.

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

SEVERE: SAAJ0537: Invalid Content-Type. Could be an error message instead of a SOAP message Exception in thread "main" org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?; 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 an indication that the message I sent has an invalid content-type or the response I receive has an invalid content-type? If it's on the client side, how do I set up the content-type?

I tried mocking the web service via Soap UI. I'm able to send and receive correct response.

Edit:

On my log, it's shown that the request is sent:

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

Then I get that exception:

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

like image 903
chris Avatar asked Dec 03 '10 22:12

chris


1 Answers

Problem solved.

It turns out I was NOT sending any SOAP content. The SOAP header is set correctly. But the SOAP body is empty. To resolve the issue I had to attach the content that I'm 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 mistake was overlooked by me because I was focus on porting an AXIS 1.x client implementation to a Spring WS implementation.

Some people, including Arjen Poustma, suggested to use tcpmon to sniff what's being sent. I didn't manage to configure and run it correctly (that's another unrelated issue). But this gave me an idea to inspect first what's being sent by my application.

I looked around and saw a similar problem in the Spring Forums about the invalid content type at WS Client using JAXB for marshalling. The last poster suggested to use the CommonsHttpMessageSender, just like the example he provided at Web Service Client with Spring-WS (which is a good one). With the CommonsHttpMessageSender it was able to print out my whole SOAP envelope:

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

I'm documenting here my experiences because I know one day there will be another guy like me who will be having this same problem.

like image 186
chris Avatar answered Sep 20 '22 01:09

chris