You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Wilkerson, Daniel" <dw...@fullsail.com> on 2014/05/15 18:01:54 UTC

Camel Smooks MyBatis

Hi everyone. Still somewhat new to Camel. I'm trying to put to ether a Camel integration scenario that routes CSV files to Smooks, then have smooks unmarshall directly to a MyBatis value object that is published to a queue for insertion into a database.

I've been able to get a Smooks route configured to process the incoming CSV data from the file component and unmarshal to XML and publish to a queue, but am a little confused on how to wire it directly to some MyBatis value objects I have (no conversion to XML).

The Smooks-Camel example from their documentation shows Camel route tags inside of a Smooks config file. Is it possible to keep my route information only in my blueprint config file and the value object bean definitions in the Smooks config file? Can the Smooks config and blueprint config be consolidated into the blueprint config file? If Camel routes are placed in the Smooks config file like they show, will they point back to my blueprint file?

I apologize if my post is a tad messy. Still learning proper Camel speak. =0)

The snippet below was copied from the smooks documentation section that covers how to map directly to beans.

<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
         xmlns:camel="http://www.milyn.org/xsd/smooks/camel-1.4.xsd">

  <!-- Create some bean instances from the input source... -->
  <jb:bean beanId="orderItem"  ... ">
    <!-- etc... See Smooks Java Binding docs -->
  </jb:bean>

  <!-- Route bean to camel endpoints... -->
  <camel:route beanid="orderItem">
    <camel:to endpoint="direct:slow" if="orderItem.priority == 'Normal'" />
    <camel:to endpoint="direct:express" if="orderItem.priority == 'High'" />
  </camel:route>

</smooks-resource-list>


My route code in the blueprint file looks like this:

<bean id="smooks" class="org.milyn.smooks.camel.dataformat.SmooksDataFormat">
  <argument value="classpath:/smooks-config.xml" />
</bean>

<camelContext trace="true" id="blueprintContext" xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="file:data_files/folder?fileName=afile.csv&amp;delete=false&amp;delay=360000" />

<!-- CSV to XML -->
<unmarshal ref="smooks" />
<convertBodyTo type="com.myapp.mybatis.domain.Data"/>
<to uri="activemq:queue:data_in_queue" />
</route>
<route>
<from uri="activemq:queue:data_in_queue"/>
<to uri="mock:result"/>
</route>
</camelContext>

My Smooks config looks like this (it's currently still configured to convert to XML but want to switch to converting directly to a MyBatis value object):

<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
    xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.4.xsd"
xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd">

    <csv:reader
        fields="column1,column2,column3" separator="|" skipLines="1"
        rootElementName="Data" recordElementName="Item" />

    <core:exports>
            <core:result type="org.milyfn.payload.StringResult" />
    </core:exports>
</smooks-resource-list>