[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: onException - properties and headers are lost


Hi Reji,

You can use useOriginalMessage()
<https://github.com/apache/camel/blob/master/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionUseOriginalMessageTest.java>
in onException to restore the original message body you received at from().
Like this:
onException(java.net.SocketException.class)
        .useOriginalMessage()
        .handled(true)
...
If the original message body was a stream you should enable stream caching
<http://camel.apache.org/stream-caching.html> on the route
(from("...").streamCaching()) or on the Camel Context.

Also there might be another problem with your route as exchange properties
should be available within onException(). Message headers are a bit
different as the endpoints called during the route modifies them a lot, but
if you store something in an exchange property at the beginning, it should
be available in onException.

Can you share the whole route and the storeOriginalPayloadInDb processor?
Which Camel version do you use exactly?

Regards,
Balazs

On Tue, Jun 5, 2018 at 2:29 AM Reji Mathews <contactreji@xxxxxxxxx> wrote:

> Hi guys
>
> I have a business requirement where if an api call fails, I need to store
> the payload in a database for future retry.
>
> I have an onException clause like this
>
> onException(java.net.SocketException.class)
>         .handled(true)
>         .maximumRedeliveries(3)
>         .log("Records are dropping due to excessing number of socket
> connections created. Dropping DPCI : ${property.dpci} , TCIN :
> ${property.tcin}")
>         .to("log:MYAUDIT_2?showAll=true")
>         .process(storeOriginalPayloadInDb)
>         .end();
>
>
> I have added a property called "originalPayload" containing the received
> data. I want it to access the property in processor "
> *storeOriginalPayloadInDb*"
>
> I get NullPointorException accessing the property "originalPayload" ,
> reason being all headers and properties of the original exchange are lost
> by the time flow comes to onException block.
>
> What is the way I can achieve my requirement?
>
> Cheers
>