3 Replies Latest reply on Mar 7, 2014 5:28 AM by richardhands

    Best practise for accessing original message after transforming

    richardhands

      I have a requirement whereby i will have a switchyard composite that exposes a SOAP interface with a wsdl binding.

       

      This will transform into java objects for use in a bean component which does a variety of orchestration to other switchyard component references.

       

      At a certain point within my orchestration flow, after i have done some lookups on data from the inbound message to get/create certain database id values, i need to be able to pass the original message XML that came into the composite, out to another externally referenced composite, which forms an 'auditing' service, as a string, along with the database ids.

       

      Has anyone had to create a scenario like this before?  Has anyone any suggestions on how this could be achieved?  i don't really want to 're-transform' the object back out using a second transformer, as obviously this isn't really the 'original' message at that point, it could have been changed.

       

      Thanks

       

      Rich

        • 1. Re: Best practise for accessing original message after transforming
          kcbabo

          If you want to capture the original message that came off the wire from the binding before transformation, then you have a couple of options.  Both options involve making a copy of the content of the message and storing it as a context property.

           

          1) Implement an exchange interceptor with a target of CONSUMER and capture the content in the before() callback.

          2) Create a custom message composer which extends the message composer for the binding you are using.  Capture the original content from the BindingData reference and then call super.compose() to continue processing.

           

          Gotchas:

          * If you are dealing with stream-based content, you need to make sure you replace the content after reading it.  If you exhaust a stream in your copy logic then the original message content is no longer there.  Here's an example of how you might do that.

          * If you store the original message content as a context property, keep in mind where you will need to access the property.  If you are making multiple invocations in your app and you need to inspect the original message in any of those invocations, then be sure to propagate the context property on each call.

          • 2. Re: Best practise for accessing original message after transforming
            richardhands

            Thanks Keith, i knew there had to be a fairly obvious answer :-)

            • 3. Re: Best practise for accessing original message after transforming
              richardhands

              I think I may just have fallen foul of the second gotcha you listed above

              * If you store the original message content as a context property, keep in mind where you will need to access the property.  If you are making multiple invocations in your app and you need to inspect the original message in any of those invocations, then be sure to propagate the context property on each call.

               

              due to some changes to the spec from the client, i now have an external soap binding, coming in through a transformer to a java bean component, and then invoking another java bean component.  My interceptor fires on both 'befores' as i'd expect, and in the first bean component if i inject the context and interrogate it, that property is there.  However, when i get to my second bean, it's not there on the context any more.  Is this just a case that i need to change my second (and subsequent) bean service interfaces to take across the original message, or is there a 'better' way to keep it on the context so that i can pick it up when needed?