You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Alex Paransky <ap...@standardset.com> on 2013/08/30 18:29:29 UTC

Messages seem to contain more than I expected...

Dear list members

I have defined the following route in my application:

    <camel:camelContext>
        <camel:route>
            <camel:from uri="direct:gozing/engine/user" />

            <camel:marshal>
                <camel:json library="Jackson"/>
            </camel:marshal>

            <camel:recipientList>
                <camel:simple id="java.lang.String">
                    stomp:topic:dm${body.userId}
                </camel:simple>
            </camel:recipientList>
        </camel:route>
    </camel:camelContext>

Here is how I am sending the message:

interface _Producer {
    void onUserEarningEvent(@Body UserEarningEvent e);
}

@Component
public class UserEventProducer  {

    @Produce(uri = "direct:gozing/engine/user")
    private _Producer
        producer;

    public void onUserEarningEvent(final UserEarningEvent e) {
        producer.onUserEarningEvent(e);
    }
}

However, it appears that what's get sent over is a bit more than I expected:

Method with name: userId not found on bean: [B@6cf54776 of type: [B.
Exchange[Message:
{"args":[*{"id":0,"userId":2,"created":null,"updated":null,"amount":5,"reason":"SingleClickOffer","description":"Reward
for Oakley GP-75 Dispatch II Sunglasses $55"}*
],"method":{"name":"onUserEarningEvent","returnType":"void","parameterTypes":["com.usamp.gozing.engine.messaging.event.user.earning.UserEarningEvent"],"exceptionTypes":[],"modifiers":1025,"annotations":[],"parameterAnnotations":[[{}]],"synthetic":false,"typeParameters":[],"declaringClass":"com.usamp.gozing.engine.messaging.producer.user._Producer","declaredAnnotations":[],"genericReturnType":"void","genericParameterTypes":["com.usamp.gozing.engine.messaging.event.user.earning.UserEarningEvent"],"genericExceptionTypes":[],"bridge":false,"varArgs":false,"defaultValue":null,"accessible":false}}]
at
org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:117)
~[camel-core-2.12-SNAPSHOT.jar:2.12-SNAPSHOT]


I really just expected to see this part in my actual message:
*{"id":0,"userId":2,"created":null,"updated":null,"amount":5,"reason":"SingleClickOffer","description":"Reward
for Oakley GP-75 Dispatch II Sunglasses $55"}*
*
*
Any ideas on what I can do to fix this.  I am sure it's something that I am
not understanding about how Camel works.

Thanks.
-AP_

Re: Messages seem to contain more than I expected...

Posted by apara <ap...@standardset.com>.
To close out this thread, here is the solution.  Because Camel does not know
that the consumer on the other end is NOT Camel, it wraps the @Produce into
a BeanInvocation object.  Using the convertBodyTo, I am able to tell Camel
to convert from BeanInvocation to the value of the first parameter.  Then,
after converting the message to JSON using Jackson, I once again tell Camel
to convert the message to a String.  Thus a text message is sent over the
STOMP connection and it gets to the browser via WebSocket as expected.

Here is the solution to the route issue I was having:

    <camel:camelContext>
        <camel:route>
            <camel:from uri="direct:gozing/engine/user" />

            <camel:convertBodyTo
type="com.usamp.gozing.engine.messaging.event.Event" />

            <camel:setHeader headerName="userId">
                <camel:simple resultType="java.lang.Integer">
                    ${body.userId}
                </camel:simple>
            </camel:setHeader>

            <camel:marshal>
                <camel:json library="Jackson"/>
            </camel:marshal>

            <camel:convertBodyTo type="java.lang.String" />

            <camel:recipientList>
                <camel:simple resultType="java.lang.String">
                    stomp:topic:dm${in.header.userId}
                </camel:simple>
            </camel:recipientList>
        </camel:route>
    </camel:camelContext>

Not sure if Header is a proper way to pass parameters/values between route
components, however.

-AP_




--
View this message in context: http://camel.465427.n5.nabble.com/Messages-seem-to-contain-more-than-I-expected-tp5738325p5738353.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Messages seem to contain more than I expected...

Posted by Alex Paransky <ap...@standardset.com>.
Claus,

This appears to be this issue which was resolved a while back:
https://issues.apache.org/jira/browse/CAMEL-2325?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

 On Aug 30, 2013 3:45 PM, "Alex Paransky" <ap...@standardset.com> wrote:

> So, here is what I currently have as a route:
>
>     <camel:camelContext>
>         <camel:route>
>             <camel:from uri="direct:gozing/engine/user" />
>
>             <camel:to uri="log:com.usamp.CAMEL-BEFORE?level=DEBUG" />
>
>             <camel:setHeader headerName="userId">
>                 <camel:simple>
>                     ${body.args[0].userId}
>                 </camel:simple>
>             </camel:setHeader>
>
>             <camel:marshal>
>                 <camel:json library="Jackson"/>
>             </camel:marshal>
>
>             <camel:recipientList>
>                 <camel:simple resultType="java.lang.String">
>                     stomp:topic:dm${in.header.userId}
>                 </camel:simple>
>             </camel:recipientList>
>
>             <camel:to uri="log:com.usamp.CAMEL-AFTER?level=DEBUG" />
>         </camel:route>
>     </camel:camelContext>
>
> Here are the debug messages, it seems that the body of the message is
> wrapped with the "Exchange".  How do I send just the body to JMS?
>
> 5:19:46.114 engine [qtp794815132-68] DEBUG CAMEL-BEFORE -
> Exchange[ExchangePattern: InOut, BodyType:
> org.apache.camel.component.bean.BeanInvocation, Body: BeanInvocation public
> abstract void
> com.usamp.gozing.engine.messaging.producer.user._Producer.onUserEarningEvent(com.usamp.gozing.engine.messaging.event.user.earning.UserEarningEvent)
> with [UserEarningEvent{id=0, userId=2, created=null, updated=null,
> amount=5, reason='SingleClickOffer', description='Reward for Bubble
> Inflatable Couch $38 Shipped'}]]]
>
> 15:19:46.530 engine [qtp794815132-68] DEBUG CAMEL-AFTER -
> Exchange[ExchangePattern: InOut, BodyType: byte[], Body:
> {"args":[{"id":0,"userId":2,"created":null,"updated":null,"amount":5,"reason":"SingleClickOffer","description":"Reward
> for Bubble Inflatable Couch $38
> Shipped"}],"method":{"name":"onUserEarningEvent","returnType":"void","parameterTypes":["com.usamp.gozing.engine.messaging.event.user.earning.UserEarningEvent"],"exceptionTypes":[],"modifiers":1025,"annotations":[],"parameterAnnotations":[[{}]],"synthetic":false,"typeParameters":[],"declaringClass":"com.usamp.gozing.engine.messaging.producer.user._Producer","declaredAnnotations":[],"genericReturnType":"void","genericParameterTypes":["com.usamp.gozing.engine.messaging.event.user.earning.UserEarningEvent"],"genericExceptionTypes":[],"bridge":false,"varArgs":false,"defaultValue":null,"accessible":false}}]
>
>
>
>
>
>
>
>
> On Fri, Aug 30, 2013 at 9:57 AM, apara <ap...@standardset.com> wrote:
>
>> I guess, I am not quite sure how the routes and expressions are working.
>>
>> The object which I am sending looks like this:
>>
>> public class UserEarningEvent {
>>     private int
>>         id;
>>
>>     private int
>>         userId;
>>
>> ...
>>     public int getUserId() {
>>         return userId;
>>     }
>> }
>>
>> On the other side of the route is a STOMP/WebSocket client, so the message
>> content I ultimately want to send is JSON.
>>
>> So, I am trying the following route:
>>
>>     <camel:camelContext>
>>         <camel:route>
>>             <camel:from uri="direct:gozing/engine/user" />
>>
>>             <camel:marshal>
>>                 <camel:json library="Jackson"/>
>>             </camel:marshal>
>>
>>             <camel:recipientList>
>>                 <camel:simple resultType="java.lang.String">
>>                     stomp:topic:dm${body.userId}
>>                 </camel:simple>
>>             </camel:recipientList>
>>         </camel:route>
>>     </camel:camelContext>
>>
>> But I am realizing that if I convert the object to JSON format, my
>> <camel:simple> expression may not work as expected.
>>
>> Here is what I actually want to do:
>>
>> 1) Take the original object of type UserEarningEvent
>> 2) Using userId construct a dynamic route
>> 3) Send JSON representation to the dynamic route constructed in 2)
>>
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Messages-seem-to-contain-more-than-I-expected-tp5738325p5738326.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>

Re: Messages seem to contain more than I expected...

Posted by Alex Paransky <ap...@standardset.com>.
So, here is what I currently have as a route:

    <camel:camelContext>
        <camel:route>
            <camel:from uri="direct:gozing/engine/user" />

            <camel:to uri="log:com.usamp.CAMEL-BEFORE?level=DEBUG" />

            <camel:setHeader headerName="userId">
                <camel:simple>
                    ${body.args[0].userId}
                </camel:simple>
            </camel:setHeader>

            <camel:marshal>
                <camel:json library="Jackson"/>
            </camel:marshal>

            <camel:recipientList>
                <camel:simple resultType="java.lang.String">
                    stomp:topic:dm${in.header.userId}
                </camel:simple>
            </camel:recipientList>

            <camel:to uri="log:com.usamp.CAMEL-AFTER?level=DEBUG" />
        </camel:route>
    </camel:camelContext>

Here are the debug messages, it seems that the body of the message is
wrapped with the "Exchange".  How do I send just the body to JMS?

5:19:46.114 engine [qtp794815132-68] DEBUG CAMEL-BEFORE -
Exchange[ExchangePattern: InOut, BodyType:
org.apache.camel.component.bean.BeanInvocation, Body: BeanInvocation public
abstract void
com.usamp.gozing.engine.messaging.producer.user._Producer.onUserEarningEvent(com.usamp.gozing.engine.messaging.event.user.earning.UserEarningEvent)
with [UserEarningEvent{id=0, userId=2, created=null, updated=null,
amount=5, reason='SingleClickOffer', description='Reward for Bubble
Inflatable Couch $38 Shipped'}]]]

15:19:46.530 engine [qtp794815132-68] DEBUG CAMEL-AFTER -
Exchange[ExchangePattern: InOut, BodyType: byte[], Body:
{"args":[{"id":0,"userId":2,"created":null,"updated":null,"amount":5,"reason":"SingleClickOffer","description":"Reward
for Bubble Inflatable Couch $38
Shipped"}],"method":{"name":"onUserEarningEvent","returnType":"void","parameterTypes":["com.usamp.gozing.engine.messaging.event.user.earning.UserEarningEvent"],"exceptionTypes":[],"modifiers":1025,"annotations":[],"parameterAnnotations":[[{}]],"synthetic":false,"typeParameters":[],"declaringClass":"com.usamp.gozing.engine.messaging.producer.user._Producer","declaredAnnotations":[],"genericReturnType":"void","genericParameterTypes":["com.usamp.gozing.engine.messaging.event.user.earning.UserEarningEvent"],"genericExceptionTypes":[],"bridge":false,"varArgs":false,"defaultValue":null,"accessible":false}}]








On Fri, Aug 30, 2013 at 9:57 AM, apara <ap...@standardset.com> wrote:

> I guess, I am not quite sure how the routes and expressions are working.
>
> The object which I am sending looks like this:
>
> public class UserEarningEvent {
>     private int
>         id;
>
>     private int
>         userId;
>
> ...
>     public int getUserId() {
>         return userId;
>     }
> }
>
> On the other side of the route is a STOMP/WebSocket client, so the message
> content I ultimately want to send is JSON.
>
> So, I am trying the following route:
>
>     <camel:camelContext>
>         <camel:route>
>             <camel:from uri="direct:gozing/engine/user" />
>
>             <camel:marshal>
>                 <camel:json library="Jackson"/>
>             </camel:marshal>
>
>             <camel:recipientList>
>                 <camel:simple resultType="java.lang.String">
>                     stomp:topic:dm${body.userId}
>                 </camel:simple>
>             </camel:recipientList>
>         </camel:route>
>     </camel:camelContext>
>
> But I am realizing that if I convert the object to JSON format, my
> <camel:simple> expression may not work as expected.
>
> Here is what I actually want to do:
>
> 1) Take the original object of type UserEarningEvent
> 2) Using userId construct a dynamic route
> 3) Send JSON representation to the dynamic route constructed in 2)
>
>
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Messages-seem-to-contain-more-than-I-expected-tp5738325p5738326.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Messages seem to contain more than I expected...

Posted by apara <ap...@standardset.com>.
I guess, I am not quite sure how the routes and expressions are working.

The object which I am sending looks like this:

public class UserEarningEvent {
    private int
        id;

    private int
        userId;

... 
    public int getUserId() {
        return userId;
    }
}

On the other side of the route is a STOMP/WebSocket client, so the message
content I ultimately want to send is JSON.

So, I am trying the following route:

    <camel:camelContext>
        <camel:route>
            <camel:from uri="direct:gozing/engine/user" />

            <camel:marshal>
                <camel:json library="Jackson"/>
            </camel:marshal>

            <camel:recipientList>
                <camel:simple resultType="java.lang.String">
                    stomp:topic:dm${body.userId}
                </camel:simple>
            </camel:recipientList>
        </camel:route>
    </camel:camelContext>

But I am realizing that if I convert the object to JSON format, my
<camel:simple> expression may not work as expected.

Here is what I actually want to do:

1) Take the original object of type UserEarningEvent 
2) Using userId construct a dynamic route
3) Send JSON representation to the dynamic route constructed in 2)



 



--
View this message in context: http://camel.465427.n5.nabble.com/Messages-seem-to-contain-more-than-I-expected-tp5738325p5738326.html
Sent from the Camel - Users mailing list archive at Nabble.com.