9 Replies Latest reply on Aug 26, 2014 6:23 AM by KUMAR RAMAN

    Access Message Parameters with Smooks

    toby saville Novice

      Hello,

      I am trying to perform a transformation on the body of a message which contains XML, by applying an XSL using smooks.

      As part of the transformation, i would like to incorporate some message parameters into the resultant XML.

      Is this possible? Can i get access to the message's parameters from smooks and eventually the XSL.

      thanks in advance,
      tobes

        • 1. Re: Access Message Parameters with Smooks
          Tom Fennelly Master

          What is the source of the parameter values? The source message payload being transformed? The ESB message itself (properties, other body locations etc)? Something external?

          If the parameters are in the source message payload, then this is possible right now. If not, then you have a problem because the SmooksTransformer action in the ESB doesn't support this right now. Smooks itself does support it by allowing you bind objects to the Smooks ExecutionContext. All Smooks transformers are able to access the ExecutionContext. This is something we could and should add support for.

          • 2. Re: Access Message Parameters with Smooks
            toby saville Novice

            hi Tom,

            i dont know how much of this detail will be helpful, but maybe im taking the wrong approach altogether - maybe you can advise.

            I have a web service that is called by our order management system. the web service accepts an Order object.

            one of the services that i have to send the Order object to, requires the username and password of the end user, using the order management system. These fields arent part of the Order object, so they are separate parameters to the web service method.

            So, in the web service i was going to pass them as message parameters (message.getBody.get("key")) and then include them in the transformed XML.

            But now that im writing this, im thinking, i can interrogate the message parameters as part of the consuming service, does that sound valid?

            Ideally, i guess they should go in the Message's Context field (security related?), although this interface looks incomplete at the moment.

            thanks,
            toby

            • 3. Re: Access Message Parameters with Smooks
              Tom Fennelly Master

              Not sure which option you're taking, but if you need to add these to the security params to the XML message, you should still be able to do that.

              You could write a simple XSL (or FreeMarker, or StringTemplate) based transform to add the username and password fields as follows....

              So assume yer input SOAP message was as follows...

              <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:abi="http://org.jboss.esb/quickstarts/bpel/ABI_OrderManager">
               <soapenv:Header/>
               <soapenv:Body>
               <abi:cancelOrder>
               <orderInquiry>
               <customerNumber>123456</customerNumber>
               <poNumber>PO000123</poNumber>
               </orderInquiry>
               </abi:cancelOrder>
               </soapenv:Body>
              </soapenv:Envelope>


              And you want to add the username and password as part of the orderInquiry, before the customerNumber (for example). Then yer Smooks based XSL transform could be as follows...

              <?xml version='1.0' encoding='UTF-8'?>
              <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
              
               <resource-config selector="orderInquiry customerNumber">
               <resource type="xsl">
               <![CDATA[<user><username>joebloggs</username><password>guessagain</password></user>]]>
               </resource>
               <param name="is-xslt-templatelet">true</param>
               <param name="action">insertbefore</param>
               </resource-config>
              </smooks-resource-list>


              Yielding...

              <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:abi="http://org.jboss.esb/quickstarts/bpel/ABI_OrderManager">
               <soapenv:Header/>
               <soapenv:Body>
               <abi:cancelOrder>
               <orderInquiry>
               <username>joebloggs</username><password>guessagain</password></user>
               <customerNumber>123456</customerNumber>
               <poNumber>PO000123</poNumber>
               </orderInquiry>
               </abi:cancelOrder>
               </soapenv:Body>
              </soapenv:Envelope>


              Of course, you could also use the same method to add WS-S headers to the message. E.g....

              <?xml version='1.0' encoding='UTF-8'?>
              <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
              
               <resource-config selector="header">
               <resource type="xsl"><![CDATA[
               <wsse:Security>
               <wsse:UsernameToken >
               <wsse:Username> Zoe </wsse:Username>
               <wsse:Password> ILoveDogs </wsse:Password>
               </wsse:UsernameToken>
               </wsse:Security>]]>
               </resource>
               <param name="is-xslt-templatelet">true</param>
               <param name="action">addto</param>
               </resource-config>
              
              </smooks-resource-list>



              • 4. Re: Access Message Parameters with Smooks
                toby saville Novice

                nice one Tom, thanks for your help, really appreciated!

                - tobes

                • 5. Re: Access Message Parameters with Smooks
                  Tom Fennelly Master

                  np Toby. Did it work for you?

                  • 6. Re: Access Message Parameters with Smooks
                    toby saville Novice

                    well, i was acessing the objects after they had been converted from SOAP to Java objects (by XFire incidentally) but your posting gave me the idea of accessing the SOAP message directly.

                    which im going to try now :)

                    • 7. Re: Access Message Parameters with Smooks
                      Jonas Buechel Novice

                      Hi Tom,

                       

                      I have a similar problem as toby had back in the day.

                       

                      You mentioned:

                      If the parameters are in the source message payload, then this is possible right now. If not, then you have a problem because the SmooksTransformer action in the ESB doesn't support this right now.

                      Is this supported by now ?

                       

                      If not, how could I achieve the following:

                      1. Extract a value from a message payload "original-request"

                      2. Write the previously extracted value into a specific element within the "defaultEntry" payload

                       

                      You mentioned something about "accessing the ExecutionContext". Can this be done programatically from within a custom action?

                       

                      Help would be very appreciated!

                       

                      Kind regards

                      Jonas

                      • 8. Re: Access Message Parameters with Smooks
                        Jonas Buechel Novice

                        I found a solution to the problem mentioned above. Please refer to the following post:

                        http://community.jboss.org/message/578433#578433

                        • 9. Re: Access Message Parameters with Smooks
                          KUMAR RAMAN Newbie

                          Hi Tom,

                          I am trying to add header to the soapClient like you added here but my problem is that in the header, I need to pass session token which will be a variable. I tried storing it locally in SoapBody and then fetching it using <xsl:value-of select="//sessiontoken">, but its not reading the value. Can you please suggest a better way of inserting a variable in the soap header.

                          Thanks in Advance.