// Create soapMessage object from Message Factory using the input
// stream created from OM.
// Get the MimeHeaders from the transportHeaders map
MimeHeaders defaultHeaders = new MimeHeaders();
if (transportHeaders != null) {
Iterator it = transportHeaders.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String key = (String) entry.getKey();
if (entry.getValue() instanceof String) {
// Normally there is one value per key
defaultHeaders.addHeader(key, (String) entry.getValue());
} else {
// There may be multiple values for each key. This code
// assumes the value is an array of String.
String values[] = (String[]) entry.getValue();
for (int i=0; i<values.length; i++) {
defaultHeaders.addHeader(key, values[i]);
}
}
}
}
// Toggle based on SOAP 1.1 or SOAP 1.2
String contentType = null;
if (ns.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE)) {
contentType = SOAPConstants.SOAP_1_1_CONTENT_TYPE;
} else {
contentType = SOAPConstants.SOAP_1_2_CONTENT_TYPE;
}
// Override the content-type
defaultHeaders.setHeader("Content-type", contentType +"; charset=UTF-8");
SOAPMessage soapMessage = mf.createMessage(defaultHeaders, inStream);
// At this point the XMLPart is still an OMElement.
// We need to change it to the new SOAPEnvelope.
createXMLPart(soapMessage.getSOAPPart().getEnvelope());