Re: Handling Exception from marshal/unmarshal
On Sat, May 16, 2009 at 10:59 PM, Joe Gottman wrote: > > Here is a small project. I hope it is understandable. I don't know JIRA > well enough to create a ticket. > http://www.nabble.com/file/p23577706/uncompressTest.7z uncompressTest.7z > > Here's the relevant part of the route: > > .doTry() > .unmarshal(new JaxbDataFormat("camel.unmarshal.test")) > .doCatch(Exception.class) > // .transform().constant(JaxbExceptionHandler.errorMessage) > //This works. > .bean(JaxbExceptionHandler.class, "handleError") //This fails, > even though > the bean is called > .end() > > When I called the .bean method (or the .setBody() method) after catching > an unmarshal exception, the results were not saved. On the other hand, > calling transform() worked for some reason. The problem is that you have to think about you exchange is InOnly or InOut. Eg if you exepct a reply or not. If its InOut (Request/Reply) then Camel will use the OUT message as response. - setBody will only set the IN message. - transform will set the OUT message Some wiki pages to look at: http://camel.apache.org/request-reply.html http://camel.apache.org/message-translator.html > > > > > Claus Ibsen-2 wrote: >> >> Hi >> >> Can you create a small project or unit test demonstrating this? >> And if so please create a JIRA ticket and attach the sample project. >> >> Then we have a good head start to investigate, and see what the problem >> is. >> >> In the mean time you are welcome to try with 2.0-SNAPSHOT to see if >> the problem still exists. >> Instructions on the Camel download page, how to get it. >> >> >> On Tue, May 12, 2009 at 2:55 PM, Joe Gottman >> wrote: >>> >>> >>> >>> Claus Ibsen-2 wrote: On Tue, May 12, 2009 at 2:13 AM, Joe Gottman wrote: Can you show the route DSL how you do this? You should generally use handled(true) to clear the exception. Or use doTry() .. doCatch() just as you would use try .. catch in normal Java http://camel.apache.org/try-catch-finally.html Or if you use a processor, you should be able to do exchange.setException(null) to clear the exception. >>> >>> >>> onException(JAXBException.class) >>> .handled(true) >>> .bean(CamelErrorHandler.class, "handleJaxbError") >>> .to("log:XML?level=ERROR&showBodyType=false"); >>> >>> Where CamelErrorHandler is a class I wrote and >>> CamelErrorHandler.handleJaxbError() takes a parameter of type >>> JAXBException. >>> We use @Property("CamelExceptionCaught") to bind the Exception to the >>> parameter. I can replace the .bean() step with a .setBody("Hello >>> World"), >>> and still the original exception stack trace is output to the log. I >>> know >>> that the handleJaxbError function is being called because I can set a >>> breakpoint in it. >>> -- >>> View this message in context: >>> http://www.nabble.com/Handling-Exception-from-marshal-unmarshal-tp23494097p23502031.html >>> Sent from the Camel Development 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 >> Apache Camel Reference Card: >> http://refcardz.dzone.com/refcardz/enterprise-integration >> Interview with me: >> http://architects.dzone.com/articles/interview-claus-ibsen-about?mz=7893-progress >> >> > > -- > View this message in context: > http://www.nabble.com/Handling-Exception-from-marshal-unmarshal-tp23494097p23577706.html > Sent from the Camel Development 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: Handling Exception from marshal/unmarshal
Hi, .bean(Class, String) is a expression , it will not affect the message body. And this DSL should work for you. .transform().bean(JaxbExceptionHandler.class, "handleError") Willem Joe Gottman wrote: > Here is a small project. I hope it is understandable. I don't know JIRA > well enough to create a ticket. > http://www.nabble.com/file/p23577706/uncompressTest.7z uncompressTest.7z > >Here's the relevant part of the route: > > .doTry() > .unmarshal(new JaxbDataFormat("camel.unmarshal.test")) > .doCatch(Exception.class) > // .transform().constant(JaxbExceptionHandler.errorMessage) //This > works. > .bean(JaxbExceptionHandler.class, "handleError") //This fails, > even though > the bean is called > .end() > >When I called the .bean method (or the .setBody() method) after catching > an unmarshal exception, the results were not saved. On the other hand, > calling transform() worked for some reason. > > > > > Claus Ibsen-2 wrote: >> Hi >> >> Can you create a small project or unit test demonstrating this? >> And if so please create a JIRA ticket and attach the sample project. >> >> Then we have a good head start to investigate, and see what the problem >> is. >> >> In the mean time you are welcome to try with 2.0-SNAPSHOT to see if >> the problem still exists. >> Instructions on the Camel download page, how to get it. >> >> >> On Tue, May 12, 2009 at 2:55 PM, Joe Gottman >> wrote: >>> >>> >>> Claus Ibsen-2 wrote: On Tue, May 12, 2009 at 2:13 AM, Joe Gottman wrote: Can you show the route DSL how you do this? You should generally use handled(true) to clear the exception. Or use doTry() .. doCatch() just as you would use try .. catch in normal Java http://camel.apache.org/try-catch-finally.html Or if you use a processor, you should be able to do exchange.setException(null) to clear the exception. >>> >>> onException(JAXBException.class) >>> .handled(true) >>> .bean(CamelErrorHandler.class, "handleJaxbError") >>> .to("log:XML?level=ERROR&showBodyType=false"); >>> >>> Where CamelErrorHandler is a class I wrote and >>> CamelErrorHandler.handleJaxbError() takes a parameter of type >>> JAXBException. >>> We use @Property("CamelExceptionCaught") to bind the Exception to the >>> parameter. I can replace the .bean() step with a .setBody("Hello >>> World"), >>> and still the original exception stack trace is output to the log. I >>> know >>> that the handleJaxbError function is being called because I can set a >>> breakpoint in it. >>> -- >>> View this message in context: >>> http://www.nabble.com/Handling-Exception-from-marshal-unmarshal-tp23494097p23502031.html >>> Sent from the Camel Development 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 >> Apache Camel Reference Card: >> http://refcardz.dzone.com/refcardz/enterprise-integration >> Interview with me: >> http://architects.dzone.com/articles/interview-claus-ibsen-about?mz=7893-progress >> >> >
Re: Handling Exception from marshal/unmarshal
Here is a small project. I hope it is understandable. I don't know JIRA well enough to create a ticket. http://www.nabble.com/file/p23577706/uncompressTest.7z uncompressTest.7z Here's the relevant part of the route: .doTry() .unmarshal(new JaxbDataFormat("camel.unmarshal.test")) .doCatch(Exception.class) // .transform().constant(JaxbExceptionHandler.errorMessage) //This works. .bean(JaxbExceptionHandler.class, "handleError") //This fails, even though the bean is called .end() When I called the .bean method (or the .setBody() method) after catching an unmarshal exception, the results were not saved. On the other hand, calling transform() worked for some reason. Claus Ibsen-2 wrote: > > Hi > > Can you create a small project or unit test demonstrating this? > And if so please create a JIRA ticket and attach the sample project. > > Then we have a good head start to investigate, and see what the problem > is. > > In the mean time you are welcome to try with 2.0-SNAPSHOT to see if > the problem still exists. > Instructions on the Camel download page, how to get it. > > > On Tue, May 12, 2009 at 2:55 PM, Joe Gottman > wrote: >> >> >> >> Claus Ibsen-2 wrote: >>> >>> On Tue, May 12, 2009 at 2:13 AM, Joe Gottman >>> wrote: >>> >>> Can you show the route DSL how you do this? You should generally use >>> handled(true) to clear the exception. >>> Or use doTry() .. doCatch() just as you would use try .. catch in normal >>> Java >>> http://camel.apache.org/try-catch-finally.html >>> >>> Or if you use a processor, you should be able to do >>> exchange.setException(null) to clear the exception. >>> >>> >>> >> >> >> onException(JAXBException.class) >> .handled(true) >> .bean(CamelErrorHandler.class, "handleJaxbError") >> .to("log:XML?level=ERROR&showBodyType=false"); >> >> Where CamelErrorHandler is a class I wrote and >> CamelErrorHandler.handleJaxbError() takes a parameter of type >> JAXBException. >> We use @Property("CamelExceptionCaught") to bind the Exception to the >> parameter. I can replace the .bean() step with a .setBody("Hello >> World"), >> and still the original exception stack trace is output to the log. I >> know >> that the handleJaxbError function is being called because I can set a >> breakpoint in it. >> -- >> View this message in context: >> http://www.nabble.com/Handling-Exception-from-marshal-unmarshal-tp23494097p23502031.html >> Sent from the Camel Development 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 > Apache Camel Reference Card: > http://refcardz.dzone.com/refcardz/enterprise-integration > Interview with me: > http://architects.dzone.com/articles/interview-claus-ibsen-about?mz=7893-progress > > -- View this message in context: http://www.nabble.com/Handling-Exception-from-marshal-unmarshal-tp23494097p23577706.html Sent from the Camel Development mailing list archive at Nabble.com.
Re: Handling Exception from marshal/unmarshal
Hi Can you create a small project or unit test demonstrating this? And if so please create a JIRA ticket and attach the sample project. Then we have a good head start to investigate, and see what the problem is. In the mean time you are welcome to try with 2.0-SNAPSHOT to see if the problem still exists. Instructions on the Camel download page, how to get it. On Tue, May 12, 2009 at 2:55 PM, Joe Gottman wrote: > > > > Claus Ibsen-2 wrote: >> >> On Tue, May 12, 2009 at 2:13 AM, Joe Gottman >> wrote: >> >> Can you show the route DSL how you do this? You should generally use >> handled(true) to clear the exception. >> Or use doTry() .. doCatch() just as you would use try .. catch in normal >> Java >> http://camel.apache.org/try-catch-finally.html >> >> Or if you use a processor, you should be able to do >> exchange.setException(null) to clear the exception. >> >> >> > > > onException(JAXBException.class) > .handled(true) > .bean(CamelErrorHandler.class, "handleJaxbError") > .to("log:XML?level=ERROR&showBodyType=false"); > > Where CamelErrorHandler is a class I wrote and > CamelErrorHandler.handleJaxbError() takes a parameter of type JAXBException. > We use @Property("CamelExceptionCaught") to bind the Exception to the > parameter. I can replace the .bean() step with a .setBody("Hello World"), > and still the original exception stack trace is output to the log. I know > that the handleJaxbError function is being called because I can set a > breakpoint in it. > -- > View this message in context: > http://www.nabble.com/Handling-Exception-from-marshal-unmarshal-tp23494097p23502031.html > Sent from the Camel Development 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 Apache Camel Reference Card: http://refcardz.dzone.com/refcardz/enterprise-integration Interview with me: http://architects.dzone.com/articles/interview-claus-ibsen-about?mz=7893-progress
Re: Handling Exception from marshal/unmarshal
Claus Ibsen-2 wrote: > > On Tue, May 12, 2009 at 2:13 AM, Joe Gottman > wrote: > > Can you show the route DSL how you do this? You should generally use > handled(true) to clear the exception. > Or use doTry() .. doCatch() just as you would use try .. catch in normal > Java > http://camel.apache.org/try-catch-finally.html > > Or if you use a processor, you should be able to do > exchange.setException(null) to clear the exception. > > > onException(JAXBException.class) .handled(true) .bean(CamelErrorHandler.class, "handleJaxbError") .to("log:XML?level=ERROR&showBodyType=false"); Where CamelErrorHandler is a class I wrote and CamelErrorHandler.handleJaxbError() takes a parameter of type JAXBException. We use @Property("CamelExceptionCaught") to bind the Exception to the parameter. I can replace the .bean() step with a .setBody("Hello World"), and still the original exception stack trace is output to the log. I know that the handleJaxbError function is being called because I can set a breakpoint in it. -- View this message in context: http://www.nabble.com/Handling-Exception-from-marshal-unmarshal-tp23494097p23502031.html Sent from the Camel Development mailing list archive at Nabble.com.
Re: Handling Exception from marshal/unmarshal
On Tue, May 12, 2009 at 2:13 AM, Joe Gottman wrote: > > I am using Camel version 2.0M1. When I call unmarshal() using the Jaxb > format I want to handle any exceptions thrown by the unmarshal() call. I > use an onException() statement and the Exception is being caught. However, > when I later try to handle the exception by setting the Message body to my > own error string, this always fails. The output is always the same stack > trace that I would have gotten if I had not handled the exception. Hi Can you show the route DSL how you do this? You should generally use handled(true) to clear the exception. Or use doTry() .. doCatch() just as you would use try .. catch in normal Java http://camel.apache.org/try-catch-finally.html Or if you use a processor, you should be able to do exchange.setException(null) to clear the exception. > > -- > View this message in context: > http://www.nabble.com/Handling-Exception-from-marshal-unmarshal-tp23494097p23494097.html > Sent from the Camel Development 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 Apache Camel Reference Card: http://refcardz.dzone.com/refcardz/enterprise-integration Interview with me: http://architects.dzone.com/articles/interview-claus-ibsen-about?mz=7893-progress