0 Replies Latest reply on Jun 15, 2011 6:29 AM by Kamil Khan

    Error while sending XML payload to CBR service

    Kamil Khan Newbie

      Hi All,

       

      I'm facing a strange error, possibly because of my own stupid mistake.

      But I've spent a few days and i'm still not able to understand the cause.

       

      I'm trying Content Based Routing with Drools on JBoss ESB 4.9 server (got the same error on 4.5 as well)

       

      When I run the simple_cbr quickstart, it runs perfectly.

      But when I try to implement almost exactly the same thing manually with my Eclipse IDE, I get the following exception.

       

      15:34:08,322 ERROR [JmsComposer] Object in JMS message is not a Serializeable
      java.io.IOException: Util.deserialize caught XMLStreamException
          at org.jboss.soa.esb.util.Util.deserialize(Util.java:225)
          at org.jboss.internal.soa.esb.couriers.helpers.JmsComposer.compose(JmsComposer.java:72)
          at org.jboss.internal.soa.esb.couriers.JmsCourier.pickup(JmsCourier.java:461)
          at org.jboss.internal.soa.esb.couriers.TwoWayCourierImpl.pickup(TwoWayCourierImpl.java:228)
          at org.jboss.internal.soa.esb.couriers.TwoWayCourierImpl.pickup(TwoWayCourierImpl.java:204)
          at org.jboss.soa.esb.listeners.message.MessageAwareListener.waitForEventAndProcess(MessageAwareListener.java:297)
          at org.jboss.soa.esb.listeners.message.MessageAwareListener.doRun(MessageAwareListener.java:253)
          at org.jboss.soa.esb.listeners.lifecycle.AbstractThreadedManagedLifecycle.run(AbstractThreadedManagedLifecycle.java:115)
          at java.lang.Thread.run(Thread.java:636)
      Caused by: javax.xml.stream.XMLStreamException: Unexpected start element: Order
          at org.jboss.internal.soa.esb.util.stax.StreamHelper.checkTag(StreamHelper.java:364)
          at org.jboss.internal.soa.esb.util.stax.StreamHelper.checkNextStartTag(StreamHelper.java:336)
          at org.jboss.soa.esb.util.Util.deserialize(Util.java:218)
          ... 8 more
      

       

      My file contents are as follows:

       

      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.0.1.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.0.1.xsd http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd">
      
       <providers>
      
        <jms-provider connection-factory="ConnectionFactory" name="TestCBR_P">
      
         <jms-bus busid="CBRbus">
          <jms-message-filter dest-name="queue/CBRq" dest-type="QUEUE"/>
         </jms-bus>
      
         <jms-bus busid="busA">
          <jms-message-filter dest-name="queue/qA" dest-type="QUEUE"/>
         </jms-bus>
      
         <jms-bus busid="busB">
          <jms-message-filter dest-name="queue/qB" dest-type="QUEUE"/>
         </jms-bus>
      
         <jms-bus busid="busC">
          <jms-message-filter dest-name="queue/qC" dest-type="QUEUE"/>
         </jms-bus>
      
        </jms-provider>
       </providers>
      
       <services>
      
        <service category="myCat"
         description="Accepts message and routes to respective service" name="routerService">
         <property name="inVMPassByValue" value="true"/>
         <listeners>
          <jms-listener busidref="CBRbus" name="TestCBR_L"/>
         </listeners>
         <actions>
          <action class="myActions.DisplayMsg" name="displayMessageAction" process="displayMessage"/>
          <action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="DroolsAction">
           <property name="ruleSet" value="myRules_xpath.drl"/>
           <property name="ruleLanguage" value="XPathLanguage.dsl"/>
           <property name="ruleReload" value="true"/>
           <property name="destinations">
            <route-to destination-name="A" service-category="route" service-name="A"/>
            <route-to destination-name="B" service-category="route" service-name="B"/>
            <route-to destination-name="C" service-category="route" service-name="C"/>
           </property>
          </action>
         </actions>
        </service>
      
        <service category="route" description="Service A" name="A">
         <listeners>
          <jms-listener busidref="busA" name="A_CBR_L"/>
         </listeners>
         <actions>
          <action class="myActions.DisplayMsg" name="displayMessageAction" process="displayMessage"/>
          <action class="myActions.A" name="DisplayAction"/>
         </actions>
        </service>
      
        <service category="route" description="Service B" name="B">
         <listeners>
          <jms-listener busidref="busB" name="B_CBR_L"/>
         </listeners>
         <actions>
          <action class="myActions.DisplayMsg" name="displayMessageAction" process="displayMessage"/>
          <action class="myActions.B" name="DisplayAction"/>
         </actions>
        </service>
      
        <service category="route" description="Service C" name="C">
         <listeners>
          <jms-listener busidref="busC" name="C_CBR_L"/>
         </listeners>
         <actions>
          <action class="myActions.DisplayMsg" name="displayMessageAction" process="displayMessage"/>
          <action class="myActions.C" name="DisplayAction"/>
         </actions>
        </service>
      
       </services>
      </jbossesb>
      

       

      myOrder.xml

       

      <Order orderId="1" orderDate="Wed Nov 15 13:45:28 EST 2006" statusCode="0" 
      netAmount="59.97" totalAmount="4.99" tax="4.95">
          <Customer userName="user1" firstName="Harry" lastName="Fletcher" state="SD"/>
          <OrderLines>
              <OrderLine position="1" quantity="1">
                  <Product productId="364" title="The 40-Year-Old Virgin " price="29.98"/>
              </OrderLine>
              <OrderLine position="2" quantity="1">
                  <Product productId="299" title="Pulp Fiction" price="29.99"/>
              </OrderLine>
          </OrderLines>
      </Order>
      

       

      SendXMLmsg.java

       

      package iPack;
      
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.jms.JMSException;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueSession;
      import javax.jms.QueueSender;
      import javax.jms.ObjectMessage;
      
      import java.io.File;
      import java.io.FileReader;
      import java.io.IOException;
      
      public class SendXMLmsg {
      
             QueueConnection conn;
              QueueSession session;
              Queue que;
      
      
              public void setupConnection() throws JMSException, NamingException
              {
                  InitialContext iniCtx = new InitialContext();
                  Object tmp = iniCtx.lookup("ConnectionFactory");
                  QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
                  conn = qcf.createQueueConnection();
                  que = (Queue) iniCtx.lookup("queue/CBRq");
                  session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
                  conn.start();
                  System.out.println("Connection Started");
              }
      
              public void stop() throws JMSException 
              { 
                  conn.stop();
                  session.close();
                  conn.close();
              }
      
              public void sendAMessage(String msg) throws JMSException {
      
                  QueueSender send = session.createSender(que);
                  ObjectMessage tm = session.createObjectMessage(msg);
                  tm.setStringProperty("jbesbfilename", "SimpleCBRTest.log"); 
                  send.send(tm);
                  send.close();
              }
              public String readAsciiFile(String fileName) throws IOException {
                    FileReader fr = null;
                    char[] thechars = null;
      
                    try {
                        File thefile = new File( fileName );
                        fr = new FileReader( thefile );
                        int size = (int) thefile.length();
                        thechars = new char[size];
      
                        int count, index = 0;
      
                        //     read in the bytes from the input stream
                        while( ( count = fr.read( thechars, index, size ) ) > 0 ) {
                            size -= count;
                            index += count;
                        }
                      } catch(Exception e) {    
                          System.out.println(e);
                      }
                      finally {
                          if( fr != null )
                          fr.close();
                      }
                      return new String(thechars);
      
              } // readAsciiFile
      
              public static void main(String[] args) throws Exception {
      
                  SendXMLmsg sm = new SendXMLmsg();
                  sm.setupConnection();
                  String fileContent = sm.readAsciiFile("/home/kamil/A1/myOrder.xml");
                  System.out.println("---------------------------------------------");
                  System.out.println(fileContent);
                  System.out.println("---------------------------------------------");
                  sm.sendAMessage(fileContent); 
                  sm.stop();
      
          }
      
      }
      

       

      myRules_xpath.drl

       

      #created on: Jun 1, 2011
      package test
      
      #list any import classes here.
      import org.jboss.soa.esb.message.Message;
      import org.jboss.soa.esb.message.format.MessageType;
      
      expander XPathLanguage.dsl
      
      #declare any global variables here
      global java.util.List destinations;
      
      
      rule "Routing Rule 1"
          when
              xpathLessThan "/Order/@totalAmount", "5.0"
          then 
              Destination : "A";        
      end
      
      rule "Routing Rule 2"
          when
              xpathEquals "/Order/@totalAmount", "5.0"
          then 
              Destination : "B";        
      end
      
      rule "Routing Rule 3"
          when
              #xpathGreaterThan "/Order/@totalAmount", "5.0"
          then 
              Destination : "C";        
      end
      

       

      and my action classes

       

      DisplayMsg.java

       

      package myActions;
      
      import org.jboss.soa.esb.helpers.ConfigTree;
      import org.jboss.soa.esb.message.Message;
      import org.jboss.soa.esb.actions.AbstractActionLifecycle;
      
      public class DisplayMsg extends AbstractActionLifecycle {
      
          protected ConfigTree    _config;
      
            public DisplayMsg(ConfigTree config) { _config = config; } 
      
            public Message noOperation(Message message) { return message; } 
      
            public Message displayMessage(Message message) throws Exception{        
                    logHeader();
                    System.out.println("Body: " + message.getBody().get());
                    logFooter();
                    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("\n______________________________________________");
             }
             private void logFooter() {
                 System.out.println("_______________________________________________\n");
             }
      
      }
      

       

      A.java (B.java and C.java are identical)

       

      package myActions;
      
      import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor;
      import org.jboss.soa.esb.actions.ActionProcessingException;
      import org.jboss.soa.esb.helpers.ConfigTree;
      import org.jboss.soa.esb.message.Message;
      
      public class A extends AbstractActionPipelineProcessor {
      
          public A(ConfigTree config){}
      
          public Message process(Message arg0) throws ActionProcessingException {
              System.out.println("This is Service A");
              return null;
          }
      
      }
      

       

      Thanks & Regards,

      Kamil.