You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by SoaMattH <ma...@netpacket.com.au> on 2009/10/05 09:24:19 UTC

Error Handling: mix of onTry...OnCatch and


The problem:
Occasionally I am getting poorly formed XML and am trying to fixit on the
fly.
Most of the time I can, 1% of the time I cannot.

In the route below this is what I want to do
1. pick up the file.
2. Use Jaxb to unmarshal
3. call the validate bean
4. call the incidentReceiverFile bean 
5. on sucessfull completion the file ends up in a processed directory
    On failure it ends up in the dead letter folder.

The route works well for well formed XML, if the unmarshal throws an error
It calls the incidentValidate?method=filterBadUTFEncoding, most of the time
this works
except for when my filterBadUTFEncoding cannot fix the bad XML (Which is
about 1% of the time)
On this case I want the file to go to dead letter folder.


The Route:
<camel:route errorHandlerRef="incidentDeadLetter" id="incidentFileRouteA">
  <camel:from ref="incidentFileEndPoint" />
    <camel:doTry>
      <camel:unmarshal ref="incidentJaxb" />
      <camel:doCatch>
        <camel:exception>org.xml.sax.SAXParseException</camel:exception>
       
<camel:exception>org.apache.xerces.impl.io.MalformedByteSequenceException</camel:exception>
        <camel:handled>
          <camel:constant>true</camel:constant>
        </camel:handled>
        <!-- retry by trying to fix the xml -->
        <camel:to uri="bean:incidentValidate?method=filterBadUTFEncoding" />
        <!-- If unmarshal fails should the camel:onException catch Me -->
        <camel:unmarshal ref="incidentJaxb" />
      </camel:doCatch>
    </camel:doTry>
        
    <camel:to uri="bean:incidentValidate?method=validate" />
    <camel:to uri="bean:incidentReceiverFile?method=processIncident" />
        
    <camel:onException useOriginalMessage="true" >
    <camel:exception>java.lang.Exception</camel:exception>
      <camel:redeliveryPolicy maximumRedeliveries="0" />
      <camel:handled>
        <camel:constant>true</camel:constant>
      </camel:handled>
    <camel:to
uri="log:au.gov.qld.des.integration.oms.business.incident?level=FATAL"/>
    <camel:to uri="bean:incidentDeadLetter" />
    <camel:to uri="log:au.gov.qld.des?showAll=true&amp;level=FATAL"/>
  </camel:onException>
</camel:route>     


I am expecting the <camel:onException> to catch any errors out of the on
catch retry ....
is this so ? the file stays in the incidentFileEndPoint directory that the
route watches and trys
to process over and over ....... What am I missing ??

Thanks Matt

-- 
View this message in context: http://www.nabble.com/Error-Handling%3A-mix-of-onTry...OnCatch-and-%3ConException%3E-tp25746191p25746191.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Error Handling: mix of onTry...OnCatch and

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I will split the "try to patch the file" code into a 2nd route as this
generally works better than deep nested route logic.

And then use direct endpoint to "link" the two routes.

>        <!-- retry by trying to fix the xml -->
>        <camel:to uri="bean:incidentValidate?method=filterBadUTFEncoding" />

Should then be
        <camel:to uri="direct:pathAndRerty" />


<route>
   <from uri="direct:patchAndRetry"/>
        <camel:to uri="bean:incidentValidate?method=filterBadUTFEncoding" />
        <!-- If unmarshal fails should the camel:onException catch Me -->
        <camel:unmarshal ref="incidentJaxb" />
</route>



On Mon, Oct 5, 2009 at 9:24 AM, SoaMattH <ma...@netpacket.com.au> wrote:
>
>
> The problem:
> Occasionally I am getting poorly formed XML and am trying to fixit on the
> fly.
> Most of the time I can, 1% of the time I cannot.
>
> In the route below this is what I want to do
> 1. pick up the file.
> 2. Use Jaxb to unmarshal
> 3. call the validate bean
> 4. call the incidentReceiverFile bean
> 5. on sucessfull completion the file ends up in a processed directory
>    On failure it ends up in the dead letter folder.
>
> The route works well for well formed XML, if the unmarshal throws an error
> It calls the incidentValidate?method=filterBadUTFEncoding, most of the time
> this works
> except for when my filterBadUTFEncoding cannot fix the bad XML (Which is
> about 1% of the time)
> On this case I want the file to go to dead letter folder.
>
>
> The Route:
> <camel:route errorHandlerRef="incidentDeadLetter" id="incidentFileRouteA">
>  <camel:from ref="incidentFileEndPoint" />
>    <camel:doTry>
>      <camel:unmarshal ref="incidentJaxb" />
>      <camel:doCatch>
>        <camel:exception>org.xml.sax.SAXParseException</camel:exception>
>
> <camel:exception>org.apache.xerces.impl.io.MalformedByteSequenceException</camel:exception>
>        <camel:handled>
>          <camel:constant>true</camel:constant>
>        </camel:handled>
>        <!-- retry by trying to fix the xml -->
>        <camel:to uri="bean:incidentValidate?method=filterBadUTFEncoding" />
>        <!-- If unmarshal fails should the camel:onException catch Me -->
>        <camel:unmarshal ref="incidentJaxb" />
>      </camel:doCatch>
>    </camel:doTry>
>
>    <camel:to uri="bean:incidentValidate?method=validate" />
>    <camel:to uri="bean:incidentReceiverFile?method=processIncident" />
>
>    <camel:onException useOriginalMessage="true" >
>    <camel:exception>java.lang.Exception</camel:exception>
>      <camel:redeliveryPolicy maximumRedeliveries="0" />
>      <camel:handled>
>        <camel:constant>true</camel:constant>
>      </camel:handled>
>    <camel:to
> uri="log:au.gov.qld.des.integration.oms.business.incident?level=FATAL"/>
>    <camel:to uri="bean:incidentDeadLetter" />
>    <camel:to uri="log:au.gov.qld.des?showAll=true&amp;level=FATAL"/>
>  </camel:onException>
> </camel:route>
>
>
> I am expecting the <camel:onException> to catch any errors out of the on
> catch retry ....
> is this so ? the file stays in the incidentFileEndPoint directory that the
> route watches and trys
> to process over and over ....... What am I missing ??
>
> Thanks Matt
>
> --
> View this message in context: http://www.nabble.com/Error-Handling%3A-mix-of-onTry...OnCatch-and-%3ConException%3E-tp25746191p25746191.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Error Handling: mix of onTry...OnCatch and

Posted by SoaMattH <ma...@netpacket.com.au>.

I broke the route up into two routes and it seems to be working fine.

Thanks Matt



SoaMattH wrote:
> 
> 
> The problem:
> Occasionally I am getting poorly formed XML and am trying to fixit on the
> fly.
> Most of the time I can, 1% of the time I cannot.
> 
> In the route below this is what I want to do
> 1. pick up the file.
> 2. Use Jaxb to unmarshal
> 3. call the validate bean
> 4. call the incidentReceiverFile bean 
> 5. on sucessfull completion the file ends up in a processed directory
>     On failure it ends up in the dead letter folder.
> 
> The route works well for well formed XML, if the unmarshal throws an error
> It calls the incidentValidate?method=filterBadUTFEncoding, most of the
> time this works
> except for when my filterBadUTFEncoding cannot fix the bad XML (Which is
> about 1% of the time)
> On this case I want the file to go to dead letter folder.
> 
> 
> The Route:
> <camel:route errorHandlerRef="incidentDeadLetter" id="incidentFileRouteA">
>   <camel:from ref="incidentFileEndPoint" />
>     <camel:doTry>
>       <camel:unmarshal ref="incidentJaxb" />
>       <camel:doCatch>
>         <camel:exception>org.xml.sax.SAXParseException</camel:exception>
>        
> <camel:exception>org.apache.xerces.impl.io.MalformedByteSequenceException</camel:exception>
>         <camel:handled>
>           <camel:constant>true</camel:constant>
>         </camel:handled>
>         <!-- retry by trying to fix the xml -->
>         <camel:to uri="bean:incidentValidate?method=filterBadUTFEncoding"
> />
>         <!-- If unmarshal fails should the camel:onException catch Me -->
>         <camel:unmarshal ref="incidentJaxb" />
>       </camel:doCatch>
>     </camel:doTry>
>         
>     <camel:to uri="bean:incidentValidate?method=validate" />
>     <camel:to uri="bean:incidentReceiverFile?method=processIncident" />
>         
>     <camel:onException useOriginalMessage="true" >
>     <camel:exception>java.lang.Exception</camel:exception>
>       <camel:redeliveryPolicy maximumRedeliveries="0" />
>       <camel:handled>
>         <camel:constant>true</camel:constant>
>       </camel:handled>
>     <camel:to
> uri="log:au.gov.qld.des.integration.oms.business.incident?level=FATAL"/>
>     <camel:to uri="bean:incidentDeadLetter" />
>     <camel:to uri="log:au.gov.qld.des?showAll=true&amp;level=FATAL"/>
>   </camel:onException>
> </camel:route>     
> 
> 
> I am expecting the <camel:onException> to catch any errors out of the on
> catch retry ....
> is this so ? the file stays in the incidentFileEndPoint directory that the
> route watches and trys
> to process over and over ....... What am I missing ??
> 
> Thanks Matt
> 
> 

-- 
View this message in context: http://www.nabble.com/Error-Handling%3A-mix-of-onTry...OnCatch-and-%3ConException%3E-tp25746191p25757182.html
Sent from the Camel - Users mailing list archive at Nabble.com.