Announcement Announcement Module
No announcement yet.
soap with attachments (swa) combined with payload Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • soap with attachments (swa) combined with payload


    To implement Soap with Attachments (SwA) within Spring Web services I am simply implementing MessageEndpoint and then in the invoke(MessageContext) method I cast messageContext.getRequest() to a SoapMessage. From then I can get the attachment.

    However, to also process some message payload (not the attachment part) I am basically writing the implementation of AbstractJDomPayloadEndpoint myself (or one of the other payload endpoints such as AbstractMarshallingPayloadEndpoint).

    It appears to me that there is no way to extend one of the payload endpoint and get the attachment, as I don't seem to have access to the MessageContext.

    It seems a bit odd that I can't get to the MessageContext while utilising one of the payload endpoints. So if I want to use attachments I have to write my own payload endpoint.

    Axis2 has MessageContext.getCurrentMessageContext() that can be called from within a service that marshalls/unmarshalls the payload.

    1. Am I right in my implementation of SwA in Spring Web Services?
    2. Is there a better way to process both the attachment and the message payload?


  • #2
    Never mind I've just realised about EndpointInterceptor that I can implement to get the message context and hence the attachments.


    • #3
      Hang on, now I get threadsafe issues, because the Endpoint is a singleton and this won't work.
      I simply had code in my interceptor like:

      public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
        MyEndpoint targetEndpoint = (MyEndpoint) endpoint;
        return true;
      where messageContext is then used within the invokeInternal method of MyEndpoint. But this would not be threadsafe.

      I saw on another thread someone suggest a request scoped bean, but as I mentioned in a comment on that thread, how does it fit in with

      Any thoughts?


      • #4
        Request-scoped beans are different from prototype beans.
        A new instance of request-scoped beans gets created for each individual http request and lives only for the lifetime of that request. This is similar to using ThreadLocals but has the advantage that Spring takes care of the whole lifecycle of the bean for you.

        For more details on how to use the request scope:


        • #5
          Thanks Tareq, I was reading the wrong section.