You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Alex Savitsky (JIRA)" <ji...@apache.org> on 2015/04/16 17:05:58 UTC

[jira] [Updated] (CAMEL-8646) Camel doesn't allow intercept and advice on the same route

     [ https://issues.apache.org/jira/browse/CAMEL-8646?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alex Savitsky updated CAMEL-8646:
---------------------------------
    Description: 
Let's assume we have a route, defined in a RouteBuilder. It allows us to define an interceptor that would be executed before every route step, via an intercept(Processor) call.

Routes can also have an advice attached to them, via RouteDefinition.adviceWith(AdviceWithRouteBuilder) call.

If these two methods of weaving custom processing into existing routes are combined, Camel throws an exception:

{noformat}
Exception in thread "main" java.lang.IllegalArgumentException: There are no outputs which matches: * in the route: Route(main)[[From[direct:main]] -> [Intercept[[Log[Intercept ${body} ${headers}]]], Log[Main ${body} ${headers}]]]
	at org.apache.camel.builder.AdviceWithTasks$3.task(AdviceWithTasks.java:257)
	at org.apache.camel.model.RouteDefinition.adviceWith(RouteDefinition.java:270)
	at camel.Test.main(Test.java:20)
{noformat}

Simple test to illustrate the issue:

{noformat}
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.model.ModelCamelContext;

public class Test {
	public static void main(String[] args) throws Exception {
		ModelCamelContext context = new DefaultCamelContext();
		RouteBuilder route = new RouteBuilder() {
			@Override
			public void configure() throws Exception {
				from("direct:advice").log("Advice ${body} ${headers}");
				from("direct:main").routeId("main").log("Main ${body} ${headers}");
			}
		};
		route.intercept().log("Intercept ${body} ${headers}");
		context.addRoutes(route);
		context.getRouteDefinition("main").adviceWith(context, new AdviceWithRouteBuilder() {
			@Override
			public void configure() throws Exception {
				weaveAddFirst().to("direct:advice");
			}
		});
		context.start();
		context.createProducerTemplate().sendBody("direct:main", "testBody");
		context.stop();
	}
}
{noformat}

  was:
Let's assume we have a route, defined in a RouteBuilder. It allows us to define an interceptor that would be executed before every route step, via an intercept(Processor) call.

Routes can also have an advice attached to them, via RouteDefinition.adviceWith(AdviceWithRouteBuilder) call.

If these two methods of weaving custom processing into existing routes are combined, Camel throws an exception:

{noformat}
Exception in thread "main" java.lang.IllegalArgumentException: There are no outputs which matches: * in the route: Route(main)[[From[direct:main]] -> [Intercept[[process[Processor@0x4b416926]]], Log[Main ${body} ${headers}]]]
	at org.apache.camel.builder.AdviceWithTasks$3.task(AdviceWithTasks.java:257)
	at org.apache.camel.model.RouteDefinition.adviceWith(RouteDefinition.java:270)
	at camel.Test.main(Test.java:27)
{noformat}

Simple test to illustrate the issue:

{noformat}
public class Test {
	public static void main(String[] args) throws Exception {
		ModelCamelContext context = new DefaultCamelContext();
		RouteBuilder route = new RouteBuilder() {
			@Override
			public void configure() throws Exception {
				from("direct:advice").log("Advice ${body} ${headers}");
				from("direct:main").routeId("main").log("Main ${body} ${headers}");
			}
		};
		route.intercept().process(new Processor() {
			@Override
			public void process(Exchange exchange) throws Exception {
				System.out.println("Intercept " + exchange);
			}
		});
		context.addRoutes(route);
		context.getRouteDefinition("main").adviceWith(context, new AdviceWithRouteBuilder() {
			@Override
			public void configure() throws Exception {
				weaveAddFirst().to("direct:advice");
			}
		});
		context.start();
		context.createProducerTemplate().sendBody("direct:main", "testBody");
		context.stop();
	}
}
{noformat}


> Camel doesn't allow intercept and advice on the same route
> ----------------------------------------------------------
>
>                 Key: CAMEL-8646
>                 URL: https://issues.apache.org/jira/browse/CAMEL-8646
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.15.0
>            Reporter: Alex Savitsky
>
> Let's assume we have a route, defined in a RouteBuilder. It allows us to define an interceptor that would be executed before every route step, via an intercept(Processor) call.
> Routes can also have an advice attached to them, via RouteDefinition.adviceWith(AdviceWithRouteBuilder) call.
> If these two methods of weaving custom processing into existing routes are combined, Camel throws an exception:
> {noformat}
> Exception in thread "main" java.lang.IllegalArgumentException: There are no outputs which matches: * in the route: Route(main)[[From[direct:main]] -> [Intercept[[Log[Intercept ${body} ${headers}]]], Log[Main ${body} ${headers}]]]
> 	at org.apache.camel.builder.AdviceWithTasks$3.task(AdviceWithTasks.java:257)
> 	at org.apache.camel.model.RouteDefinition.adviceWith(RouteDefinition.java:270)
> 	at camel.Test.main(Test.java:20)
> {noformat}
> Simple test to illustrate the issue:
> {noformat}
> import org.apache.camel.builder.AdviceWithRouteBuilder;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.impl.DefaultCamelContext;
> import org.apache.camel.model.ModelCamelContext;
> public class Test {
> 	public static void main(String[] args) throws Exception {
> 		ModelCamelContext context = new DefaultCamelContext();
> 		RouteBuilder route = new RouteBuilder() {
> 			@Override
> 			public void configure() throws Exception {
> 				from("direct:advice").log("Advice ${body} ${headers}");
> 				from("direct:main").routeId("main").log("Main ${body} ${headers}");
> 			}
> 		};
> 		route.intercept().log("Intercept ${body} ${headers}");
> 		context.addRoutes(route);
> 		context.getRouteDefinition("main").adviceWith(context, new AdviceWithRouteBuilder() {
> 			@Override
> 			public void configure() throws Exception {
> 				weaveAddFirst().to("direct:advice");
> 			}
> 		});
> 		context.start();
> 		context.createProducerTemplate().sendBody("direct:main", "testBody");
> 		context.stop();
> 	}
> }
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)