14 Replies Latest reply on Jan 20, 2010 6:56 AM by tagnegilles

    Smooks problem

    tagnegilles

      Hi Guys,

       

      I try to use smooks in my ESB project to store some data in an exterm database. But it doesn't work. I am doing may be something wrong. Please i need your help. I am using JBossESB 4.7 in JBoss AS 5.1.0 jdk6

       

      jboss-esb.xml

      <?xml version="1.0"?>
      <jbossesb parameterReloadSecs="5"
       xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd">
       <providers>
        <jms-provider connection-factory="ConnectionFactory" name="JbossMessaging">
         <jms-bus busid="splitterChannel">
          <jms-message-filter dest-name="/queue/splitterQueue" dest-type="QUEUE"/>
         </jms-bus>
        </jms-provider>
        <schedule-provider name="CronSchedulerProvider">
         <cron-schedule cronExpression="0/3 * * * * ?" scheduleid="myCronSchedule"/>
        </schedule-provider>
        <fs-provider name="FileSystemProvider">
         <fs-bus busid="esbFileSystem">
          <fs-message-filter directory="/Users/gilles/Desktop/ESB/Input"
           error-delete="false"
           error-directory="/Users/gilles/Desktop/ESB/Error"
           error-suffix=".error" input-suffix=".csv" post-delete="true"
           post-directory="/Users/gilles/Desktop/ESB/Post" post-suffix=".post" work-suffix=".work"/>
         </fs-bus>
        </fs-provider>
       </providers>
       <services>
       
        <service category="splitterTest" description="Splitt the .csv file"
         invmScope="GLOBAL" name="fileSplitter">
         <listeners>
          <fs-listener busidref="esbFileSystem" is-gateway="true"
           name="FileListener" scheduleidref="myCronSchedule">
           <property name="composer-class" value="org.jboss.soa.esb.smooks.splitting.FileStreamSplitter"/>
           <property name="splitterConfig" value="/mySmooksConf.xml"/>
          </fs-listener>
         </listeners>
         <actions mep="OneWay">
          <action class="org.jboss.soa.esb.actions.SystemPrintln" name="Print">
           <property name="message" value="[Splitter] Message Split complete"/>
          </action>
         </actions>
        </service>
        
        <service category="splitterTest"
         description="Route the message to a jms queue" invmScope="GLOBAL" name="routerSplitter">
         <actions mep="OneWay">
          <action class="org.jboss.soa.esb.actions.Notifier" name="NotifyAction1">
           <property name="destinations">
            <NotificationList type="ok">
             <target class="NotifyQueues">
              <queue jndiName="queue/splitterQueue"/>
             </target>
            </NotificationList>
           </property>
           <property name="okMethod" value="notifyOK"/>
          </action>
          <!--  Alte Version
          <action class="org.jboss.soa.esb.actions.routing.JMSRouter" name="jmsRouter">
           <property name="unwrap" value="true"/>
           <property name="jndiName" value="queue/splitterQueue"/>
          </action>  -->
         </actions>
        </service>
        
        <service category="splitterTest"
         description="Route the age element of the message to a jms queue"
         invmScope="GLOBAL" name="routerAgeSplitter">
         <actions mep="OneWay">
          <action class="org.jboss.soa.esb.actions.Notifier" name="NotifyAction2">
           <property name="destinations">
            <NotificationList type="ok">
             <target class="NotifyQueues">
              <queue jndiName="queue/splitterAgeESBQueue"/>
             </target>
            </NotificationList>
           </property>
           <property name="okMethod" value="notifyOK"/>
          </action>
          <!--    
          <action class="org.jboss.soa.esb.actions.routing.JMSRouter" name="jmsRouterAge">
           <property name="unwrap" value="true"/>
           <property name="jndiName" value="queue/splitterAgeESBQueue"/>
          </action>  -->
         </actions>
        </service>
        
        <service category="splitterTest" description="Make routing on Age"
         invmScope="GLOBAL" name="recipientListAge">
         <actions mep="OneWay">
          <action class="org.jboss.soa.esb.actions.StaticRouter" name="staticRoutingAge">
           <property name="destinations">
            <route-to destination-name="ToRouterAgeSplitter"
             service-category="splitterTest" service-name="routerAgeSplitter"/>
            <route-to destination-name="ToDbPersistAge"
             service-category="splitterTest" service-name="dbPersist"/>
           </property>
          </action>
         </actions>
        </service>
        
        <service category="splitterTest"
         description="Persist data in the database" invmScope="GLOBAL" name="dbPersist">
         <actions mep="OneWay">
          <action class="org.jboss.soa.esb.actions.SystemPrintln" name="PrintMessage1">
           <property name="message" value="Message"/>
          </action>   
          <action class="org.jboss.soa.esb.smooks.SmooksAction" name="smoksActionXML">
           <property name="smooksConfig" value="/xmlSmooksConf.xml"/>
          </action>
          <action class="org.jboss.soa.esb.actions.SystemPrintln" name="PrintMessage2">
           <property name="message" value="Message"/>
          </action>   
          <action class="org.jboss.soa.esb.smooks.SmooksAction" name="smoksActionDB">
           <property name="smooksConfig" value="/dbSmooksConf.xml"/>
          </action>
         </actions>
        </service>
       </services>
      </jbossesb>
      

       

      mySmooksConf.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
           xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd" 
           xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd"
           xmlns:esbr="http://www.jboss.org/xsd/jbossesb/smooks/routing-1.0.xsd"
           xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd">
           
          <params>        
              <param name="stream.filter.type">SAX</param>
          </params>     
               
           <csv:reader fields="id,firstname,lastname,age" rootElementName="liste" recordElementName="person">
                <csv:singleBinding beanId="personvirtual" class="java.util.HashMap"/>       
           </csv:reader>
      
           <ftl:freemarker applyOnElement="person">          
                <ftl:template><!--${personvirtual.id},${personvirtual.firstname},${personvirtual.lastname}--></ftl:template>
                <ftl:use>
                     <ftl:bindTo id="personFragment" />
                </ftl:use>
           </ftl:freemarker>
      
           <ftl:freemarker applyOnElement="person">          
                <ftl:template><!--${personvirtual.id},${personvirtual.age}--></ftl:template>
                <ftl:use>
                     <ftl:bindTo id="personAgeFragment" />
                </ftl:use>
           </ftl:freemarker>     
      
      
          <esbr:routeBean beanIdRef="personFragment" toServiceCategory="splitterTest" toServiceName="routerSplitter" routeOnElement="person"/>
         
          <esbr:routeBean beanIdRef="personAgeFragment" toServiceCategory="splitterTest" toServiceName="recipientListAge" routeOnElement="person"/>
              
      </smooks-resource-list>
      

       

      xmlSmooksConf.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
           xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd">
           
          <params>        
              <param name="stream.filter.type">SAX</param>
          </params>     
               
           <csv:reader fields="id,age" rootElementName="personliste" recordElementName="person"/>     
           
      </smooks-resource-list>
      
        • 1. Re: Smooks problem
          tagnegilles

          splitter-ds.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <datasources>
             <local-tx-datasource>
                <jndi-name>SplitterSqlDB</jndi-name>
                <connection-url>jdbc:hsqldb:hsql://localhost:1704</connection-url>
                <driver-class>org.hsqldb.jdbcDriver</driver-class>
                <user-name>sa</user-name>
                <password></password>
                <min-pool-size>5</min-pool-size>
                <max-pool-size>20</max-pool-size>
                <idle-timeout-minutes>0</idle-timeout-minutes>
                <depends>jboss:service=SplitterSqlDB</depends>     
                <prepared-statement-cache-size>32</prepared-statement-cache-size>
             </local-tx-datasource>
          
             <mbean code="org.jboss.internal.soa.esb.dependencies.HypersonicDatabase"
               name="jboss:service=SplitterSqlDB">
               <attribute name="Port">1704</attribute>
               <attribute name="BindAddress">localhost</attribute> 
               <attribute name="Database">SplitterSqlDB</attribute>
               <attribute name="Silent">true</attribute>
               <attribute name="Trace">false</attribute>
               <attribute name="No_system_exit">true</attribute>
               <attribute name="DataDir">${jboss.server.data.dir}</attribute>
             </mbean>
          </datasources>
          
          

           

          myEsbmq-service.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-service_5_0.dtd" >
          <server>
              <mbean code="org.jboss.jms.server.destination.QueueService"
                     name="jboss.esb.splitter:service=Queue,name=splitterQueue"
                     xmbean-dd="xmdesc/Queue-xmbean.xml">
                  <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
                  <depends>jboss.messaging:service=PostOffice</depends>
              </mbean>
              
              <mbean code="org.jboss.jms.server.destination.QueueService"
                     name="jboss.esb.splitter:service=Queue,name=splitterAgeESBQueue"
                     xmbean-dd="xmdesc/Queue-xmbean.xml">
                  <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
                  <depends>jboss.messaging:service=PostOffice</depends>
              </mbean>    
           
               <mbean code="org.jboss.jms.server.bridge.BridgeService" name="splitter:service=Bridge,name=SplitterAgeBridge"
                    xmbean-dd="xmdesc/Bridge-xmbean.xml">
          
                    <!-- The JNDI lookup for the source destination -->
                    <attribute name="SourceDestinationLookup">/queue/splitterAgeESBQueue</attribute>
          
                    <!-- The JNDI lookup for the target destination -->
                    <attribute name="TargetDestinationLookup">/queue/splitterAgeQueue</attribute>
          
                    <!--
                         The username to use for the source connection <attribute
                         name="SourceUsername">bob</attribute>
                    -->
          
                    <!--
                         The password to use for the source connection <attribute
                         name="SourcePassword">cheesecake</attribute>
                    -->
          
                    <!--
                         The username to use for the target connection <attribute
                         name="TargetUsername">mary</attribute>
                    -->
          
                    <!--
                         The password to use for the target connection <attribute
                         name="TargetPassword">hotdog</attribute>
                    -->
          
                    <!--
                         Optional: The Quality Of Service mode to use, one of:
                         QOS_AT_MOST_ONCE = 0; QOS_DUPLICATES_OK = 1; QOS_ONCE_AND_ONLY_ONCE =
                         2;
                    -->
                    <attribute name="QualityOfServiceMode">0</attribute>
          
                    <!--
                         JMS selector to use for consuming messages from the source <attribute
                         name="Selector">specify jms selector here</attribute>
                    -->
          
                    <!--
                         The maximum number of messages to consume from the source before
                         sending to the target
                    -->
                    <attribute name="MaxBatchSize">1</attribute>
          
                    <!--
                         The maximum time to wait (in ms) before sending a batch to the target
                         even if MaxBatchSize is not exceeded. -1 means wait forever
                    -->
                    <attribute name="MaxBatchTime">-1</attribute>
          
                    <!--
                         If consuming from a durable subscription this is the subscription
                         name <attribute name="SubName">mysub</attribute>
                    -->
          
                    <!--
                         If consuming from a durable subscription this is the client ID to use
                         <attribute name="ClientID">myClientID</attribute>
                    -->
          
                    <!--
                         The number of ms to wait between connection retrues in the event
                         connections to source or target fail
                    -->
                    <attribute name="FailureRetryInterval">5000</attribute>
          
                    <!--
                         The maximum number of connection retries to make in case of failure,
                         before giving up -1 means try forever
                    -->
                    <attribute name="MaxRetries">-1</attribute>
          
                    <!--
                         If true then the message id of the message before bridging will be
                         added as a header to the message so it is available to the receiver.
                         Can then be sent as correlation id to correlate in a distributed
                         request-response
                    -->
                    <attribute name="AddMessageIDInHeader">false</attribute>
                    
                    <!--
                         The JMS provider loader that is used to lookup the source destination
                    -->
                    <depends optional-attribute-name="SourceProviderLoader">
                         jboss.messaging:service=JMSProviderLoader,name=JMSProvider</depends>
          
                    <!--
                         The JMS provider loader that is used to lookup the target destination
                    -->
                    <depends optional-attribute-name="TargetProviderLoader">
                         jboss.messaging:service=JMSProviderLoader,name=JMSProvider</depends>
                         
                    <depends>jboss.esb.splitter:service=Queue,name=splitterAgeESBQueue</depends>
               </mbean>   
              
               <mbean code="org.jboss.jms.server.bridge.BridgeService" name="splitter:service=Bridge,name=SplitterBridge"
                    xmbean-dd="xmdesc/Bridge-xmbean.xml">
          
                    <!-- The JNDI lookup for the source destination -->
                    <attribute name="SourceDestinationLookup">/queue/splitterQueue</attribute>
          
                    <!-- The JNDI lookup for the target destination -->
                    <attribute name="TargetDestinationLookup">/queue/splitterMDQueue</attribute>
          
                    <!--
                         The username to use for the source connection <attribute
                         name="SourceUsername">bob</attribute>
                    -->
          
                    <!--
                         The password to use for the source connection <attribute
                         name="SourcePassword">cheesecake</attribute>
                    -->
          
                    <!--
                         The username to use for the target connection <attribute
                         name="TargetUsername">mary</attribute>
                    -->
          
                    <!--
                         The password to use for the target connection <attribute
                         name="TargetPassword">hotdog</attribute>
                    -->
          
                    <!--
                         Optional: The Quality Of Service mode to use, one of:
                         QOS_AT_MOST_ONCE = 0; QOS_DUPLICATES_OK = 1; QOS_ONCE_AND_ONLY_ONCE =
                         2;
                    -->
                    <attribute name="QualityOfServiceMode">0</attribute>
          
                    <!--
                         JMS selector to use for consuming messages from the source <attribute
                         name="Selector">specify jms selector here</attribute>
                    -->
          
                    <!--
                         The maximum number of messages to consume from the source before
                         sending to the target
                    -->
                    <attribute name="MaxBatchSize">1</attribute>
          
                    <!--
                         The maximum time to wait (in ms) before sending a batch to the target
                         even if MaxBatchSize is not exceeded. -1 means wait forever
                    -->
                    <attribute name="MaxBatchTime">-1</attribute>
          
                    <!--
                         If consuming from a durable subscription this is the subscription
                         name <attribute name="SubName">mysub</attribute>
                    -->
          
                    <!--
                         If consuming from a durable subscription this is the client ID to use
                         <attribute name="ClientID">myClientID</attribute>
                    -->
          
                    <!--
                         The number of ms to wait between connection retrues in the event
                         connections to source or target fail
                    -->
                    <attribute name="FailureRetryInterval">5000</attribute>
          
                    <!--
                         The maximum number of connection retries to make in case of failure,
                         before giving up -1 means try forever
                    -->
                    <attribute name="MaxRetries">-1</attribute>
          
                    <!--
                         If true then the message id of the message before bridging will be
                         added as a header to the message so it is available to the receiver.
                         Can then be sent as correlation id to correlate in a distributed
                         request-response
                    -->
                    <attribute name="AddMessageIDInHeader">false</attribute>
                    
                    <!--
                         The JMS provider loader that is used to lookup the source destination
                    -->
                    <depends optional-attribute-name="SourceProviderLoader">
                         jboss.messaging:service=JMSProviderLoader,name=JMSProvider</depends>
          
                    <!--
                         The JMS provider loader that is used to lookup the target destination
                    -->
                    <depends optional-attribute-name="TargetProviderLoader">
                         jboss.messaging:service=JMSProviderLoader,name=JMSProvider</depends>
                         
                    <depends>jboss.esb.splitter:service=Queue,name=splitterQueue</depends>
               </mbean>    
          </server>
          
          
          • 2. Re: Smooks problem
            tagnegilles

            deployment.xml

             

            <jbossesb-deployment>
                 <depends>jboss.esb.splitter:service=Queue,name=splitterQueue</depends>
                 <depends>jboss.esb.splitter:service=Queue,name=splitterAgeESBQueue</depends>
                 <depends>jboss.esb:deployment=smooks.esb</depends>
                 <!-- 
                 <depends>splitter:service=SplitterSqlDatabaseInitializer</depends>  -->
            </jbossesb-deployment>
            

             

            persistence.xml

             

            <?xml version="1.0" encoding="UTF-8"?>
            <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd ">
                 <persistence-unit name="persondb" transaction-type="RESOURCE_LOCAL">
                      <non-jta-data-source>java:/SplitterSqlDB</non-jta-data-source>
                      <properties>
                           <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
                           <property name="hibernate.hbm2ddl.auto" value="create-drop" />          
                      </properties>
                 </persistence-unit>
            </persistence>
            
            

             

             

            PersonAge.java

             

            package de.gilles.projects.splitteresb;
            
            import java.io.Serializable;
            
            import javax.persistence.Column;
            import javax.persistence.Entity;
            import javax.persistence.Id;
            import javax.persistence.Table;
            
            @Entity
            @Table(name="PERSON_AGE_TABLE")
            public class PersonAge implements Serializable {
            
                 /**
                  * 
                  */
                 private static final long serialVersionUID = 1L;
                 
                 @Id
                 @Column(name="PERSON_ID",nullable=false,unique=true)
                 private Integer id;
                 @Column(name="PERSON_AGE", nullable=false)    
                 private Integer age;
                 
                 public PersonAge() {}
            
                 public PersonAge(Integer id, Integer age) {
                      this.id = id;
                      this.age = age;
                 }
                
                 public Integer getId() {
                      return id;
                 }
            
                 public void setId(Integer id) {
                      this.id = id;
                 }
            
            
                 public Integer getAge() {
                      return age;
                 }
            
                 public void setAge(Integer age) {
                      this.age = age;
                 }
            
            }
            
            
            • 3. Re: Smooks problem
              tagnegilles

              dbSmooksConf.xml

              <?xml version="1.0" encoding="UTF-8"?>
              <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
                   xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd" 
                   xmlns:dao="http://www.milyn.org/xsd/smooks/persistence-1.2.xsd">
                   
              
                   
              
                   <jb:bean beanId="person" class="de.gilles.projects.splitteresb.PersonAge" createOnElement="person">
                        <jb:value property="id" data="id" decoder="Integer"/>
                        <jb:value property="age" data="age" decoder="Integer"/>
                   </jb:bean>   
              
                   <dao:inserter beanId="person" insertOnElement="person"/>  
                   
              </smooks-resource-list>
              
              when i put this file file.csv in the /Users/gilles/Desktop/ESB/Input
              1,Max,Mustermann,31
              2,Ingrid,Duck,28
              3,Bernd,Schneider,15
              4,Bettina,Klaus,20
              
              

               

              i have this result

              12:44:30,424 INFO  [STDOUT] [Splitter] Message Split complete: 
              12:44:30,471 INFO  [STDOUT] [/Users/gilles/Desktop/ESB/Input/bien.csv.work].
              12:44:30,598 INFO  [STDOUT] Message: 
              12:44:30,598 INFO  [STDOUT] [1,31].
              12:44:32,316 INFO  [STDOUT] Message: 
              12:44:32,316 INFO  [STDOUT] [<personliste><person><id>1</id><age>31</age></person></personliste>].
              12:44:32,377 WARN  [ContentDeliveryConfigBuilder] ContentHandlerFactory [org.milyn.delivery.JavaContentHandlerFactory] unable to create resource processing instance for resource [Target Profile: [[org.milyn.profile.profile#default_profile]], Selector: [person], Selector Namespace URI: [null], Resource: [org.milyn.persistence.EntityInserter], Num Params: [1]]. org/milyn/scribe/ObjectStore
              12:44:32,412 WARN  [InterceptorsFactory] EJBTHREE-1246: Do not use InterceptorsFactory with a ManagedObjectAdvisor, InterceptorRegistry should be used via the bean container
              12:44:32,412 WARN  [InterceptorsFactory] EJBTHREE-1246: Do not use InterceptorsFactory with a ManagedObjectAdvisor, InterceptorRegistry should be used via the bean container
              12:44:32,427 WARN  [InterceptorsFactory] EJBTHREE-1246: Do not use InterceptorsFactory with a ManagedObjectAdvisor, InterceptorRegistry should be used via the bean container
              12:44:32,427 WARN  [InterceptorsFactory] EJBTHREE-1246: Do not use InterceptorsFactory with a ManagedObjectAdvisor, InterceptorRegistry should be used via the bean container
              12:44:32,453 INFO  [STDOUT] **********************************************************
              12:44:32,475 INFO  [STDOUT] **           Message Receive from ESB                   **
              12:44:32,475 INFO  [STDOUT] **********************************************************
              12:44:32,475 INFO  [STDOUT]       
              PersonID: 1
              Age: 31
              12:44:32,466 WARN  [ActionProcessingPipeline] No fault address defined for fault message! To: InVMEpr [ PortReference < <wsa:Address invm://73706c697474657254657374242424242424242424242424646250657273697374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] MessageID: 62253491-8694-4340-9c3a-4105a0e6bd2e
              12:44:32,487 INFO  [STDOUT] **********************************************************
              12:44:32,488 INFO  [STDOUT] **           Message Receive from ESB                   **
              12:44:32,488 INFO  [STDOUT] **********************************************************
              12:44:32,488 INFO  [STDOUT]       
              PersonID: 2
              Age: 28
              12:44:32,492 INFO  [STDOUT] **********************************************************
              12:44:32,492 INFO  [STDOUT] **           Message Receive from ESB                   **
              12:44:32,492 INFO  [STDOUT] **********************************************************
              12:44:32,492 INFO  [STDOUT]       
              PersonID: 3
              Age: 15
              12:44:32,498 INFO  [STDOUT] **********************************************************
              12:44:32,498 INFO  [STDOUT] **           Message Receive from ESB                   **
              12:44:32,498 INFO  [STDOUT] **********************************************************
              12:44:32,498 INFO  [STDOUT]       
              PersonID: 4
              Age: 20
              12:44:34,257 INFO  [STDOUT] **********************************************************
              12:44:34,257 INFO  [STDOUT] **           Message Receive from ESB                   **
              12:44:34,258 INFO  [STDOUT] **********************************************************
              12:44:34,258 INFO  [STDOUT]       
              PersonID: 1
              Firstame: Max
              Lastname: Mustermann
              12:44:34,533 INFO  [STDOUT] Message: 
              12:44:34,533 INFO  [STDOUT] [2,28].
              12:44:34,536 INFO  [STDOUT] Message: 
              12:44:34,536 INFO  [STDOUT] [<personliste><person><id>2</id><age>28</age></person></personliste>].
              12:44:34,538 WARN  [ActionProcessingPipeline] No fault address defined for fault message! To: InVMEpr [ PortReference < <wsa:Address invm://73706c697474657254657374242424242424242424242424646250657273697374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] MessageID: 18b7468f-bb85-47d9-9282-c6c0c52e25e6
              12:44:34,673 INFO  [STDOUT] Message: 
              12:44:34,673 INFO  [STDOUT] [3,15].
              12:44:34,679 INFO  [STDOUT] Message: 
              12:44:34,679 INFO  [STDOUT] [<personliste><person><id>3</id><age>15</age></person></personliste>].
              12:44:34,681 WARN  [ActionProcessingPipeline] No fault address defined for fault message! To: InVMEpr [ PortReference < <wsa:Address invm://73706c697474657254657374242424242424242424242424646250657273697374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] MessageID: c592e112-c028-4b11-b0ed-3d90280d3b56
              12:44:34,824 INFO  [STDOUT] Message: 
              12:44:34,824 INFO  [STDOUT] [4,20].
              12:44:34,827 INFO  [STDOUT] Message: 
              12:44:34,827 INFO  [STDOUT] [<personliste><person><id>4</id><age>20</age></person></personliste>].
              12:44:34,829 WARN  [ActionProcessingPipeline] No fault address defined for fault message! To: InVMEpr [ PortReference < <wsa:Address invm://73706c697474657254657374242424242424242424242424646250657273697374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] MessageID: 6fd4634d-7725-4300-8624-34b82703eb48
              12:44:35,265 INFO  [STDOUT] **********************************************************
              12:44:35,265 INFO  [STDOUT] **           Message Receive from ESB                   **
              12:44:35,265 INFO  [STDOUT] **********************************************************
              12:44:35,266 INFO  [STDOUT]       
              PersonID: 2
              Firstame: Ingrid
              Lastname: Duck
              12:44:36,279 INFO  [STDOUT] **********************************************************
              12:44:36,279 INFO  [STDOUT] **           Message Receive from ESB                   **
              12:44:36,279 INFO  [STDOUT] **********************************************************
              12:44:36,279 INFO  [STDOUT]       
              PersonID: 3
              Firstame: Bernd
              Lastname: Schneider
              12:44:37,283 INFO  [STDOUT] **********************************************************
              12:44:37,283 INFO  [STDOUT] **           Message Receive from ESB                   **
              12:44:37,283 INFO  [STDOUT] **********************************************************
              12:44:37,283 INFO  [STDOUT]       
              PersonID: 4
              Firstame: Bettina
              Lastname: Klaus
              

               

              The data wasn't stored in the database. The Table was created. What am i doing wrong?

              • 4. Re: Smooks problem
                mzeijen

                I see that you are using the Persistence cartridge to persist the PersonAge pojo into the database using JPA.The problem is probably that persistence cartridge doesn't know how to insert it. Normally, in a non ESB environment, you would register a EntityManagerRegister object using the PersistenceUtil#setDAORegister() method. The EntityManagerRegister provides the persistence cartridge with the EntityManagerDaoAdapter. The EntityManagerDaoAdapter is the object that uses the EntityManager to actually persist the PersonAge pojo. Because you are in a ESB enviroment things are a bit different, because you have no way to set the EntityManagerRegister via the PersistenceUtil#setDAORegister() method before Smooks is executed. At the moment there is no standard way to do this from within Smooks so you will have to provide your own.

                 

                I propose that you write a simple visitor object that is executed on the document start (selector: #document). On the visitBefore method of that visitor you create a EntityManagerRegister, providing it your EntityContext (you could retrieve that via JNDI maybe) and  use the PersistenceUtil#setDAORegister() to register the EntityManagerRegister. Then your problem should be solved.

                 

                I must say that the persistence cartridge should provide you with a decent exception when no DaoRegister object is available. I will look into that.

                 

                I hope I provided you with enough an clear enough information to solve your problem.

                1 of 1 people found this helpful
                • 5. Re: Smooks problem
                  tfennelly

                  See this JIRA: https://jira.jboss.org/jira/browse/JBESB-3121

                   

                  Might explain why no error is appearing.

                  1 of 1 people found this helpful
                  • 6. Re: Smooks problem
                    tfennelly
                    Gilles... I hope the opening greeting in your first post on this thread was a Freudian Slip
                    • 7. Re: Smooks problem
                      tfennelly
                      Actually, this post should really be on the user forum, since it's not really about ESB dev.
                      • 8. Re: Smooks problem
                        tagnegilles

                        Thanks Maurice for the answer. I try to do what you said. But It doesn't work, may be i am doing something wrong

                         

                        I wrote this class

                         

                        package de.gilles.projects.splitteresb;
                        
                        import java.io.IOException;
                        
                        import javax.naming.InitialContext;
                        import javax.naming.NamingException;
                        import javax.persistence.EntityManager;
                        import javax.persistence.Persistence;
                        import javax.persistence.PersistenceUnit;
                        
                        import org.milyn.SmooksException;
                        import org.milyn.container.ExecutionContext;
                        import org.milyn.delivery.sax.SAXElement;
                        import org.milyn.delivery.sax.SAXVisitBefore;
                        import org.milyn.persistence.util.PersistenceUtil;
                        import org.milyn.scribe.adapter.jpa.EntityManagerRegister;
                        
                        @PersistenceUnit(name="persistence/personDB",unitName="persondb")
                        public class DBSaxVisitor implements SAXVisitBefore {
                        
                             @Override
                             public void visitBefore(SAXElement arg0, ExecutionContext arg1)
                                       throws SmooksException, IOException {
                                  try {
                                       InitialContext jndiContext = new InitialContext();
                                       EntityManager entityManager = (EntityManager) jndiContext.lookup("persistence/PersonDB");               
                                       EntityManagerRegister entityManagerRegister = new EntityManagerRegister(entityManager);
                                       PersistenceUtil.setDAORegister(arg1, entityManagerRegister);
                                       System.out.println("HI GUYS");
                                  } catch (NamingException e) {
                                       // TODO: handle exception
                                  }
                        
                                  
                             }
                        
                        }
                        

                         

                        But i don't know whether this wil work

                         

                        @PersistenceUnit(name="persistence/personDB",unitName="persondb")
                        public class DBSaxVisitor implements SAXVisitBefore {

                         

                        I registered the visitor in the dbSmooksConf.xml

                         

                        <?xml version="1.0" encoding="UTF-8"?>
                        <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
                             xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd" 
                             xmlns:ds="http://www.milyn.org/xsd/smooks/datasource-1.1.xsd"
                             xmlns:db="http://www.milyn.org/xsd/smooks/db-routing-1.1.xsd"
                             xmlns:dao="http://www.milyn.org/xsd/smooks/persistence-1.2.xsd">
                             
                             <resource-config selector="#document">
                                  <resource>de.gilles.projects.splitteresb.DBSaxVisitor</resource>
                             </resource-config>
                             
                             <jb:bean beanId="personage" class="de.gilles.projects.splitteresb.PersonAge" createOnElement="person">
                                  <jb:value property="id" data="person/id" decoder="Integer"/>
                                  <jb:value property="age" data="person/age" decoder="Integer"/>
                             </jb:bean>   
                        
                             <dao:inserter beanId="personage" insertOnElement="person"/>  
                             
                        </smooks-resource-list>
                        

                         

                        I started again. I don't see the output "HI GUYS" on the console. I still have this

                         

                        14:52:21,122 INFO  [STDOUT] [Splitter] Message Split complete: 
                        14:52:21,122 INFO  [STDOUT] [/Users/gilles/Desktop/ESB/Input/bien.csv.work].
                        14:52:21,236 INFO  [STDOUT] **********************************************************
                        14:52:21,236 INFO  [STDOUT] **           Message Receive from ESB                   **
                        14:52:21,237 INFO  [STDOUT] **********************************************************
                        14:52:21,237 INFO  [STDOUT]       
                        PersonID: 1
                        Age: 31
                        14:52:21,259 INFO  [STDOUT] Message: 
                        14:52:21,259 INFO  [STDOUT] [1,31].
                        14:52:21,271 INFO  [STDOUT] Message: 
                        14:52:21,271 INFO  [STDOUT] [<personliste><person><id>1</id><age>31</age></person></personliste>].
                        14:52:21,280 INFO  [STDOUT] **********************************************************
                        14:52:21,280 INFO  [STDOUT] **           Message Receive from ESB                   **
                        14:52:21,280 INFO  [STDOUT] **********************************************************
                        14:52:21,280 INFO  [STDOUT]       
                        PersonID: 2
                        Age: 28
                        14:52:21,302 WARN  [ActionProcessingPipeline] No fault address defined for fault message! To: InVMEpr [ PortReference < <wsa:Address invm://73706c697474657254657374242424242424242424242424646250657273697374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] MessageID: 4b427c32-e4a1-432d-a14b-73624bc86a7d
                        14:52:21,309 INFO  [STDOUT] **********************************************************
                        14:52:21,309 INFO  [STDOUT] **           Message Receive from ESB                   **
                        14:52:21,309 INFO  [STDOUT] **********************************************************
                        14:52:21,309 INFO  [STDOUT]       
                        PersonID: 3
                        Age: 15
                        14:52:21,321 INFO  [STDOUT] **********************************************************
                        14:52:21,321 INFO  [STDOUT] **           Message Receive from ESB                   **
                        14:52:21,321 INFO  [STDOUT] **********************************************************
                        14:52:21,321 INFO  [STDOUT]       
                        PersonID: 4
                        Age: 20
                        14:52:21,433 INFO  [STDOUT] Message: 
                        14:52:21,433 INFO  [STDOUT] [2,28].
                        14:52:21,435 INFO  [STDOUT] Message: 
                        14:52:21,435 INFO  [STDOUT] [<personliste><person><id>2</id><age>28</age></person></personliste>].
                        14:52:21,437 WARN  [ActionProcessingPipeline] No fault address defined for fault message! To: InVMEpr [ PortReference < <wsa:Address invm://73706c697474657254657374242424242424242424242424646250657273697374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] MessageID: b8836712-2aa0-46e3-8bb8-727eff97a792
                        14:52:21,517 INFO  [STDOUT] Message: 
                        14:52:21,517 INFO  [STDOUT] [3,15].
                        14:52:23,222 INFO  [STDOUT] **********************************************************
                        14:52:23,222 INFO  [STDOUT] **           Message Receive from ESB                   **
                        14:52:23,222 INFO  [STDOUT] **********************************************************
                        14:52:23,223 INFO  [STDOUT]       
                        PersonID: 1
                        Firstame: Max
                        Lastname: Mustermann
                        14:52:23,230 INFO  [STDOUT] Message: 
                        14:52:23,231 INFO  [STDOUT] [<personliste><person><id>3</id><age>15</age></person></personliste>].
                        14:52:23,233 WARN  [ActionProcessingPipeline] No fault address defined for fault message! To: InVMEpr [ PortReference < <wsa:Address invm://73706c697474657254657374242424242424242424242424646250657273697374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] MessageID: 414c3e4f-c58a-43f7-a0ec-02254044240c
                        14:52:23,384 INFO  [STDOUT] Message: 
                        14:52:23,384 INFO  [STDOUT] [4,20].
                        14:52:23,390 INFO  [STDOUT] Message: 
                        14:52:23,390 INFO  [STDOUT] [<personliste><person><id>4</id><age>20</age></person></personliste>].
                        14:52:23,392 WARN  [ActionProcessingPipeline] No fault address defined for fault message! To: InVMEpr [ PortReference < <wsa:Address invm://73706c697474657254657374242424242424242424242424646250657273697374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] MessageID: be7026f0-2d0d-4a96-bf3d-4700408538e4
                        14:52:25,532 INFO  [STDOUT] **********************************************************
                        14:52:25,532 INFO  [STDOUT] **           Message Receive from ESB                   **
                        14:52:25,532 INFO  [STDOUT] **********************************************************
                        14:52:25,532 INFO  [STDOUT]       
                        PersonID: 2
                        Firstame: Ingrid
                        Lastname: Duck
                        14:52:27,591 INFO  [STDOUT] **********************************************************
                        14:52:27,591 INFO  [STDOUT] **           Message Receive from ESB                   **
                        14:52:27,591 INFO  [STDOUT] **********************************************************
                        14:52:27,591 INFO  [STDOUT]       
                        PersonID: 3
                        Firstame: Bernd
                        Lastname: Schneider
                        14:52:28,595 INFO  [STDOUT] **********************************************************
                        14:52:28,595 INFO  [STDOUT] **           Message Receive from ESB                   **
                        14:52:28,595 INFO  [STDOUT] **********************************************************
                        14:52:28,596 INFO  [STDOUT]       
                        PersonID: 4
                        Firstame: Bettina
                        Lastname: Klaus
                        
                        • 9. Re: Smooks problem
                          mzeijen

                          It looks like that you haven't set the stream filter type to SAX. Because you haven't declared this the DBSaxVisitor won't be executed. Please include the following coding in your smooks configuration:

                           

                          <params>
                              <param name="stream.filter.type">SAX</param>
                          </params>
                          

                           

                          If this still doesn't work then please check if the EntityManager is actually returned from the jndi lookup or that you get the NamingException that you don't handle (according to your example). If that still doesn't work then maybe you could generate a execution report and attach it to this topic.

                          • 10. Re: Smooks problem
                            tagnegilles

                            Thanks Maurice for your help. I fund how to solve the problem. I wrote a ESB customer action GillesSmooksAction.java

                             

                            package de.gilles.projects.splitteresb;
                            
                            import java.io.ByteArrayInputStream;
                            
                            import javax.naming.InitialContext;
                            import javax.persistence.EntityManager;
                            import javax.persistence.EntityManagerFactory;
                            import javax.persistence.EntityTransaction;
                            import javax.persistence.Persistence;
                            import javax.persistence.PersistenceUnit;
                            import javax.xml.transform.stream.StreamSource;
                            
                            import org.jboss.soa.esb.actions.AbstractActionLifecycle;
                            import org.jboss.soa.esb.actions.ActionProcessingException;
                            import org.jboss.soa.esb.helpers.ConfigTree;
                            import org.jboss.soa.esb.message.Message;
                            import org.milyn.Smooks;
                            import org.milyn.container.ExecutionContext;
                            import org.milyn.event.report.HtmlReportGenerator;
                            import org.milyn.persistence.util.PersistenceUtil;
                            import org.milyn.scribe.adapter.jpa.EntityManagerRegister;
                            
                            public class GillesSmooksAction extends AbstractActionLifecycle {
                                 
                                 protected ConfigTree _configTree;
                                 
                                 public GillesSmooksAction(ConfigTree configTree){
                                      _configTree = configTree;
                                 }
                                 
                                 public Message process(Message message) throws ActionProcessingException {
                                      
                                      Smooks smooks = null;
                                      EntityManagerFactory emf = null;
                                      EntityManager em = null;
                                      
                                      try {
                                           String smooksConfigFile = _configTree.getAttribute("smooksConfig");
                                           if(smooksConfigFile == null){
                                                throw new Exception("The Attribute with the name: 'smooksConfig' doesn't exist." );
                                           }
                            
                                           InitialContext jndiContext = new InitialContext();
                                           emf = (EntityManagerFactory) jndiContext.lookup("java:/personDbEntityManagerFactory");
                                           em = emf.createEntityManager();
                                           smooks = new Smooks(smooksConfigFile);
                                           ExecutionContext executionContext = smooks.createExecutionContext();
                                           executionContext.setEventListener(new HtmlReportGenerator("/Users/gilles/Desktop/report/reportjpa.html"));
                                           PersistenceUtil.setDAORegister(executionContext, new EntityManagerRegister(em));
                                           EntityTransaction tx = em.getTransaction();
                                           tx.begin();
                                           smooks.filterSource(executionContext, new StreamSource(new ByteArrayInputStream(((String)message.getBody().get()).getBytes())));
                                           tx.commit();
                                           
                                      } catch (Exception e) {
                                           
                                           e.printStackTrace();
                                           throw new ActionProcessingException(e);               
                                      } 
                                      finally{
                                           
                                           try {
                                                if(em != null) em.close();
                                           } catch (Exception e2) {}
                                           
                                           try {
                                                if(emf != null) emf.close();
                                           } catch (Exception e2) {}
                                           
                                           if(smooks != null) smooks.close();
                                      }
                                      return message;
                                 }
                                 
                               public void exceptionHandler(Message message, Throwable exception) {
                                    logHeader();
                                    System.out.println("!ERROR!");
                                    System.out.println(exception.getMessage());
                                    System.out.println("For Message: ");
                                    System.out.println(message.getBody().get());
                                    logFooter();
                               }
                                 
                            
                               // This makes it easier to read on the console
                               private void logHeader() {
                                    System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
                               }
                               private void logFooter() {
                                    System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
                               }
                               
                            }
                            

                             

                            Then i changed the jboss-esb.xml, persistence.xml and the dbSmooksConf.xml

                             

                            jboss-esb.xml

                            <?xml version="1.0"?>
                            <jbossesb parameterReloadSecs="5"
                             xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd">
                             <providers>
                              <jms-provider connection-factory="ConnectionFactory" name="JbossMessaging">
                               <jms-bus busid="splitterChannel">
                                <jms-message-filter dest-name="/queue/splitterQueueAware" dest-type="QUEUE"/>
                               </jms-bus>
                              </jms-provider>
                              <schedule-provider name="CronSchedulerProvider">
                               <cron-schedule cronExpression="0/3 * * * * ?" scheduleid="myCronSchedule"/>
                              </schedule-provider>
                              <fs-provider name="FileSystemProvider">
                               <fs-bus busid="esbFileSystem">
                                <fs-message-filter directory="/Users/gilles/Desktop/ESB/Input"
                                 error-delete="false"
                                 error-directory="/Users/gilles/Desktop/ESB/Error"
                                 error-suffix=".error" input-suffix=".csv" post-delete="true"
                                 post-directory="/Users/gilles/Desktop/ESB/Post" post-suffix=".post" work-suffix=".work"/>
                               </fs-bus>
                              </fs-provider>
                             </providers>
                             <services>
                              <service category="splitterTest" description="Splitt the .csv file"
                               invmScope="GLOBAL" name="fileSplitter">
                               <listeners>
                                <fs-listener busidref="esbFileSystem" is-gateway="true"
                                 name="FileListener" scheduleidref="myCronSchedule">
                                 <property name="composer-class" value="org.jboss.soa.esb.smooks.splitting.FileStreamSplitter"/>
                                 <property name="splitterConfig" value="/mySmooksConf.xml"/>
                                </fs-listener>
                               </listeners>
                               <actions mep="OneWay">
                                <action class="org.jboss.soa.esb.actions.SystemPrintln" name="Print">
                                 <property name="message" value="[Splitter] Message Split complete"/>
                                </action>
                               </actions>
                              </service>
                              <service category="splitterTest"
                               description="Route the message to a jms queue" invmScope="GLOBAL" name="routerSplitter">
                               <actions mep="OneWay">
                                <action class="org.jboss.soa.esb.actions.Notifier" name="NotifyAction1">
                                 <property name="destinations">
                                  <NotificationList type="ok">
                                   <target class="NotifyQueues">
                                    <queue jndiName="queue/splitterQueue"/>
                                   </target>
                                  </NotificationList>
                                 </property>
                                 <property name="okMethod" value="notifyOK"/>
                                </action>
                            
                               </actions>
                              </service>
                              <service category="splitterTest"
                               description="Route the age element of the message to a jms queue"
                               invmScope="GLOBAL" name="routerAgeSplitter">
                               <actions mep="OneWay">
                                <action class="org.jboss.soa.esb.actions.Notifier" name="NotifyAction2">
                                 <property name="destinations">
                                  <NotificationList type="ok">
                                   <target class="NotifyQueues">
                                    <queue jndiName="queue/splitterAgeESBQueue"/>
                                   </target>
                                  </NotificationList>
                                 </property>
                                 <property name="okMethod" value="notifyOK"/>
                                </action>
                            
                               </actions>
                              </service>
                              <service category="splitterTest" description="Make routing on Age"
                               invmScope="GLOBAL" name="recipientListAge">
                               <actions mep="OneWay">
                                <action class="org.jboss.soa.esb.actions.StaticRouter" name="staticRoutingAge">
                                 <property name="destinations">
                                  <route-to destination-name="ToRouterAgeSplitter"
                                   service-category="splitterTest" service-name="routerAgeSplitter"/>
                                  <route-to destination-name="ToDbPersistAge"
                                   service-category="splitterTest" service-name="dbPersist"/>
                                 </property>
                                </action>
                               </actions>
                              </service>
                              <service category="splitterTest"
                               description="Persist data in the database" invmScope="GLOBAL" name="dbPersist">
                            
                               <actions mep="OneWay">
                                <action class="org.jboss.soa.esb.actions.SystemPrintln" name="PrintMessage1">
                                 <property name="message" value="Message"/>
                                </action>
                                <action class="org.jboss.soa.esb.smooks.SmooksAction" name="smoksActionXML">
                                 <property name="smooksConfig" value="/xmlSmooksConf.xml"/>
                                </action>
                                <action class="org.jboss.soa.esb.actions.SystemPrintln" name="PrintMessage2">
                                 <property name="message" value="Message"/>
                                </action>
                            
                                 <!-- GillesSmooksAction -->
                                <action class="de.gilles.projects.splitteresb.GillesSmooksAction" name="dbPersist">
                                 <property name="smooksConfig" value="/dbSmooksConf.xml"/>
                                </action>
                            
                            
                               </actions>
                              </service>
                             </services>
                            </jbossesb>
                            

                             

                            persistence.xml

                            <?xml version="1.0" encoding="UTF-8"?>
                            <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd ">
                                 <persistence-unit name="persondb" transaction-type="RESOURCE_LOCAL">
                                      <non-jta-data-source>java:/SplitterSqlDB</non-jta-data-source>
                                      <class>de.gilles.projects.splitteresb.PersonAge</class>
                                      <properties>
                                           <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
                                           <property name="hibernate.hbm2ddl.auto" value="create-drop" />     
                                           <property name="jboss.entity.manager.factory.jndi.name" value="java:/personDbEntityManagerFactory"/>     
                                      </properties>
                                 </persistence-unit>
                            </persistence>
                            

                             

                            dbSmooksConf.xml

                            <?xml version="1.0" encoding="UTF-8"?>
                            <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
                                 xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd" 
                                 xmlns:dao="http://www.milyn.org/xsd/smooks/persistence-1.2.xsd">
                                 
                                <params>        
                                    <param name="stream.filter.type">SAX</param>
                                </params>
                            
                                 <jb:bean beanId="personage" class="de.gilles.projects.splitteresb.PersonAge" createOnElement="person">
                                      <jb:value property="id" data="person/id" decoder="Integer"/>
                                      <jb:value property="age" data="person/age" decoder="Integer"/>
                                 </jb:bean>              
                            
                                 <dao:inserter beanId="personage" insertOnElement="person"/>  
                                 
                            </smooks-resource-list>
                            

                             

                            It works

                            • 11. Re: Smooks problem
                              mzeijen

                              Hi Gilles,

                               

                              I am glad that you solved the problem and that there is no bug in the Smooks Persistence code .

                               

                              One important note: I see in you code that you create a new Smooks instance for every message. This is a performance killer. You should make the Smooks a field of the GillesSmooksAction object and instantiate it in the 'initialise()' method. Then don't forget to close the Smooks object in the 'destroy() ' method. The Smooks object is thread safe, however the ExecutionContext not. So the ExectionContext needs to be created in the 'process' method, but that is very cheap. For more tips to boost the performance of Smooks take a look here: http://www.smooks.org/mediawiki/index.php?title=V1.2:Smooks_v1.2_User_Guide#Performance_Tuning. If you process a lot of messages concurrently then you should certainly upgrade to the latest 1.2 version of Smooks and use the new feature to pool the reader instances. You need to create a pool with the same size as the number of threads that are used to execute the action.

                               

                              Regards,

                               

                              Maurice

                              • 12. Re: Smooks problem
                                tagnegilles

                                Thanks Maurice for the advices. I changed the GillesSmooksAction.java

                                 

                                package de.gilles.projects.splitteresb;
                                
                                import java.io.ByteArrayInputStream;
                                import java.io.ByteArrayOutputStream;
                                
                                import javax.naming.InitialContext;
                                import javax.persistence.EntityManager;
                                import javax.persistence.EntityManagerFactory;
                                import javax.persistence.EntityTransaction;
                                import javax.xml.transform.stream.StreamResult;
                                import javax.xml.transform.stream.StreamSource;
                                
                                import org.jboss.soa.esb.actions.AbstractActionLifecycle;
                                import org.jboss.soa.esb.actions.ActionLifecycleException;
                                import org.jboss.soa.esb.actions.ActionProcessingException;
                                import org.jboss.soa.esb.helpers.ConfigTree;
                                import org.jboss.soa.esb.message.Message;
                                import org.milyn.Smooks;
                                import org.milyn.container.ExecutionContext;
                                import org.milyn.event.report.HtmlReportGenerator;
                                import org.milyn.persistence.util.PersistenceUtil;
                                import org.milyn.scribe.adapter.jpa.EntityManagerRegister;
                                
                                public class GillesSmooksAction extends AbstractActionLifecycle {
                                     
                                     protected ConfigTree _configTree;
                                     protected Smooks smooks = null;
                                     protected EntityManagerFactory emf = null;
                                     protected String smooksConfigFile = null;
                                     
                                     public GillesSmooksAction(ConfigTree configTree){
                                          _configTree = configTree;
                                     }
                                     
                                     public Message process(Message message) throws ActionProcessingException {
                                          
                                          EntityManager em = null;
                                          StreamResult result = new StreamResult(new ByteArrayOutputStream());
                                          
                                          try {
                                
                                               em = emf.createEntityManager();
                                               ExecutionContext executionContext = smooks.createExecutionContext();
                                               executionContext.setEventListener(new HtmlReportGenerator("/Users/gilles/Desktop/report/reportjpa.html"));
                                               PersistenceUtil.setDAORegister(executionContext, new EntityManagerRegister(em));
                                               EntityTransaction tx = em.getTransaction();
                                               
                                               tx.begin();
                                               smooks.filterSource(executionContext, new StreamSource(new ByteArrayInputStream(((String)message.getBody().get()).getBytes())),result);
                                               message.getBody().add(result.getOutputStream().toString());
                                               tx.commit();
                                               
                                          } catch (Exception e) {
                                               
                                               e.printStackTrace();
                                               throw new ActionProcessingException(e);               
                                          } 
                                          finally{
                                               
                                               try {
                                                    if(em != null) em.close();
                                               } catch (Exception e2) {}
                                               
                                               result = null;
                                          }
                                          return message;
                                     }
                                     
                                   public void exceptionHandler(Message message, Throwable exception) {
                                        logHeader();
                                        System.out.println("!ERROR!");
                                        System.out.println(exception.getMessage());
                                        System.out.println("For Message: ");
                                        System.out.println(message.getBody().get());
                                        logFooter();
                                   }
                                   
                                   @Override
                                     public void initialise() throws ActionLifecycleException {
                                          super.initialise();
                                          smooksConfigFile = _configTree.getAttribute("smooksConfig");
                                          
                                          try {
                                               if(smooksConfigFile == null){
                                                    throw new Exception("The Attribute with the name: 'smooksConfig' doesn't exist." );
                                               }
                                               
                                               InitialContext jndiContext = new InitialContext();
                                               emf = (EntityManagerFactory) jndiContext.lookup("java:/personDbEntityManagerFactory");               
                                               smooks = new Smooks(smooksConfigFile);
                                               
                                          } catch (Exception e) {
                                               e.printStackTrace();
                                               throw new ActionLifecycleException(e);
                                          }
                                
                                     }
                                
                                   
                                   @Override
                                     public void destroy() throws ActionLifecycleException {
                                          super.destroy();
                                          
                                          try {
                                               if(emf != null) {emf.close(); emf = null;}  
                                          } catch (Exception e2) {
                                               
                                               e2.printStackTrace();
                                               throw new ActionLifecycleException(e2);
                                          }
                                          
                                          if(smooks != null) {smooks.close(); smooks = null;}          
                                     }
                                
                                   // This makes it easier to read on the console
                                   private void logHeader() {
                                        System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
                                   }
                                   private void logFooter() {
                                        System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
                                   }
                                   
                                }
                                
                                

                                 

                                I have forgotten to mention it. I was obliged to add the milyn-scribe-core.1.2.4.jar in the esb.deployer because jboss couldn't found the ObjectStore.class. But i think Tom has already created a Jira to solve the problem https://jira.jboss.org/jira/browse/JBESB-3121.

                                Do you think i will give the reader.pool.size the value 3?

                                • 13. Re: Smooks problem
                                  mzeijen

                                  The number of Reader instances should be equal to the number of threads that you assign to the service listener. If you have multiple listeners (ignoring the gateway listener, because that doesn't actually execute the actions) then you should add up all the threads of the listeners and use that number for your pool size.

                                   

                                  So if your service can have 3 active threads executing it then a pool size of 3 is correct.

                                  • 14. Re: Smooks problem
                                    tagnegilles
                                    Thanks Maurice it's clear