You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by gsilverman <gs...@dispensingsolutionsinc.com> on 2011/06/08 17:31:31 UTC
Splitter StopOnException doesn't forward the exception on the
Exchange
I have the following route which uses stopOnException to catch exceptions:
<route errorHandlerRef="queryFormularyError">
<from uri="seda:createRx" />
<split strategyRef="aggregatorStrategy"
parallelProcessing="true" stopOnException="true">
<method bean="processSegment" method="split" />
<bean ref="processSegment" method="process" />
</split>
<to uri="direct:dispense" />
</route>
The processSegment bean in the above route can throw the following
exception:
throw new Exception("Product, " + vendorndc + ", is not in formulary")
I want the caught exception to be processed by the errorHandlerRef in the
route element but when I call
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class) in the
error handler, the exception getMessage() method returns null, not the
message in the thrown exception.
Here is my error handler:
public class QueryFormularyErrorHandler implements Processor{
private static final transient Logger LOG =
LoggerFactory.getLogger(QueryFormularyErrorHandler.class);
public void process(Exchange exchange) throws Exception {
Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
Exception.class);
LOG.info("Query formulary error: " + e.getMessage());
exchange.getIn().setBody(e.getMessage());
}
}
--
View this message in context: http://camel.465427.n5.nabble.com/Splitter-StopOnException-doesn-t-forward-the-exception-on-the-Exchange-tp4469882p4469882.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Splitter StopOnException doesn't forward the exception on the
Exchange
Posted by gsilverman <gs...@dispensingsolutionsinc.com>.
I don't believe the AggregatorStrategy is the problem, but here is mine:
public class DispensingAggregationStrategy implements AggregationStrategy{
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
if (oldExchange == null)
return newExchange;
NewDispensingBean body =
newExchange.getIn().getBody(NewDispensingBean.class);
NewDispensingBean existing =
oldExchange.getIn().getBody(NewDispensingBean.class);
existing.aggregate(body);
Object rde = newExchange.getIn().getHeader("rde");
if(rde != null)
oldExchange.getIn().setHeader("rde", rde);
oldExchange.getIn().setBody(existing);
return oldExchange;
}
}
This just agregates the splitter results into a NewDispensingBean. As I
mentioned earlier, I tried to capture the error using the following in the
Aggregator, but newExchange.getException() was always null:
if (newExchange.getException() != null) {
if (oldExchange == null) {
return newExchange;
} else {
oldExchange.setException(
newExchange.getException());
return oldExchange;
}
}
--
View this message in context: http://camel.465427.n5.nabble.com/Splitter-StopOnException-doesn-t-forward-the-exception-on-the-Exchange-tp4469882p4476414.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Splitter StopOnException doesn't forward the exception on the Exchange
Posted by Claus Ibsen <cl...@gmail.com>.
I cannot reproduce this on trunk. What do you do in that custom
aggregatorStrategy you do?
On Wed, Jun 8, 2011 at 5:31 PM, gsilverman
<gs...@dispensingsolutionsinc.com> wrote:
> I have the following route which uses stopOnException to catch exceptions:
>
> <route errorHandlerRef="queryFormularyError">
> <from uri="seda:createRx" />
> <split strategyRef="aggregatorStrategy"
> parallelProcessing="true" stopOnException="true">
> <method bean="processSegment" method="split" />
> <bean ref="processSegment" method="process" />
> </split>
> <to uri="direct:dispense" />
> </route>
>
> The processSegment bean in the above route can throw the following
> exception:
>
> throw new Exception("Product, " + vendorndc + ", is not in formulary")
>
> I want the caught exception to be processed by the errorHandlerRef in the
> route element but when I call
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class) in the
> error handler, the exception getMessage() method returns null, not the
> message in the thrown exception.
>
> Here is my error handler:
>
> public class QueryFormularyErrorHandler implements Processor{
> private static final transient Logger LOG =
> LoggerFactory.getLogger(QueryFormularyErrorHandler.class);
> public void process(Exchange exchange) throws Exception {
> Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
> Exception.class);
>
> LOG.info("Query formulary error: " + e.getMessage());
> exchange.getIn().setBody(e.getMessage());
> }
>
> }
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Splitter-StopOnException-doesn-t-forward-the-exception-on-the-Exchange-tp4469882p4469882.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: Splitter StopOnException doesn't forward the exception on the Exchange
Posted by Claus Ibsen <cl...@gmail.com>.
I have created a ticket to improve this
https://issues.apache.org/jira/browse/CAMEL-4080
On Thu, Jun 9, 2011 at 5:36 PM, Claus Ibsen <cl...@gmail.com> wrote:
> When moving to the DLQ there is no caused exception attached and
> whatnot. Its the original message *as is*.
>
>
> On Thu, Jun 9, 2011 at 5:15 PM, gsilverman
> <gs...@dispensingsolutionsinc.com> wrote:
>> Yes. I'm using camel v2.71.
>>
>> Here is my error handler:
>>
>> <errorHandler id="queryFormularyError" type="DeadLetterChannel"
>> deadLetterUri="direct:queryFormularyError" useOriginalMessage="true" />
>>
>> and the deadletter route is:
>>
>> <route>
>> <from uri="direct:queryFormularyError" />
>> <process ref="queryformularyErrorHandler" />
>> <to uri="bean:createReturnMsg" />
>> </route>
>>
>> The queryFormularyErrorHandler refers to the QueryFormularyErrorHandler
>> processor described earlier, and the createReturnMsg bean just translates
>> the exception message into a format that can be returned to the caller.
>>
>> I tried handling the error in the AggregatorStrategy, as described in the
>> Camel Book chapter 8, but that did not work. I couldn't get it to trap the
>> error at all. In the meantime, I've resorted to handling the error after
>> splitter/aggregator returns and transfers control to a new route, but I
>> would much prefer handling errors as they occur, in the splitter.
>>
>> Thanks for your help.
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Splitter-StopOnException-doesn-t-forward-the-exception-on-the-Exchange-tp4469882p4473105.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: Splitter StopOnException doesn't forward the exception on the
Exchange
Posted by gsilverman <gs...@dispensingsolutionsinc.com>.
So, if I understand you correctly, I shouldn't use the DeadLetterChannel type
in the error handler. What types are available and how would I then
configure the error handler?
--
View this message in context: http://camel.465427.n5.nabble.com/Splitter-StopOnException-doesn-t-forward-the-exception-on-the-Exchange-tp4469882p4473197.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Splitter StopOnException doesn't forward the exception on the Exchange
Posted by Claus Ibsen <cl...@gmail.com>.
When moving to the DLQ there is no caused exception attached and
whatnot. Its the original message *as is*.
On Thu, Jun 9, 2011 at 5:15 PM, gsilverman
<gs...@dispensingsolutionsinc.com> wrote:
> Yes. I'm using camel v2.71.
>
> Here is my error handler:
>
> <errorHandler id="queryFormularyError" type="DeadLetterChannel"
> deadLetterUri="direct:queryFormularyError" useOriginalMessage="true" />
>
> and the deadletter route is:
>
> <route>
> <from uri="direct:queryFormularyError" />
> <process ref="queryformularyErrorHandler" />
> <to uri="bean:createReturnMsg" />
> </route>
>
> The queryFormularyErrorHandler refers to the QueryFormularyErrorHandler
> processor described earlier, and the createReturnMsg bean just translates
> the exception message into a format that can be returned to the caller.
>
> I tried handling the error in the AggregatorStrategy, as described in the
> Camel Book chapter 8, but that did not work. I couldn't get it to trap the
> error at all. In the meantime, I've resorted to handling the error after
> splitter/aggregator returns and transfers control to a new route, but I
> would much prefer handling errors as they occur, in the splitter.
>
> Thanks for your help.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Splitter-StopOnException-doesn-t-forward-the-exception-on-the-Exchange-tp4469882p4473105.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: Splitter StopOnException doesn't forward the exception on the
Exchange
Posted by gsilverman <gs...@dispensingsolutionsinc.com>.
Yes. I'm using camel v2.71.
Here is my error handler:
<errorHandler id="queryFormularyError" type="DeadLetterChannel"
deadLetterUri="direct:queryFormularyError" useOriginalMessage="true" />
and the deadletter route is:
<route>
<from uri="direct:queryFormularyError" />
<process ref="queryformularyErrorHandler" />
<to uri="bean:createReturnMsg" />
</route>
The queryFormularyErrorHandler refers to the QueryFormularyErrorHandler
processor described earlier, and the createReturnMsg bean just translates
the exception message into a format that can be returned to the caller.
I tried handling the error in the AggregatorStrategy, as described in the
Camel Book chapter 8, but that did not work. I couldn't get it to trap the
error at all. In the meantime, I've resorted to handling the error after
splitter/aggregator returns and transfers control to a new route, but I
would much prefer handling errors as they occur, in the splitter.
Thanks for your help.
--
View this message in context: http://camel.465427.n5.nabble.com/Splitter-StopOnException-doesn-t-forward-the-exception-on-the-Exchange-tp4469882p4473105.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Splitter StopOnException doesn't forward the exception on the Exchange
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Can you post more details about how you configured the error handler?
And what version of Camel are you using?
On Wed, Jun 8, 2011 at 5:31 PM, gsilverman
<gs...@dispensingsolutionsinc.com> wrote:
> I have the following route which uses stopOnException to catch exceptions:
>
> <route errorHandlerRef="queryFormularyError">
> <from uri="seda:createRx" />
> <split strategyRef="aggregatorStrategy"
> parallelProcessing="true" stopOnException="true">
> <method bean="processSegment" method="split" />
> <bean ref="processSegment" method="process" />
> </split>
> <to uri="direct:dispense" />
> </route>
>
> The processSegment bean in the above route can throw the following
> exception:
>
> throw new Exception("Product, " + vendorndc + ", is not in formulary")
>
> I want the caught exception to be processed by the errorHandlerRef in the
> route element but when I call
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class) in the
> error handler, the exception getMessage() method returns null, not the
> message in the thrown exception.
>
> Here is my error handler:
>
> public class QueryFormularyErrorHandler implements Processor{
> private static final transient Logger LOG =
> LoggerFactory.getLogger(QueryFormularyErrorHandler.class);
> public void process(Exchange exchange) throws Exception {
> Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
> Exception.class);
>
> LOG.info("Query formulary error: " + e.getMessage());
> exchange.getIn().setBody(e.getMessage());
> }
>
> }
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Splitter-StopOnException-doesn-t-forward-the-exception-on-the-Exchange-tp4469882p4469882.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: Splitter StopOnException doesn't forward the exception on the Exchange
Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jun 8, 2011 at 5:31 PM, gsilverman
<gs...@dispensingsolutionsinc.com> wrote:
> I have the following route which uses stopOnException to catch exceptions:
>
> <route errorHandlerRef="queryFormularyError">
> <from uri="seda:createRx" />
> <split strategyRef="aggregatorStrategy"
> parallelProcessing="true" stopOnException="true">
> <method bean="processSegment" method="split" />
> <bean ref="processSegment" method="process" />
> </split>
> <to uri="direct:dispense" />
> </route>
>
> The processSegment bean in the above route can throw the following
> exception:
>
> throw new Exception("Product, " + vendorndc + ", is not in formulary")
>
> I want the caught exception to be processed by the errorHandlerRef in the
> route element but when I call
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class) in the
> error handler, the exception getMessage() method returns null, not the
> message in the thrown exception.
>
Ah okay so there is an Exception. Check what type the exception is.
The caused exception could be wrapped.
So there may be a cause on the exception, and if you drill down it
most likely contain your exception = new Exception("Product, " +
vendorndc + ", is not in formulary")
> Here is my error handler:
>
> public class QueryFormularyErrorHandler implements Processor{
> private static final transient Logger LOG =
> LoggerFactory.getLogger(QueryFormularyErrorHandler.class);
> public void process(Exchange exchange) throws Exception {
> Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
> Exception.class);
>
> LOG.info("Query formulary error: " + e.getMessage());
> exchange.getIn().setBody(e.getMessage());
> }
>
> }
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Splitter-StopOnException-doesn-t-forward-the-exception-on-the-Exchange-tp4469882p4469882.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/