public void writeTo(OutputStream outputStream) throws IOException {
try {
OMOutputFormat outputFormat = getOutputFormat();
if (outputStream instanceof TransportOutputStream) {
TransportOutputStream transportOutputStream = (TransportOutputStream) outputStream;
String contentType = outputFormat.getContentType();
if (!(outputFormat.isDoingSWA() || outputFormat.isOptimized())) {
String charsetEncoding = axiomMessage.getCharsetEncoding();
contentType += "; charset=" + charsetEncoding;
}
SoapVersion version = getVersion();
if (SoapVersion.SOAP_11 == version) {
transportOutputStream.addHeader(TransportConstants.HEADER_SOAP_ACTION, soapAction);
transportOutputStream.addHeader(TransportConstants.HEADER_ACCEPT, version.getContentType());
}
else if (SoapVersion.SOAP_12 == version) {
contentType += "; action=" + soapAction;
transportOutputStream.addHeader(TransportConstants.HEADER_ACCEPT, version.getContentType());
}
transportOutputStream.addHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType);
}
if (!(outputFormat.isOptimized()) & outputFormat.isDoingSWA()) {
writeSwAMessage(outputStream, outputFormat);
}