title: Java SOAP Message Content Type
body: <p>I used maven wsimport and Java 1.7 generated the SOAP client side code.
  the WSDL was given by the customer, I believe its a .NET backed SOAP server.</p>
  
  <p>After calling the service, I am keep getting a error like:     </p>
  
  <blockquote>
    <p>The server sent HTTP status code 415: Cannot process the message
    because the content type 'application/soap+xml; charset=utf-8; was not
    the expected type 'text/xml; charset=utf-8'.</p>
  </blockquote>
  
  <p>I am trying to modify the MimeHeader in the SOAPMessage class though a customised handler (and I did register the handler to the chain correctly):</p>
  
  <pre><code>MimeHeaders mimeHeaders = msg.getMimeHeaders();
  mimeHeaders.removeAllHeaders();
  mimeHeaders.removeHeader("Content-Type");
  mimeHeaders.addHeader(HttpHeaders.CONTENT_TYPE, "text/xml; charset=utf-8");
  </code></pre>
  
  <p>the above code seems doesn't change anything inside the mimiHeaders, the vector object seems to be immutable....</p>
  
  <p>then I created the SOAP message manually</p>
  
  <pre><code>  MessageFactory newInstance = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
    MimeHeaders he = new MimeHeaders();
    he.addHeader("Content-Type", "text/xml; charset=utf-8");
    String ss = "&lt;x:Envelope&gt;xxxxx&lt;/x:Envelope&gt;";
    InputStream in = new ByteArrayInputStream(ss.getBytes(StandardCharsets.UTF_8));
  
    SOAPMessage createMessage = newInstance.createMessage(he, in);
    createMessage.writeTo(System.out);  
    context.setMessage(createMessage);
    msg.saveChanges();
  </code></pre>
  
  <p>this time the mimeHeader and Content-Type on the SOAPMessage itself both set to 
  text/xml; charset=utf-8</p>
  
  <p>but the server still through the same error 415 application/soap+xml is not expected......</p>
  
  <p>I understand the server seems follows SOAP 1.1 thats why its expecting text/xml... but when I created the factory I clearly specified the protocol to 1.1 and manually set the mimeHeader. I am confused really </p>
  
  <p>Note: using SOAPUI or PostMan is absolutely fine, the problem only happens when using a wsimport generated java client </p>