Can't get Spring SOAP Client to work: content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'

Can't get Spring SOAP Client to work: content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'

can definition
can synonym
can noun meaning
can band
can verb
can y

Hi, I am trying to make a simple soap client work using Spring-ws. The googling I've done on this error says I'm using Soap 1.1 and need to specify Soap 1.2. I've tried to do that. Am I doing it correctly below? If this is not the problem does anybody see what the problem is?

Here's a chunk of the stack trace: Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'. [415]
    at com.jda.fileserver.FujiAuthenticationTest.testLogin(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(

Here's my code, thanks for trying to help:

public class AuthTest {
public void testLogin() throws Exception {
        StringBuffer loginXml = new StringBuffer();
        loginXml.append("<soapenv:Envelope xmlns:soapenv=\"\" xmlns:ns=\"\">");
        loginXml.append("  <soapenv:Header>");
        loginXml.append("    <ns:loginOperationDetails>");
        loginXml.append("    </ns:loginOperationDetails>");
        loginXml.append("  </soapenv:Header>");
        loginXml.append("  <soapenv:Body>");
        loginXml.append("    <ns:LogIn>");
        loginXml.append("      <ns:logInInfo>");
        loginXml.append("        <ns:CustomerAccountId>customer1</ns:CustomerAccountId>");
        loginXml.append("        <ns:Username>jsmith</ns:Username>");
        loginXml.append("        <ns:Password>abc123</ns:Password>");
        loginXml.append("      </ns:logInInfo>");
        loginXml.append("    </ns:LogIn>");
        loginXml.append("  </soapenv:Body>");

        WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
        SaajSoapMessageFactory defaultMessageFactory = (SaajSoapMessageFactory) webServiceTemplate.getMessageFactory();
        webServiceTemplate.setMessageFactory(defaultMessageFactory); // probably not needed

        StreamSource source = new StreamSource(new StringReader(loginXml.toString()));
        StreamResult result = new StreamResult(System.out);
        String uri = "";
        SoapActionCallback requestCallback = new SoapActionCallback("");
        try {
            webServiceTemplate.sendSourceAndReceiveToResult(uri, source, requestCallback, result);
        catch (SoapFaultException sfe) {
            throw new Exception("SoapFaultException", sfe);
        catch (WebServiceTransportException wste) {
            throw new Exception("WebServiceTransportException", wste);

Ok, I fixed the above problem, which gets me to another problem. First here's how I fixed the above problem. Now I don't set the SOAP version on the SaajSoapMessageFactory, I set it on the wrapped MessageFactory. Now the Content-Type going out in my request is application/soap+xml.

WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SaajSoapMessageFactory newSoapMessageFactory = new SaajSoapMessageFactory(msgFactory);

Next problem, now I'm getting this: Unexpected fault in the service.

and here's the info that was returned in the response:

500 Internal Server Error
The SOAP action specified on the message, '', does not match the HTTP SOAP Action, ''.

I'll try to solve this, but wanted to update anybody reading this so they can stop looking into the previous error. I need to figure out how to correctly set the soap action.

Can, Can was the leading avant-garde rock group of the 70s. Can experimented with noise, synthesizers, non-traditional music, cut-and-paste techniques, and, most  Can definition, to be able to; have the ability, power, or skill to: She can solve the problem easily, I'm sure. See more.

Please use the below code to change the header content type to text/xml;charset=utf-8 in Spring webservice template marshallSendAndReceive method.

  WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.marshalSendAndReceive(url, request, new WebServiceMessageCallback() {

                public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
                    SaajSoapMessage soapMessage = (SaajSoapMessage) message;
                    MimeHeaders headers = soapMessage.getSaajMessage().getMimeHeaders();
                    headers.addHeader(TransportConstants.HEADER_CONTENT_TYPE, "text/xml;charset=utf-8");

The Official CAN / Spoon Records Website, Can may refer to: Contents. 1 Containers; 2 Music; 3 Other; 4 See also. Containers[edit]. Aluminum can · Drink can · Oil can · Steel and tin cans · Trash can  Define can. can synonyms, can pronunciation, can translation, English dictionary definition of can. to be able to, have the power or skill to: I can take a bus to the

For adding soapheader with action and to tags, below code is working fine for me.

public void doWithMessage(WebServiceMessage message) throws IOException {
    SaajSoapMessage soapMessage = (SaajSoapMessage) message;

    SoapEnvelope soapEnvelope = soapMessage.getEnvelope();
    SoapHeader soapHeader = soapEnvelope.getHeader();

    //Initialize QName for Action and To
    QName action = new QName("{uri}", "Action", "{actionname}");
    QName to = new QName("{uri}", "To", "{actionname}");

    soapHeader.addNamespaceDeclaration("{actionname}", "{uri}");

    SoapHeaderElement soapHeaderElementAction = soapHeader.addHeaderElement(action);
    SoapHeaderElement soapHeaderElementTo = soapHeader.addHeaderElement(to);

    soapHeaderElementAction.setText("{text inside the tags}");

    soapHeaderElementTo.setText("{text inside the tags}");

    soapMessage.setSoapAction("{add soap action uri}");



Can, Can (stylised as CAN) was a German experimental rock band formed in Cologne in 1968 by the core quartet of Holger Czukay (bass, tape editing), Irmin  110 synonyms of can from the Merriam-Webster Thesaurus, plus 97 related words, definitions, and antonyms. Find another word for can. Can: to bring (as an action or operation) to an immediate end.

Can (band), VerbEdit. can (third-person singular simple present can, present participle -, simple past could, past participle (obsolete except in adjectival use) couth). A Controller Area Network (CAN bus) is a robust vehicle bus standard designed to allow microcontrollers and devices to communicate with each other's applications without a host computer. It is a message-based protocol , designed originally for multiplex electrical wiring within automobiles to save on copper, but can also be used in many other

can, can meaning: 1. to be able to: 2. used to say that you can and will do something: 3. to be allowed to: . Learn more. Can(stylised as CAN) was a German experimental rockband formed in Colognein 1968 by the core quartet of Holger Czukay(bass, tape editing), Irmin Schmidt(keyboards), Michael Karoli(guitar), and Jaki Liebezeit(drums).

CAN, 1.4Used to indicate that something is typically the case. 'antique clocks can seem out of place in modern homes'. More example sentences. We would like to show you a description here but the site won’t allow us.