You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Miguel Ruiz Velasco Sobrino <mi...@fcm.com.mx> on 2018/01/11 07:37:40 UTC

Backpropagate exception on direct: and vm: routes

Hi!,

I have a route (direct: or VM:) with lots of processors, each one does a 
tiny part of a huge validation. Sometimes a processor in the middle 
encounters an error (and throws an exception). At this point the 
validation has to stop, not executing the remainder of the route AND 
returning to the caller to manage the exception. The pattern is a 
request-reply.

The route has the following structure:



<camel:route id="cfdi33Validation">
             <camel:from uri="direct:cfdi33Validation"/>
             <camel:from uri="vm:cfdi33Validation"/>

             <camel:process ref="testCfdi33Processor"/>
             <camel:process ref="cfdi33XSDValidatorProcessor" id="XSD 
CFDI33"/>
             <camel:process ref="cfdi33extractCfdi33Fields" 
id="extractFields"/>
             <camel:process ref="descontarPlanRecepcionProcessor" 
id="descontarPlan CFDI 3.3"/>

             <camel:process ref="cfdi33ValidarTfdCertificado"/>
...
             <camel:process ref="cfdi33SelloTfdValidator"/>
         </camel:route>

Sometimes the descontarPlanRecepcionProcessor encounters an error (and 
throws an exception) . The route must return the error to it's caller 
route. The exception must be propagated to the caller route. Currently 
the exception is logged and discarded, but the original caller timeout 
because it expects an answer that never arrives.

I have read the docs, but cannot figure how to do the above.

Can anyone have any idea?

Regards,

-- 
Miguel Ruiz Velasco Sobrino
FCM Computacion Mexicana SAPI de CV
http://fcm.com.mx   (55)5682-0041


Re: Backpropagate exception on direct: and vm: routes

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
Try adding
<continued>
    <constant>true</constant>
</continued>
to the onException element

Quinn Stevenson
quinn@pronoia-solutions.com
(801) 244-7758



> On Jan 12, 2018, at 10:44 AM, Miguel Ruiz Velasco Sobrino <mi...@fcm.com.mx> wrote:
> 
>  the same as me:
> https://stackoverflow.com/questions/34617646/return-back-from-current-route-in-apache-camel-and-continue-routing <https://stackoverflow.com/questions/34617646/return-back-from-current-route-in-apache-camel-and-continue-routing>
> 
> First I did this:
>            <camel:onException>
>                <camel:exception>/SomeException/</camel:exception>
> <camel:handled><camel:constant>true</camel


Re: Backpropagate exception on direct: and vm: routes

Posted by Miguel Ruiz Velasco Sobrino <mi...@fcm.com.mx>.
Dear Quinn,

I found the following Stackoverflow post asking the same as me:
https://stackoverflow.com/questions/34617646/return-back-from-current-route-in-apache-camel-and-continue-routing

First I did this:
             <camel:onException>
                 <camel:exception>/SomeException/</camel:exception>
<camel:handled><camel:constant>true</camel:constant></camel:handled>
                 <camel:log loggingLevel="WARN" message="ERROR en la 
ruta cfdi33Validation ${body.class} ${exception}" />
                 <camel:setHeader headerName="fatal">
<camel:constant>true</camel:constant>
                 </camel:setHeader>
                 <camel:to 
uri="log:cfdi33Validation?level=DEBUG&amp;showCaughtException=true&amp;showStackTrace=true&amp;showHeaders=true"/>
             </camel:onException>
and
             <camel:onException>
                 <camel:exception>/SomeException/</camel:exception>
<camel:handled><camel:constant>true</camel:constant></camel:handled>
                 <camel:log loggingLevel="WARN" message="ERROR en la 
ruta cfdi33Validation ${body.class} ${exception}" />
                 <camel:setHeader headerName="fatal">
<camel:constant>true</camel:constant>
                 </camel:setHeader>
                 <camel:to 
uri="log:cfdi33Validation?level=DEBUG&amp;showCaughtException=true&amp;showStackTrace=true&amp;showHeaders=true"/>
                 <camel:stop/>
</camel:onException>

The handled=true made the route finish, but did not return to the caller 
route, it tried directly to return a response to JMS (and failed because 
of missing processing).

Based on the post answer, and my own failures, I modified the route 
definition to look like this:

         <camel:route id="cfdi33Validation">
             <camel:from uri="direct:Validation"/>
             <camel:from uri="vm:Validation"/>
             <camel:onException>
                 <camel:exception>/SomeException/</camel:exception>
<camel:continued><camel:constant>true</camel:constant></camel:continued>
                 <camel:log loggingLevel="WARN" message="ERROR en la 
ruta cfdi33Validation ${body.class} ${exception}" />
                 <camel:setHeader headerName="fatal">
<camel:constant>true</camel:constant>
                 </camel:setHeader>
                 <camel:to 
uri="log:cfdi33Validation?level=DEBUG&amp;showCaughtException=true&amp;showStackTrace=true&amp;showHeaders=true"/>
             </camel:onException>

             <camel:process ref="testCfdi33Processor"/>
             <camel:process ref="cfdi33XSDValidatorProcessor" id="XSD 
CFDI33"/>
             <camel:process ref="cfdi33SchematronValidatorProcessor" 
id="SCH CFDI33"/>
             <camel:process ref="cfdi33extractCfdi33Fields" 
id="extractFields"/>
             <camel:process ref="descontarPlanRecepcionProcessor" 
id="descontarPlan CFDI 3.3"/>
...
         </camel:route>

After an exception is raised, OnException sets fatal and the following 
the processors return immediately if the see the /fatal/ header.

public class ExtractCFDI33FieldsProcessor implements Processor, 
InitializingBean {
     @Override
     public void process(Exchange ex) throws Exception {
         if(ex.getIn().getHeader("fatal", false, Boolean.class)==true)
             return;
         ...


This a [very] ugly workarround, but barely works. I think would be 
better to cut the route processing short (like a return in the middle of 
a function).


Regards,

Miguel Ruiz Velasco Sobrino
FCM Computacion Mexicana SAPI de CV
http://fcm.com.mx   (55)5682-0041

On 01/12/2018 08:22 AM, Quinn Stevenson wrote:
> I don’t see an <onException …> element in the route - are you handling the exception?
>
> Quinn Stevenson
> quinn@pronoia-solutions.com
> (801) 244-7758
>
>
>
>> On Jan 11, 2018, at 12:37 AM, Miguel Ruiz Velasco Sobrino <mi...@fcm.com.mx> wrote:
>>
>> Hi!,
>>
>> I have a route (direct: or VM:) with lots of processors, each one does a tiny part of a huge validation. Sometimes a processor in the middle encounters an error (and throws an exception). At this point the validation has to stop, not executing the remainder of the route AND returning to the caller to manage the exception. The pattern is a request-reply.
>>
>> The route has the following structure:
>>
>>
>>
>> <camel:route id="cfdi33Validation">
>>             <camel:from uri="direct:cfdi33Validation"/>
>>             <camel:from uri="vm:cfdi33Validation"/>
>>
>>             <camel:process ref="testCfdi33Processor"/>
>>             <camel:process ref="cfdi33XSDValidatorProcessor" id="XSD CFDI33"/>
>>             <camel:process ref="cfdi33extractCfdi33Fields" id="extractFields"/>
>>             <camel:process ref="descontarPlanRecepcionProcessor" id="descontarPlan CFDI 3.3"/>
>>
>>             <camel:process ref="cfdi33ValidarTfdCertificado"/>
>> ...
>>             <camel:process ref="cfdi33SelloTfdValidator"/>
>>         </camel:route>
>>
>> Sometimes the descontarPlanRecepcionProcessor encounters an error (and throws an exception) . The route must return the error to it's caller route. The exception must be propagated to the caller route. Currently the exception is logged and discarded, but the original caller timeout because it expects an answer that never arrives.
>>
>> I have read the docs, but cannot figure how to do the above.
>>
>> Can anyone have any idea?
>>
>> Regards,
>>
>> -- 
>> Miguel Ruiz Velasco Sobrino
>> FCM Computacion Mexicana SAPI de CV
>> http://fcm.com.mx   (55)5682-0041
>>



Re: Backpropagate exception on direct: and vm: routes

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
I don’t see an <onException …> element in the route - are you handling the exception?

Quinn Stevenson
quinn@pronoia-solutions.com
(801) 244-7758



> On Jan 11, 2018, at 12:37 AM, Miguel Ruiz Velasco Sobrino <mi...@fcm.com.mx> wrote:
> 
> Hi!,
> 
> I have a route (direct: or VM:) with lots of processors, each one does a tiny part of a huge validation. Sometimes a processor in the middle encounters an error (and throws an exception). At this point the validation has to stop, not executing the remainder of the route AND returning to the caller to manage the exception. The pattern is a request-reply.
> 
> The route has the following structure:
> 
> 
> 
> <camel:route id="cfdi33Validation">
>            <camel:from uri="direct:cfdi33Validation"/>
>            <camel:from uri="vm:cfdi33Validation"/>
> 
>            <camel:process ref="testCfdi33Processor"/>
>            <camel:process ref="cfdi33XSDValidatorProcessor" id="XSD CFDI33"/>
>            <camel:process ref="cfdi33extractCfdi33Fields" id="extractFields"/>
>            <camel:process ref="descontarPlanRecepcionProcessor" id="descontarPlan CFDI 3.3"/>
> 
>            <camel:process ref="cfdi33ValidarTfdCertificado"/>
> ...
>            <camel:process ref="cfdi33SelloTfdValidator"/>
>        </camel:route>
> 
> Sometimes the descontarPlanRecepcionProcessor encounters an error (and throws an exception) . The route must return the error to it's caller route. The exception must be propagated to the caller route. Currently the exception is logged and discarded, but the original caller timeout because it expects an answer that never arrives.
> 
> I have read the docs, but cannot figure how to do the above.
> 
> Can anyone have any idea?
> 
> Regards,
> 
> -- 
> Miguel Ruiz Velasco Sobrino
> FCM Computacion Mexicana SAPI de CV
> http://fcm.com.mx   (55)5682-0041
>