3 Replies Latest reply on Jan 22, 2013 2:55 PM by Tom Cunningham

    Can't cast message body object when using Camel JPA Gateway

    Jason Wong Newbie

      I'm using JBoss SOA-P 5.3 and attempting to setup a Camel JPA gateway.  I pulled the camel-jpa-2.4.0.jar from FuseSource (http://repo.fusesource.com/maven2-legacy/org/apache/camel/camel-jpa/2.4.0-fuse-00-00/) since it doesn't come with SOA-P.  I have everything setup to where it polls the database, pulls in the record, and kicks off the action pipeline.  The weird behavior I'm seeing is that it says the message contents are an Order object (i.e. reference to the object) but it says its class is a String.  When I override the toString method on my object, the output shows that it is an Order.  When I try to cast the object to my Order object though I get the ClassCastException.  Any thoughts on why I can't cast the message body contents to my Order object?

       

      Below are the log outputs showing this disconnect (first one is w/o toString overridden and the second one is w/ toString overriden).

      ----------------------------------------------------------------------------------------

      12:34:53,583 INFO  [JPAProcessAction] Processing Message

      12:34:53,583 INFO  [JPAProcessAction] Message Properties: properties: [ {jboss.esb:category=MessageCounter,deployment=OrderStagingListener.esb,service-category=Staging,service-name=JPARecordProcessorTime=320664} ]

      12:34:53,583 INFO  [JPAProcessAction] Message Body: body: [ objects: {org.jboss.soa.esb.message.defaultEntry=com.foo.phase2.esb.jpa.Order@12938d7} ]

      12:34:53,584 INFO  [JPAProcessAction] Object: com.foo.phase2.esb.jpa.Order@12938d7

      12:34:53,584 INFO  [JPAProcessAction] Object Class: class java.lang.String

      12:34:53,686 ERROR [DefaultErrorHandler] Failed delivery for exchangeId: a529fe01-d83c-4eb9-91d6-2f56ddc8100f. Exhausted after delivery attempt: 1 caught: org.jboss.soa.esb.couriers.FaultMessageException: java.lang.ClassCastException: java.lang.String cannot be cast to com.foo.phase2.esb.jpa.Order

      ----------------------------------------------------------------------------------------

      12:35:56,151 INFO  [JPAProcessAction] Processing Message

      12:35:56,151 INFO  [JPAProcessAction] Message Properties: properties: [ {jboss.esb:category=MessageCounter,deployment=OrderStagingListener.esb,service-category=Staging,service-name=JPARecordProcessorTime=279859} ]

      12:35:56,151 INFO  [JPAProcessAction] Message Body: body: [ objects: {org.jboss.soa.esb.message.defaultEntry=Order - ID:1, Name:Joe, Email:foo@foo.com, Phone:1234567890, Address:1 Main} ]

      12:35:56,152 INFO  [JPAProcessAction] Object: Order - ID:1, Name:Joe, Email:foo@foo.com, Phone:1234567890, Address:1 Main

      12:35:56,152 INFO  [JPAProcessAction] Object Class: class java.lang.String

      12:35:56,153 ERROR [DefaultErrorHandler] Failed delivery for exchangeId: 95f99edd-5053-4a9e-a013-0b4aaab3792f. Exhausted after delivery attempt: 1 caught: org.jboss.soa.esb.couriers.FaultMessageException: java.lang.ClassCastException: java.lang.String cannot be cast to com.foo.phase2.esb.jpa.Order

      ----------------------------------------------------------------------------------------

       

      Here is the Action class that processes the message.

       

      @Process
      public void process(Message message) {
           log.info("Processing Message");
           log.info("Message Properties: " + message.getProperties());
           log.info("Message Body: " + message.getBody());
           log.info("Object: " + message.getBody().get(Body.DEFAULT_LOCATION));
           log.info("Object Class: " + message.getBody().get(Body.DEFAULT_LOCATION).getClass());
           Order order = (Order) message.getBody().get();
      } 
      
      

       

      Here is the jboss-esb.xml for the service.

       

      <?xml version="1.0" encoding="UTF-8"?>
      <jbossesb
           xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.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.3.0.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd"
           parameterReloadSecs="5">
      
           <providers>
                <camel-provider name="camelProvider">
                     <camel-bus busid="jpaBus">
                          <from uri="jpa:com.foo.phase2.esb.jpa.Order?consumeDelete=true&amp;consumer.delay=5000&amp;consumer.namedQuery=NewOrdersQuery" />
                     </camel-bus>
                </camel-provider>
           </providers>
      
           <services>
                <service category="Staging" name="JPARecordProcessor" description="Processes records" invmScope="GLOBAL">
                     <listeners>
                          <camel-gateway name="jpaGateway" busidref="jpaBus" />
                     </listeners>
                     <actions>
                          <action name="action" class="com.foo.phase2.esbactions.JPAProcessAction" />
                     </actions>
                </service>
           </services>
      </jbossesb>