Spring WS Invalid Content Type

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.


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:


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.


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


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" />

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.

Need Your Help

How does rspec work with Rails 3 for integration tests?

ruby-on-rails rspec integration-testing ruby-on-rails-3 webrat

What I'm trying to ahieve is to do integration tests with webrat in rails3 like Yehuda does with test-unit in http://pivotallabs.com/talks/76-extending-rails-3 minute 34.

ThreadPool SetMaxThreads and SetMinThreads Magic Number

c# threadpool

Is there a magic number or formula for setting the values of SetMaxThreads and SetMinThreads for ThreadPool? I have thousands of long-running methods that need execution but just can't find the pe...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.