// 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() == null) {
// This is not necessarily a problem; log it and make sure not to NPE
if (log.isDebugEnabled()) {
log.debug(" Not added to transport header. header =" + key +
" because value is null;");
}
}
else if (entry.getValue() instanceof String) {
// Normally there is one value per key
if (log.isDebugEnabled()) {
log.debug(" add transport header. header =" + key +
" value = " + entry.getValue());
}
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++) {
if (log.isDebugEnabled()) {
log.debug(" add transport header. header =" + key +
" value = " + values[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
String ctValue = contentType +"; charset=UTF-8";
defaultHeaders.setHeader("Content-type", ctValue);
if (log.isDebugEnabled()) {
log.debug(" setContentType =" + ctValue);
}
SOAPMessage soapMessage = mf.createMessage(defaultHeaders, inStream);