Cannot process the message because the content type ‘application/soap+xml; charset=utf-8’ was not the expected type ‘text/xml; charset=utf-8’

PROBLEM

You are getting this exception when invoking a web service:-

org.springframework.ws.client.WebServiceTransportException: Cannot process the message because the content type ‘application/soap+xml; charset=utf-8’ was not the expected type ‘text/xml; charset=utf-8’. [415]

SOLUTION

You are using the wrong SOAP version. SOAP v1.1 uses text/xml while SOAP v1.2 uses application/soap+xml.

If you are using Spring Web Services, add the following lines:-

<!--?xml version="1.0" encoding="UTF-8"?-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:oxm="http://www.springframework.org/schema/oxm" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd">

	<!-- Configure the SOAP version to 1.1 -->
    <bean id="soapMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
        <property name="soapVersion">
            <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_11">
        </util:constant></property>
    </bean>

    <oxm:jaxb2-marshaller id="marshaller" contextpath="myproject.wsdl.ws">

    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <constructor-arg ref="soapMessageFactory">
        <property name="marshaller" ref="marshaller">
        <property name="unmarshaller" ref="marshaller">
        <property name="defaultUri" value="http://my.web.service?wsdl">
    </property></property></property></constructor-arg></bean>
</oxm:jaxb2-marshaller></beans>

Comments

Leave a Reply

Your email address will not be published.