You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Alex Anderson <al...@gmail.com> on 2013/02/05 13:55:36 UTC

[2.9.5] body=null after onException(_).handled(false)

I have a route that looks like so:

    onCompletion().onFailureOnly().beanRef('myBean', 'handleFailed')
    from('seda:asdf')
        .onException(SpecificException)
            .beanRef('myBean', 'handleSpecificException')
            .handled(false)
            .end()
        .dynamicRouter('myBean', 'slip')

When myBean.slip() throws SpecificException, If I print in.body in
handleSpecificException(), I can see that it is not null.

If I print it again in handleFailed() it is now null.

I have "fixed" this by adding the following to MyBean.handleSpecificException():

    x.out.body = x.in.body
    x.out.headers = x.in.headers

Is this expected behaviour - should the workaround be required?

Thanks,

Alex

Re: [2.9.5] body=null after onException(_).handled(false)

Posted by Henryk Konsek <he...@gmail.com>.
Hi Alex,

>   // N.B. This method implicitly returns null

This is my favorite kind of pitfalls of the Java/Groovy integration :) .

I'm glad it is solved.

Best regards.

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com

Re: [2.9.5] body=null after onException(_).handled(false)

Posted by Alex Anderson <al...@frontlinesms.com>.
Henryk,

Sorry for the confusion - my error handler is written in Groovy, and
the definition of the exception handler is as follows:

  // N.B. This method implicitly returns null
  def exception(Exchange exchange) {
    System.out.println("Exception: " + exchange.getIn());
  }

In Java this is effectively:

  Object exception(Exchange exchange) {
    System.out.println("Exception: " + exchange.getIn());
    return null;
  }

So I guess that explains that!

Thanks again for your help,

Alex

Re: [2.9.5] body=null after onException(_).handled(false)

Posted by Alex Anderson <al...@frontlinesms.com>.
On 5 February 2013 18:39, Henryk Konsek <he...@gmail.com> wrote:
> Hi Alex,
>
>> When myBean.slip() throws SpecificException, If I print in.body in
>> handleSpecificException(), I can see that it is not null.
>>
>> If I print it again in handleFailed() it is now null.
>
> Actually I can't reproduce this problem neither under Camel 2.9.5 nor
> under Camel 2.10.1.
>
> Here is my minimal example trying to reproduce your behavior:
>
> ______________
> public class ErrorHandler {
>
>   public void exception(Exchange exchange) {
>     System.out.println("Exception: " + exchange.getIn());
>   }
>
>   public void completion(Exchange exchange) {
>     System.out.println("Completion: " + exchange.getIn());
>   }
>
>   public void router() {
>     throw new RuntimeException();
>   }
>
> }
>
> CamelContext context = new DefaultCamelContext();
> context.addRoutes(new RouteBuilder() {
>   @Override
>   public void configure() throws Exception {
>     onCompletion().onFailureOnly().bean(new ErrorHandler(), "completion");
>     from("seda:start")
>        .onException(Exception.class)
>        .bean(new ErrorHandler(), "exception")
>        .handled(false)
>        .end()
>     .dynamicRouter(bean(ErrorHandler.class, "router"));
>     }
>   });
> context.start();
> context.createProducerTemplate().sendBody("seda:start","msg");
> ______________
>
> The output produced by it indicates that both handlers work fine:
>
> ______________
> Exception: Message: msg
> Completion: Message: msg
> ______________
>
> If you would be so kind and create minimal Maven project with test
> case demonstrating the issue, I could debug it and tell you what is
> the problem.

Hi Henryk,

Thanks for your help.  I agree that your example doesn't exhibit the
problem - I'm sorry for not working through a simple example myself
before sending to the mailing list.

When I have time I will try to recreate and share on this list.

Alex

Re: [2.9.5] body=null after onException(_).handled(false)

Posted by Henryk Konsek <he...@gmail.com>.
Hi Alex,

> When myBean.slip() throws SpecificException, If I print in.body in
> handleSpecificException(), I can see that it is not null.
>
> If I print it again in handleFailed() it is now null.

Actually I can't reproduce this problem neither under Camel 2.9.5 nor
under Camel 2.10.1.

Here is my minimal example trying to reproduce your behavior:

______________
public class ErrorHandler {

  public void exception(Exchange exchange) {
    System.out.println("Exception: " + exchange.getIn());
  }

  public void completion(Exchange exchange) {
    System.out.println("Completion: " + exchange.getIn());
  }

  public void router() {
    throw new RuntimeException();
  }

}

CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
  @Override
  public void configure() throws Exception {
    onCompletion().onFailureOnly().bean(new ErrorHandler(), "completion");
    from("seda:start")
       .onException(Exception.class)
       .bean(new ErrorHandler(), "exception")
       .handled(false)
       .end()
    .dynamicRouter(bean(ErrorHandler.class, "router"));
    }
  });
context.start();
context.createProducerTemplate().sendBody("seda:start","msg");
______________

The output produced by it indicates that both handlers work fine:

______________
Exception: Message: msg
Completion: Message: msg
______________

If you would be so kind and create minimal Maven project with test
case demonstrating the issue, I could debug it and tell you what is
the problem.

Best regards.

--
Henryk Konsek
http://henryk-konsek.blogspot.com