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.
After calling the service, I am keep getting a error like:
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'.
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):
MimeHeaders mimeHeaders = msg.getMimeHeaders();
mimeHeaders.removeAllHeaders();
mimeHeaders.removeHeader("Content-Type");
mimeHeaders.addHeader(HttpHeaders.CONTENT_TYPE, "text/xml; charset=utf-8");
the above code seems doesn't change anything inside the mimiHeaders, the vector object seems to be immutable....
then I created the SOAP message manually
MessageFactory newInstance = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
MimeHeaders he = new MimeHeaders();
he.addHeader("Content-Type", "text/xml; charset=utf-8");
String ss = "<x:Envelope>xxxxx</x:Envelope>";
InputStream in = new ByteArrayInputStream(ss.getBytes(StandardCharsets.UTF_8));
SOAPMessage createMessage = newInstance.createMessage(he, in);
createMessage.writeTo(System.out);
context.setMessage(createMessage);
msg.saveChanges();
this time the mimeHeader and Content-Type on the SOAPMessage itself both set to text/xml; charset=utf-8
but the server still through the same error 415 application/soap+xml is not expected......
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
Note: using SOAPUI or PostMan is absolutely fine, the problem only happens when using a wsimport generated java client