...
The AdviceWithRouteBuilder
offers the following extra methods
Method | Description |
---|---|
| Is used to easily mock all endpoints. See more details and examples at Mock. |
| Is used to easily mock endpoints using a pattern. See more details and examples at Mock. See below for pattern matching. |
| Is used to select node(s) matching by id's, and weave in the following nodes. See below for pattern matching and examples. |
| Is used to select nodes(s) matching by their |
| Camel 2.8: Is used to select node(s) matching by their class type (the classes from the org.apache.camel.model package), and weave in the following nodes. See below for examples. |
| Camel 2.8: Is a short hand to easily weave in the following nodes in the start of the route. |
| Camel 2.8: Is a short hand to easily weave in the following nodes in the end of the route. |
The pattern
option is used for matching. It uses the same rules as the Intercept, which is applied in the following order:
...
The weaveById
allows you to manipulate the rote, for example by replacing a node with other nodes. The following methods is available:
Method | Description |
---|---|
| Removes the selected node(s). |
| Replaces the selected node(s) with the following nodes. |
| Before the selected node(s), the following nodes is added. |
| After the selected node(s), the following nodes is added. |
...
Wiki Markup |
---|
{snippet:id=e2|lang=java|title=Remove|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithTypeTest.java} |
Using selectors
Available os of Camel 2.8
The following methods weaveById(pattern)
, weaveByToString(pattern)
and weaveByType(Class)
each match N+ nodes. By using optional selectors you can narrow down the nodes being used. For example if weaveByType(Class)
returns 2 nodes. Then you can use a selector to indicate it should only select the first node.
Selector | Description |
---|---|
| Will only select the first matched node. |
| Will only select the last matched node. |
| Will only select the n'th matched node. The index is zero-based. |
| Will only select the matches node within the given range by index (both inclusive). The index is zero-based. |
For example to remove the first .to
node in route you can do as follows:
Code Block |
---|
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// only remove the first to node in the route
weaveByType(ToDefinition.class).selectFirst().remove();
}
});
|
Using weaveAddFirst / weaveAddLast
Available os of Camel 2.8
The weaveAddFirst
and weaveAddLast
is a shorthand to easily add nodes to the route. These methods can only add to an existing routes. If you want to manipulate the route, then there are plenty of methods as already shown on this page.
For example if you want to send a message to a mock:input
endpoint you can do as follows:
Code Block |
---|
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { // send the incoming message to mock:input weaveAddFirst().to("mock:input"); } }); |
Likewise if you want to easily send a message to a mock:output
endpoint you can do as follows:
Code Block |
---|
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// send the outgoing message to mock:output
weaveAddLast().to("mock:output");
}
});
|
You can of course combine those in the same advice with:
Code Block |
---|
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveAddFirst().to("mock:input");
weaveAddLast().to("mock:output");
}
});
|