You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2010/02/10 21:38:40 UTC
Re: onException: cannot get an exception object form exchange
properties.
JMS only stores body + headers. Any properties and the likes are not
stored. Hence what you move to jms:errors in the Message body.
If you want to store the Exception as well you gotta serialize it and
store it as a header etc.
You can try the transferExchange=true option on the JMS endpoint, then
Camel will store the entire Exchange including the Exception.
See more at the wiki page
http://camel.apache.org/jms.html
On Wed, Feb 10, 2010 at 6:35 PM, Nick Chistyakov <ch...@gmail.com> wrote:
> Hello camel riders!
> I found a problem on getting an exception object out of exchange.
> If I declare a route like this:
> onException(Exception.class)
> .handled(true)
> .to("jms:errrors");
>
> Then, I should be able to write a code like this:
> Exchange e = consumer.receive("jms:errrors", 1000);
> and I can access an exception by:
> e.getProperty(Exchange.EXCEPTION_CAUGHT);
> The problem is that there is no exception object (null instead of it) in
> case when I run the system composed of set of modules
> that all have the route above to handle exceptions.
>
> The simple unit test, where everything is one context will pass. But will
> fail in more complicated cases.
> The exchange will contain a message that was not delivered but somehow it
> will miss any information about exception.
>
> If I modify my route :)
> onException(Exception.class)
> .onWhen(new Predicate() {
> @Override
> public boolean matches(Exchange exchange) {
> exchange.getIn().setBody(exchange.getException());
> return true;
> }
> })
> .handled(true)
> .to("jms:errors");
> I will yet get it (instead of original message body though)
>
> Where can I find a code that finally serializes the exchange and sends it to
> destination?
> I tried to debug it but I'm not o experienced in camel internals, so I
> didn't find it.
> I would like to track what is going on.
> To make my point 100% clear I provided a small test project.
> It's a maven project so anyone can easily run it.
> It contains a Router and 2 test:
> OnExceptionGreenTest and
> OnExceptionRedTest
> one is passing one is not.
> Best regards,
> Nick
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: onException: cannot get an exception object form exchange
properties.
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
You can always put the caused exception to a Header as a String. The
JMS spec only allows a limited set of types to be used as JMS headers
(= JMS properties).
On Thu, Feb 11, 2010 at 2:58 PM, Nick Chistyakov <ch...@gmail.com> wrote:
> Hello Claus,
>
> transferExchange=true will not work, I tracked it down to Exchange
> transformation to ActiveMQObjectMessage
>
> ActiveMQSession.java:
> 1671: msg = (ActiveMQMessage)msg.copy();
>
> ActiveMQMessage.java
>
> ....
>
> public Message copy() {
> ActiveMQMessage copy = new ActiveMQMessage();
> copy(copy);
> return copy;
> }
>
> will call:
>
> ActiveMQObjectMessage.java
>
> private void copy(ActiveMQObjectMessage copy) {
> storeContent();
> super.copy(copy);
> copy.object = null;
> }
>
> and actually this copy.object is a place where the exception is stored in
> properties.
> It will not be copied and that information will be lost.
>
> Best regards,
> Nick
>
>
> On Wed, Feb 10, 2010 at 11:38 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> JMS only stores body + headers. Any properties and the likes are not
>> stored. Hence what you move to jms:errors in the Message body.
>> If you want to store the Exception as well you gotta serialize it and
>> store it as a header etc.
>>
>> You can try the transferExchange=true option on the JMS endpoint, then
>> Camel will store the entire Exchange including the Exception.
>> See more at the wiki page
>> http://camel.apache.org/jms.html
>>
>> On Wed, Feb 10, 2010 at 6:35 PM, Nick Chistyakov <ch...@gmail.com>
>> wrote:
>> > Hello camel riders!
>> > I found a problem on getting an exception object out of exchange.
>> > If I declare a route like this:
>> > onException(Exception.class)
>> > .handled(true)
>> > .to("jms:errrors");
>> >
>> > Then, I should be able to write a code like this:
>> > Exchange e = consumer.receive("jms:errrors", 1000);
>> > and I can access an exception by:
>> > e.getProperty(Exchange.EXCEPTION_CAUGHT);
>> > The problem is that there is no exception object (null instead of it) in
>> > case when I run the system composed of set of modules
>> > that all have the route above to handle exceptions.
>> >
>> > The simple unit test, where everything is one context will pass. But will
>> > fail in more complicated cases.
>> > The exchange will contain a message that was not delivered but somehow it
>> > will miss any information about exception.
>> >
>> > If I modify my route :)
>> > onException(Exception.class)
>> > .onWhen(new Predicate() {
>> > @Override
>> > public boolean matches(Exchange exchange) {
>> >
>> exchange.getIn().setBody(exchange.getException());
>> > return true;
>> > }
>> > })
>> > .handled(true)
>> > .to("jms:errors");
>> > I will yet get it (instead of original message body though)
>> >
>> > Where can I find a code that finally serializes the exchange and sends it
>> to
>> > destination?
>> > I tried to debug it but I'm not o experienced in camel internals, so I
>> > didn't find it.
>> > I would like to track what is going on.
>> > To make my point 100% clear I provided a small test project.
>> > It's a maven project so anyone can easily run it.
>> > It contains a Router and 2 test:
>> > OnExceptionGreenTest and
>> > OnExceptionRedTest
>> > one is passing one is not.
>> > Best regards,
>> > Nick
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: onException: cannot get an exception object form exchange
properties.
Posted by Claus Ibsen <cl...@gmail.com>.
See this unit test which works and uses the transferExchange option
https://svn.apache.org/repos/asf/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeadLetterQueueUsingTransferExchangeTest.java
On Thu, Feb 11, 2010 at 2:58 PM, Nick Chistyakov <ch...@gmail.com> wrote:
> Hello Claus,
>
> transferExchange=true will not work, I tracked it down to Exchange
> transformation to ActiveMQObjectMessage
>
> ActiveMQSession.java:
> 1671: msg = (ActiveMQMessage)msg.copy();
>
> ActiveMQMessage.java
>
> ....
>
> public Message copy() {
> ActiveMQMessage copy = new ActiveMQMessage();
> copy(copy);
> return copy;
> }
>
> will call:
>
> ActiveMQObjectMessage.java
>
> private void copy(ActiveMQObjectMessage copy) {
> storeContent();
> super.copy(copy);
> copy.object = null;
> }
>
> and actually this copy.object is a place where the exception is stored in
> properties.
> It will not be copied and that information will be lost.
>
> Best regards,
> Nick
>
>
> On Wed, Feb 10, 2010 at 11:38 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> JMS only stores body + headers. Any properties and the likes are not
>> stored. Hence what you move to jms:errors in the Message body.
>> If you want to store the Exception as well you gotta serialize it and
>> store it as a header etc.
>>
>> You can try the transferExchange=true option on the JMS endpoint, then
>> Camel will store the entire Exchange including the Exception.
>> See more at the wiki page
>> http://camel.apache.org/jms.html
>>
>> On Wed, Feb 10, 2010 at 6:35 PM, Nick Chistyakov <ch...@gmail.com>
>> wrote:
>> > Hello camel riders!
>> > I found a problem on getting an exception object out of exchange.
>> > If I declare a route like this:
>> > onException(Exception.class)
>> > .handled(true)
>> > .to("jms:errrors");
>> >
>> > Then, I should be able to write a code like this:
>> > Exchange e = consumer.receive("jms:errrors", 1000);
>> > and I can access an exception by:
>> > e.getProperty(Exchange.EXCEPTION_CAUGHT);
>> > The problem is that there is no exception object (null instead of it) in
>> > case when I run the system composed of set of modules
>> > that all have the route above to handle exceptions.
>> >
>> > The simple unit test, where everything is one context will pass. But will
>> > fail in more complicated cases.
>> > The exchange will contain a message that was not delivered but somehow it
>> > will miss any information about exception.
>> >
>> > If I modify my route :)
>> > onException(Exception.class)
>> > .onWhen(new Predicate() {
>> > @Override
>> > public boolean matches(Exchange exchange) {
>> >
>> exchange.getIn().setBody(exchange.getException());
>> > return true;
>> > }
>> > })
>> > .handled(true)
>> > .to("jms:errors");
>> > I will yet get it (instead of original message body though)
>> >
>> > Where can I find a code that finally serializes the exchange and sends it
>> to
>> > destination?
>> > I tried to debug it but I'm not o experienced in camel internals, so I
>> > didn't find it.
>> > I would like to track what is going on.
>> > To make my point 100% clear I provided a small test project.
>> > It's a maven project so anyone can easily run it.
>> > It contains a Router and 2 test:
>> > OnExceptionGreenTest and
>> > OnExceptionRedTest
>> > one is passing one is not.
>> > Best regards,
>> > Nick
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: onException: cannot get an exception object form exchange
properties.
Posted by Nick Chistyakov <ch...@gmail.com>.
Hello Claus,
transferExchange=true will not work, I tracked it down to Exchange
transformation to ActiveMQObjectMessage
ActiveMQSession.java:
1671: msg = (ActiveMQMessage)msg.copy();
ActiveMQMessage.java
....
public Message copy() {
ActiveMQMessage copy = new ActiveMQMessage();
copy(copy);
return copy;
}
will call:
ActiveMQObjectMessage.java
private void copy(ActiveMQObjectMessage copy) {
storeContent();
super.copy(copy);
copy.object = null;
}
and actually this copy.object is a place where the exception is stored in
properties.
It will not be copied and that information will be lost.
Best regards,
Nick
On Wed, Feb 10, 2010 at 11:38 PM, Claus Ibsen <cl...@gmail.com> wrote:
> JMS only stores body + headers. Any properties and the likes are not
> stored. Hence what you move to jms:errors in the Message body.
> If you want to store the Exception as well you gotta serialize it and
> store it as a header etc.
>
> You can try the transferExchange=true option on the JMS endpoint, then
> Camel will store the entire Exchange including the Exception.
> See more at the wiki page
> http://camel.apache.org/jms.html
>
> On Wed, Feb 10, 2010 at 6:35 PM, Nick Chistyakov <ch...@gmail.com>
> wrote:
> > Hello camel riders!
> > I found a problem on getting an exception object out of exchange.
> > If I declare a route like this:
> > onException(Exception.class)
> > .handled(true)
> > .to("jms:errrors");
> >
> > Then, I should be able to write a code like this:
> > Exchange e = consumer.receive("jms:errrors", 1000);
> > and I can access an exception by:
> > e.getProperty(Exchange.EXCEPTION_CAUGHT);
> > The problem is that there is no exception object (null instead of it) in
> > case when I run the system composed of set of modules
> > that all have the route above to handle exceptions.
> >
> > The simple unit test, where everything is one context will pass. But will
> > fail in more complicated cases.
> > The exchange will contain a message that was not delivered but somehow it
> > will miss any information about exception.
> >
> > If I modify my route :)
> > onException(Exception.class)
> > .onWhen(new Predicate() {
> > @Override
> > public boolean matches(Exchange exchange) {
> >
> exchange.getIn().setBody(exchange.getException());
> > return true;
> > }
> > })
> > .handled(true)
> > .to("jms:errors");
> > I will yet get it (instead of original message body though)
> >
> > Where can I find a code that finally serializes the exchange and sends it
> to
> > destination?
> > I tried to debug it but I'm not o experienced in camel internals, so I
> > didn't find it.
> > I would like to track what is going on.
> > To make my point 100% clear I provided a small test project.
> > It's a maven project so anyone can easily run it.
> > It contains a Router and 2 test:
> > OnExceptionGreenTest and
> > OnExceptionRedTest
> > one is passing one is not.
> > Best regards,
> > Nick
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>