2 Replies Latest reply on Mar 1, 2007 6:26 AM by Mohamed Riyaz

    Newb Question - How to send objects in message payload

    Mohamed Riyaz Newbie

      Hi,

      How do we send javabeans as part of message payload.

      I tried with the quickstart ESBmessageclient. I am getting the following exception.:
      ################################################
      Exception in thread "main" org.jboss.soa.esb.couriers.CourierException: java.io.IOException: org.jboss.soa.esb.MarshalException: Cannot pack object customer
      at org.jboss.internal.soa.esb.couriers.JmsCourier.deliver(JmsCourier.java:181)
      at org.jboss.internal.soa.esb.couriers.TwoWayCourierImpl.deliver(TwoWayCourierImpl.java:157)
      at org.jboss.soa.esb.listeners.ListenerUtil.tryToDeliver(ListenerUtil.java:70)
      at sendobjects.client.SendEsbMessage.main(SendEsbMessage.java:34)
      Caused by: java.io.IOException: org.jboss.soa.esb.MarshalException: Cannot pack object customer
      at org.jboss.soa.esb.util.Util.serialize(Util.java:189)
      at org.jboss.internal.soa.esb.couriers.JmsCourier.deliver(JmsCourier.java:168)
      ... 3 more
      ################################################

      my code is as follows:
      Message esbMessage = MessageFactory.getInstance().getMessage();
      Call call = new Call();
      call.setMessageID(new URI(UUID.randomUUID().toString()));
      esbMessage.getHeader().setCall(call);
      Customer customer = new Customer();
      customer.setCustAddr("Hyderabad");
      customer.setCustId("Cust012");
      customer.setCustName("Andy");
      esbMessage.getBody().add("customer", customer);
      ListenerUtil.tryToDeliver(esbMessage, category, name);

      Thanks in advance

        • 1. Re: Newb Question - How to send objects in message payload
          Ashish Rajhansha Newbie

          Hi,

          I am quoting some lines from the ProgrammersGuide - Might help U. -

          More complex content may be added through the add method, which supports named Objects. Names must be unique on behalf of a given Message or an appropriate exception will be thrown. Using <name, Object> pairs allows for a finer granularity of data access. The type of Objects that can be added to the Body can be arbitrary: they do not need to be Java Serializable. However, in the case where non-Serializable Objects are added, it is necessary to provide JBossESB with the ability to marshal/unmarshal the Message when it flows across the network.
          See the section of Message Formats for more details.

          Note:Caution: we discourage the general use of Serialized Java objects in
          messages because it constrains the service implementations. Use with
          care.

          In general you will find it easier to work with the Message Body through the namedObject approach. You can add, remove and inspect individual data items within the Message payload without having to decode the entire Body. Furthermore, you can combine named Objects within the payload with the byte array.

          Ashish

          • 2. Re: Newb Question - How to send objects in message payload
            Mohamed Riyaz Newbie

            Thank you Ashish

            The problem was because the javabean which I was trying to add to the message payload didn implement the Serializable interface.

            Now I have changed the javabean to implement Serializable interface and it works fine.

            Riyaz