You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hude <fl...@googlemail.com> on 2015/01/07 17:19:51 UTC

Re: Problem with adviceWith on 2.13.x

Hi,

we’ve got a problem with the changes for CAMEL-7560. Since an upgrade from
2.12.2 to 2.12.5 all tests where we use the weaveAddFirst method to advice
routes with an onException-clause failed with the following
IllegalArgumentException:

"java.lang.IllegalArgumentException: There are no outputs which matches:
..."

The reason is that the call "outputs.get(0).getOutputs();" in
AdviceWithTasks for an OnExceptionDefinition only returns the onException
part of the route. I've added a test in AdviceWithTasksTest to demonstrate
it:

public void testBeforeWithOnException() throws Exception {
        context.addRoutes(new RouteBuilder() {
            
            @Override
            public void configure() throws Exception {
                from("direct:start2")
                .onException(Throwable.class).handled(true).end()
                .to("mock:foo")
                .to("mock:bar")
                .id("bar2")
                .to("mock:result");;
                
            }
        });
        // START SNIPPET: e3
        context.getRouteDefinitions().get(1).adviceWith(context, new
AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                // weave the node in the route which has id = bar
                // and insert the following route path before the adviced
node
               
weaveById("bar2").before().to("mock:a").transform(constant("Bye World"));
            }
        });
        // END SNIPPET: e3

        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
        getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
        getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");

        template.sendBody("direct:start2", "Hello World");

        assertMockEndpointsSatisfied();
}

Is there any need why it’s for any abstract definition? If I change the
premise in AdviceWithTasks.getParentOutputs from
"outputs.get(0).isAbstract()" to "outputs.get(0) instanceof
TransactedDefinition" all tests passed. Enclosed you will find my svn patch.

Greeting

Dennis

AdviceWithTasks_Patch.txt
<http://camel.465427.n5.nabble.com/file/n5761437/AdviceWithTasks_Patch.txt>  



--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-adviceWith-on-2-13-x-tp5752421p5761437.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem with adviceWith on 2.13.x

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

Your test case works in newer Camel releases
https://github.com/apache/camel/commit/5538801e5dc23469d133ebe78ba69c12eecfff1d

On Wed, Jan 7, 2015 at 5:19 PM, Hude <fl...@googlemail.com> wrote:
> Hi,
>
> we’ve got a problem with the changes for CAMEL-7560. Since an upgrade from
> 2.12.2 to 2.12.5 all tests where we use the weaveAddFirst method to advice
> routes with an onException-clause failed with the following
> IllegalArgumentException:
>
> "java.lang.IllegalArgumentException: There are no outputs which matches:
> ..."
>
> The reason is that the call "outputs.get(0).getOutputs();" in
> AdviceWithTasks for an OnExceptionDefinition only returns the onException
> part of the route. I've added a test in AdviceWithTasksTest to demonstrate
> it:
>
> public void testBeforeWithOnException() throws Exception {
>         context.addRoutes(new RouteBuilder() {
>
>             @Override
>             public void configure() throws Exception {
>                 from("direct:start2")
>                 .onException(Throwable.class).handled(true).end()
>                 .to("mock:foo")
>                 .to("mock:bar")
>                 .id("bar2")
>                 .to("mock:result");;
>
>             }
>         });
>         // START SNIPPET: e3
>         context.getRouteDefinitions().get(1).adviceWith(context, new
> AdviceWithRouteBuilder() {
>             @Override
>             public void configure() throws Exception {
>                 // weave the node in the route which has id = bar
>                 // and insert the following route path before the adviced
> node
>
> weaveById("bar2").before().to("mock:a").transform(constant("Bye World"));
>             }
>         });
>         // END SNIPPET: e3
>
>         getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
>         getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
>         getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
>         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
>
>         template.sendBody("direct:start2", "Hello World");
>
>         assertMockEndpointsSatisfied();
> }
>
> Is there any need why it’s for any abstract definition? If I change the
> premise in AdviceWithTasks.getParentOutputs from
> "outputs.get(0).isAbstract()" to "outputs.get(0) instanceof
> TransactedDefinition" all tests passed. Enclosed you will find my svn patch.
>
> Greeting
>
> Dennis
>
> AdviceWithTasks_Patch.txt
> <http://camel.465427.n5.nabble.com/file/n5761437/AdviceWithTasks_Patch.txt>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problem-with-adviceWith-on-2-13-x-tp5752421p5761437.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/