}
}
@Override
public void writeTo(OutputStream outputStream) throws IOException {
MimeHeaders mimeHeaders = getSaajMessage().getMimeHeaders();
if (ObjectUtils.isEmpty(mimeHeaders.getHeader(TransportConstants.HEADER_ACCEPT))) {
mimeHeaders.setHeader(TransportConstants.HEADER_ACCEPT, getVersion().getContentType());
}
try {
SOAPMessage message = getSaajMessage();
message.saveChanges();
if (outputStream instanceof TransportOutputStream) {
TransportOutputStream transportOutputStream = (TransportOutputStream) outputStream;
// some SAAJ implementations (Axis 1) do not have a Content-Type header by default
MimeHeaders headers = message.getMimeHeaders();
if (ObjectUtils
.isEmpty(
headers.getHeader(TransportConstants.HEADER_CONTENT_TYPE))) {
SOAPEnvelope envelope1 = message.getSOAPPart().getEnvelope();
if (envelope1.getElementQName().getNamespaceURI()
.equals(SoapVersion.SOAP_11.getEnvelopeNamespaceUri())) {
headers.addHeader(TransportConstants.HEADER_CONTENT_TYPE, SoapVersion.SOAP_11.getContentType());
}
else {
headers.addHeader(TransportConstants.HEADER_CONTENT_TYPE, SoapVersion.SOAP_12.getContentType());
}
message.saveChanges();
}
for (Iterator<?> iterator = headers.getAllHeaders(); iterator.hasNext();) {
MimeHeader mimeHeader = (MimeHeader) iterator.next();
transportOutputStream.addHeader(mimeHeader.getName(), mimeHeader.getValue());
}
}
message.writeTo(outputStream);