-
Notifications
You must be signed in to change notification settings - Fork 317
Description
Martin Bosak opened SWS-388 and commented
I had to extend AxiomSoapMessage to override the writeTo method so that I could correctly handle returning a PDF file as an MTOM attachement in a response message. My extension delegates to 'normal' instance of AxiomSoapMessage to perform most all functionality except that it intercepts the writeTo method to set the options I need on the OMOutputFormat object and correctly set the content type.
Now I have to add security to it (using the wss4j interceptor). For now I need to add the WS-Security Timestamp element to the response. The problem I have is that wss4j Interceptor (and wss4j handler) creates a new AxiomSoapMessage instance. I need to intercept the setAxiomSoapMessage method so I can save the new instance as my delegate object; but I can't because the method is declared final in AxiomSoapMessage class.
FYI, here is my modified writeTo method:
public void writeTo(OutputStream outputStream) throws IOException {
try {
String charsetEncoding = delegate.getAxiomMessage().getCharsetEncoding();
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(charsetEncoding);
format.setSOAP11(getVersion() == SoapVersion.SOAP_11);
if (this.pdfAttached) {
format.setDoOptimize(true);
}
if (outputStream instanceof TransportOutputStream) {
TransportOutputStream transportOutputStream = (TransportOutputStream) outputStream;
String contentType = format.getContentType();
contentType += "; charset=\"" + charsetEncoding + "\"";
format.setContentType(contentType);
transportOutputStream.addHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType);
transportOutputStream.addHeader(TransportConstants.HEADER_SOAP_ACTION, delegate.getSoapAction());
}
if (payloadCaching) {
delegate.getAxiomMessage().serialize(outputStream, format);
}
else {
delegate.getAxiomMessage().serializeAndConsume(outputStream, format);
}
outputStream.flush();
}
catch (XMLStreamException ex) {
throw new AxiomSoapMessageException("Could not write message to OutputStream: " + ex.getMessage(), ex);
}
catch (OMException ex) {
throw new AxiomSoapMessageException("Could not write message to OutputStream: " + ex.getMessage(), ex);
}
}Affects: 1.5.3
2 votes, 3 watchers