Skip to content

Add support for customizing AxiomSoapMessage#writeTo #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gregturn opened this issue Jul 7, 2008 · 1 comment
Closed

Add support for customizing AxiomSoapMessage#writeTo #540

gregturn opened this issue Jul 7, 2008 · 1 comment
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@gregturn
Copy link
Contributor

gregturn commented Jul 7, 2008

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

@gregturn gregturn added status: waiting-for-triage An issue we've not yet triaged in: core labels Sep 22, 2020
@snicoll snicoll removed the in: core label Feb 19, 2025
@snicoll snicoll added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 17, 2025
@snicoll snicoll added this to the 4.1.0-M1 milestone Mar 17, 2025
@snicoll snicoll changed the title Extending AxiomSoapMessage difficult due to final methods [SWS-388] Add support for customizing AxiomSoapMessage#writeTo Mar 17, 2025
@snicoll snicoll self-assigned this Mar 17, 2025
@snicoll
Copy link
Member

snicoll commented Mar 17, 2025

I am looking at the current AxiomSoapMessage and I agree that the method is doing quite a bit there. I've added something that hopefully should help you, if that still makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants