2 Replies Latest reply on Jul 28, 2010 9:41 AM by Michael Burman

    Preserving MessageProperties with Smooks splitter?

    Michael Burman Newbie



      How to preserve some Message Properties and Headers, when using Smooks splitter? I'm interested in the gateway, where the information comes from.


      As of now, I'm enriching the process with a filter in the gateway to store the original busId for later on processing. With this information, I can later on find out what sort of messages where received, so I can dynamically create XsltActions to process from different formats. This all works just fine, however when I put a Smooks splitter infront of it, I lose all that information.




      ConfigTree config = (ConfigTree) params.get(Environment.GATEWAY_CONFIG);
      String value = config.getAttribute(ListenerTagNames.BUSIDREF_ATTRIBUTE_TAG);
      msg.getProperties().setProperty(HeraclesMessageProperties.INPUT_GATEWAY_BUSIDREF , value);


      This works fine.


      Smooks splitter config:


      <frag:serialize fragment="Invoice" bindTo="invoiceFrag" omitXMLDeclaration="false" />

      <esbr:routeBean beanIdRef="invoiceFrag" toServiceCategory="Transformation" toServiceName="TransformationRouting" routeOnElement="Invoice" />


      In the TransformationRouting service, I don't have the information anymore.


      <fs-listener busidref="InHouse1InputFileChannel"
      is-gateway="true" name="InHouse1FileGateway" schedule-frequency="5">
      <property name="composer-class"
      value="org.jboss.soa.esb.smooks.splitting.FileStreamSplitter" />
      <property name="splitterConfig" value="/META-INF/smooks-splitter.xml" />


      So this will fail in my Action later on in the transformation process:


      String inputBusId = (String) message.getProperties().getProperty(HeraclesMessageProperties.INPUT_GATEWAY_BUSIDREF);
      String inputFormat = inputChannelToFormat.get(inputBusId);


      Is there a way to do splitting while still keeping the original messageProperties intact (aka copy them to the new messages) ? One way I could think of is running a service which will do just splitting and routing them to JMS queue, where I would recreate the gateway and message and keep my information. This doesn't sound like a good way of doing it, since then splitting wouldn't be part of the message's flow in the ESB. Bad for auditing purposes.



        • 1. Re: Preserving MessageProperties with Smooks splitter?
          Edward Pilipczuk Newbie

          I had the same problem with smooks when used as a gateway to read and split huge CSV files.

          My requirement was to track input file name to prevent double submission of the already processed file.

          Your case is simple, to pass channel id you can only provide channel id as CorrelationID in JMS

          For each channel ID you should provide separate smooks-config-per-channel-id.xml file in which

          the following could be defined (example from my implementations)


          <?xml version="1.0" encoding="UTF-8"?>
          <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
              <param name="stream.filter.type">SAX</param> 
            <csv:reader fields="seq,recid,descr" quote="'" separator=";" skipLines="1" />
            <resource-config selector="csv-record">
            <jms:router beanId="csv_record_as_xml" destination="/queue/RecordQueueGW" executeBefore="false" routeOnElement="csv-record">
              <jms:message deliveryMode="persistent" priority="4" timeToLive="0" type="TextMessage">
              <jms:connection factory="ConnectionFactory"/>
              <jms:session acknowledgeMode="AUTO_ACKNOWLEDGE"
              <jms:jndi contextFactory="org.jnp.interfaces.NamingContextFactory"
              <jms:highWaterMark mark="200" pollFrequency="1000" timeout="60000"/>
            <ftl:freemarker applyOnElement="csv-record">
                <ftl:bindTo id="csv_record_as_xml"/>


          Then when you process messages in action classes you can reference the JMS correlation ID pattern by calling:


          // Get JMS Correlation Id fragment from RelatesTo field of Message header

          String msgId = message.getHeader().getCall().getRelatesTo().getFragment();




          • 2. Re: Preserving MessageProperties with Smooks splitter?
            Michael Burman Newbie

            That's an interesting approach. Thanks for that, I'll try it. Still, for any developers of JBossESB, I hope there would a be way to do this without this kind of 'bubblegum' solution (I can volunteer to help, but I have no idea where to start, since I don't know Smooks).