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

    Preserving MessageProperties with Smooks splitter?

    Michael Burman Newbie

      Hi,

       

      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.

       

      Filter:

       

      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" />
      </fs-listener>

       

      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.

       

      Hints?

        • 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"
            <params>
              <param name="stream.filter.type">SAX</param> 
            </params> 
            <csv:reader fields="seq,recid,descr" quote="'" separator=";" skipLines="1" />
            <resource-config selector="csv-record">
                 <resource>org.milyn.delivery.DomModelCreator</resource>
            </resource-config>
            <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:correlationIdPattern>CHANNELID</jms:correlationIdPattern>
              </jms:message>
              <jms:connection factory="ConnectionFactory"/>
              <jms:session acknowledgeMode="AUTO_ACKNOWLEDGE"
                   transacted="false"/>
              <jms:jndi contextFactory="org.jnp.interfaces.NamingContextFactory"
                   namingFactory="org.jboss.naming:java.naming.factory.url.pkgs"
                   providerUrl="jnp://localhost:1099"/>
              <jms:highWaterMark mark="200" pollFrequency="1000" timeout="60000"/>
            </jms:router>
            <ftl:freemarker applyOnElement="csv-record">
              <ftl:template>templates/record.ftl</ftl:template>
              <ftl:use>
                <ftl:bindTo id="csv_record_as_xml"/>
              </ftl:use>
            </ftl:freemarker>
          </smooks-resource-list>

           

          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();

           

          regards,

          Edward

          • 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).