I have the following route for demo purposes
from("direct:external")
.routeId("external")
.to("http4://www.third-party.com/foo").id("ext");
For testing, I would like to * replace the http4: endpoint with a direct: endpoint * add a mock: endpoint at the end of the route for verification
I've added the following adviceWithRouteBuilder
context.getRouteDefinition("external").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveAddLast().to("mock:result");
weaveByToUri(".*http4://.*")
.replace()
.to("direct:foo");
}
});
This one seems to work but if I change the order of the weave*
statements, like so
public void configure() throws Exception {
weaveByToUri(".*http4://.*")
.replace()
.to("direct:foo");
weaveAddLast().to("mock:result");
}
It gives me the following error
java.lang.IllegalArgumentException: There are no outputs which matches: * in the route: Route(external)[[From[direct:external]] -> [pipeline -> [[To[direct:foo]]]]]
I would actually expect to get the same result, independent of the order.
A Mock endpoint which provides a literate, fluent API for testing routes using a JMock style API. The mock endpoint have two set of methods. expectedXXX or expectsXXX - To set pre conditions, before the test is executed. assertXXX - To assert assertions, after the test has been executed.
The CamelContext is the runtime system, which holds everything together as depicted in the figure below. The CamelContext provides access to many useful services, the most notable being components, type converters, a registry, endpoints, routes, data formats, and languages.
One thing to note here is that the weave*
calls are only aware of the original RouteBuilder. So when you perform the weaveByUri()
call first, it replaces .to("http4://www.third-party.com/foo")
with .to("direct:foo")
, which incidentally happens to be the last endpoint in your route. Now, when you perform the weaveAddLast()
call, it looks for "http4://www.third-party.com/foo"
but doesn't find it, since it was replaced by "direct:foo"
. This results in an exception being thrown.
So if, hypothetically, there's another endpoint after the "http4..."
endpoint such that it's not the last endpoint in your route anymore, your adviceWith()
should work. For instance, it will work if your original route looked something like this:
from("direct://external")
.routeId("external")
.to("http4://www.third-party.com/foo")
.id("ext")
.to("direct://bar")
;
I should note that I think that this is a bug and that the order shouldn't matter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With