Announcement Announcement Module
Collapse
No announcement yet.
cafe-amqp example, runtime exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • cafe-amqp example, runtime exception

    I've pulled the source for the latest spring integration examples and am having trouble with the last of four steps. The demo creates 100 drink orders and puts them onto a RabbitMQ queue. I can see that these have been created through the rabbitmq administration panel.

    The last step of the cafe-amqp demo is to run CafeDemoAppOperationsAmqp. What I am encountering is an error processing the payload of the message in the AmqpInboundChannelAdapter, which has the payload as an array of bytes. This might not be a problem; perhaps the payload is always an array of bytes. But when the payload is being transformed by the AbstractPayloadTransformer, an exception is thrown because the transformer wants a string instead of a byte array.

    The partial stack is shown below:

    Caused by: java.lang.ClassCastException: [B cannot be cast to java.lang.String
    at org.springframework.integration.json.JsonToObjectT ransformer.transformPayload(JsonToObjectTransforme r.java:30)
    at org.springframework.integration.transformer.Abstra ctPayloadTransformer.doTransform(AbstractPayloadTr ansformer.java:33)
    at org.springframework.integration.transformer.Abstra ctTransformer.transform(AbstractTransformer.java:3 3)
    I suppose I will inject my own transformer before the JsonToObjectTransformer is invoked to change the bytes to a string, but I'm sure there must be something wrong for this to happen.

    Any ideas?

  • #2
    I was able to get it to work by injecting the transformer as I mentioned I would try. The transformer is basic:

    Code:
    public class ByteArrayToJsonTransformer extends AbstractTransformer {
        @Override
        protected Object doTransform(Message<?> message) throws Exception {
            Object payload = message.getPayload();
            return new String((byte[]) payload);
        }
    }
    I injected this in the cafe-amqp configuration file cafeDemo-amqp-operations-xml.xml, just after the inbound-channel-adapter definition:

    Code:
        <bean class="com.sellis.transfomers.ByteArrayToJsonTransformer" id="byteArrayToJsonTransformer"/>
    
        <int:transformer input-channel="byteToJsonChannel" output-channel="jsonOrders"
                ref="byteArrayToJsonTransformer"/>
    
        <int:json-to-object-transformer id="json-to-order" input-channel="jsonOrders" output-channel="preOrders"
                                        type="org.springframework.integration.samples.cafe.Order" />
    Now the demo is running for me.

    Comment


    • #3
      When did you clone the repo? Have you pulled recent updates?

      This problem (https://jira.springsource.org/browse/INTSAMPLES-100) was fixed Jan 10th - https://github.com/SpringSource/spri...commits/master - see the 6th commit down.

      I just pulled Gunnar's changes and all worked fine for me.

      Comment


      • #4
        It was before the fix was put in. I'll pull and try again. I have to remember to check the open issues as well as the forums before posting here. Thanks for trying it out. Reading the text of the issue, it makes sense that the type of data would not be json text when the payload is processed by the transformer.

        Comment


        • #5
          As a follow up, I didn't pull the new samples since I have made some minor changes, such as adding an error logger. But I integrated Gunnar's changes and it works perfectly. This was a good learning experience, as my own solution was a hack at best; the addition of the content-type to the transformer is so much nicer. Thanks.

          Comment

          Working...
          X