4 Replies Latest reply on Jan 4, 2011 3:16 AM by Jonas Buechel

    Buffering values between actions

    Jonas Buechel Novice

      Hi there,

       

      First of all, I'm fairly new to JBoss ESB.

       

      We came across the following scenario:

       

      System1 has to consume a Webservice of System2. Though System1 can't understand the Webservice structure of System2's Webservice.

      Therefore we need to implement an ESB Service which:

      - provides a WS to System1

      - consumes the WS from System2

      - maps the response from System2 to System1

       

      This all works so far.

       

      The actual issue we ran into is the following:

      We would need to

      - buffer a request parameter value sent from System1 and span between several actions

      - before the response is being sent back to System1 the buffered value should be merged into the response

       

      Can anybody tell us how this could be achieved in an easy way?

       

      Thanks in advance!

      Jonas

        • 1. Re: Buffering values between actions
          Jonas Buechel Novice

          I got a bit further.. A possible approach could be:

           

          1. Saving the original request message body to another payload location (e.g. test-payload).

          2. Before sending the response back to System1 the relevant value could be read from the test-payload and written to the message body of org.jboss.soa.esb.message.defaultEntry.

           

          Step 1 is done.

           

          How could be done step 2?

          - e.g. read from test-payload and write/merge the relevant data to org.jboss.soa.esb.message.defaultEntry location using an XSLT or smooks action?

          • 2. Re: Buffering values between actions
            Jonas Buechel Novice

            I finally came up with the following solution (if somebody knows a simpler approach, please let us know):

             

            Smooks configuration:

            <?xml version="1.0" encoding="UTF-8"?>
            <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
            <!--
            This freemaker configuration adds the value of the bean
            ${ncoInstanceIdBean} to the relevant ESB message. The bean
            ${ncoInstanceIdBean} is actually of type String and is being created
            and populated within
            com.frox.itsm.ncinv.consumer.ItsmResponseProcessor
            -->
            <ftl:freemarker applyOnElement="ncoInstanceId">
            <ftl:template><!--${ncoInstanceIdBean}--></ftl:template>
            <ftl:use>
            <ftl:inline directive="addto" />
            </ftl:use>
            </ftl:freemarker>
            </smooks-resource-list>
            <?xml version="1.0" encoding="UTF-8"?>
            <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
             xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd">
            
             <ftl:freemarker applyOnElement="ncoInstanceId">
              <ftl:template><!--${ncoInstanceIdBean}--></ftl:template>
              <ftl:use>
               <ftl:inline directive="addto" />
              </ftl:use>
             </ftl:freemarker>
            
            </smooks-resource-list>
            

             

            ESB action implementation:

                 public Message process(Message message) throws ActionProcessingException {
            
                      try {
                           // Get the original request from the name body
                           ConfigTree treeOrigRequest = ConfigTree.fromXml(message.getBody()
                                     .get(Constants.NAMED_BODY_ORIGINAL_REQUEST).toString());
            
                           // Extract the ncoInstanceId
                           String ncoInstanceId = treeOrigRequest
                                     .getFirstTextChild(NCO_INSTANCE_ID_ELEMENT_NAME);
            
                           // Smook transformation using a freemaker template
                           Smooks smooks = new Smooks(getClass().getResourceAsStream(
                                     SMOOKS_CONFIG_LOCATION));
            
                           ExecutionContext executionContext = smooks.createExecutionContext();
            
                           BeanRepository.getInstance(executionContext).addBean(
                                     NCO_INSTANCE_ID_BEAN, ncoInstanceId);
            
                           StringResult result = new StringResult();
            
                           smooks.filterSource(executionContext, new StringSource(message
                                     .getBody().get().toString()), result);
            
                           // Add the result to the message body
                           message.getBody().add(result.getResult());
            
                      } catch (IOException e1) {
            
                           e1.printStackTrace();
            
                      } catch (SAXException e1) {
            
                           e1.printStackTrace();
                      }
            
                      return message;
                 }
            
            • 3. Re: Buffering values between actions
              Daniel Bevenius Master

              Hi Jonas,

               

              just a note about performance. You can safely cache and reuse the Smooks Object. Initialization of Smooks takes some time and therefore it is important that it is reused.

               

              Regards,

               

              /Daniel

              • 4. Re: Buffering values between actions
                Jonas Buechel Novice

                Hi Daniel,

                 

                thanks for your hint! That makes sense..

                 

                Very appreciated!

                 

                Kind regards

                Jonas