本文整理汇总了Java中org.apache.camel.builder.AdviceWithRouteBuilder类的典型用法代码示例。如果您正苦于以下问题:Java AdviceWithRouteBuilder类的具体用法?Java AdviceWithRouteBuilder怎么用?Java AdviceWithRouteBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AdviceWithRouteBuilder类属于org.apache.camel.builder包,在下文中一共展示了AdviceWithRouteBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: routeShouldReturnOddFor1EvenFor6
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
@Test
public void routeShouldReturnOddFor1EvenFor6() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveAddLast().setBody(simple("${body} is ${headers.NumberParity}.")).to(resultEndpoint);
}
});
context.start();
resultEndpoint.expectedMessageCount(2);
resultEndpoint.expectedBodiesReceived("1 is odd.", "6 is even.");
template.sendBody(1);
template.sendBody(6);
resultEndpoint.assertIsSatisfied();
context.stop();
}
示例2: testResponseToJSON
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
@Test
public void testResponseToJSON() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:test");
}
}
);
ResponseMessage message = new ResponseMessage(ResponseCode.SUCCESS, "MESSAGE");
context.start();
Object object = template.requestBody("direct:test", message);
Assert.assertTrue(object instanceof String);
}
示例3: testAdviceWith
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
public void testAdviceWith() throws Exception {
context.getRouteDefinition("route-a").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("direct:bar")
.skipSendToOriginalEndpoint()
.throwException(new IllegalArgumentException("Forced"));
}
});
getMockEndpoint("mock:error").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(0);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
示例4: testParseUrl
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
@Test
public void testParseUrl() throws Exception {
final String route = "IslandoraTriplestoreIndexerParseUrl";
context.getRouteDefinition(route).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:start");
weaveAddLast().to(resultEndpoint);
}
});
context.start();
resultEndpoint.expectedMessageCount(1);
final Exchange exchange = template.send(xchange ->
xchange.getIn().setBody(IOUtils.toString(loadResourceAsStream("AS2Event.jsonld"), "UTF-8"))
);
this.assertPredicate(
exchangeProperty("url").isEqualTo("http://localhost:8000/node/1?_format=jsonld"),
exchange,
true
);
assertMockEndpointsSatisfied();
}
示例5: testMultipleAdvice
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
@Test
public void testMultipleAdvice() throws Exception {
context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:resultA").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new Exception("my exception");
}
});
}
});
context.getRouteDefinition("RouteB").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
}
});
context.start();
getMockEndpoint("mock:resultA").expectedMessageCount(0);
template.sendBody("direct:startA", "a trigger");
assertMockEndpointsSatisfied();
}
示例6: advice
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
void advice(@Observes CamelContextStartingEvent event,
@Uri("mock:messages") MockEndpoint messages,
ModelCamelContext context) throws Exception {
messages.expectedMessageCount(2);
messages.expectedBodiesReceived("Hello", "Bye");
verifier.messages = messages;
context.getRouteDefinition("route")
.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() {
weaveAddLast().to("mock:messages");
}
});
}
示例7: testAdviceWithOnException
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
public void testAdviceWithOnException() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveById("b").after().to("mock:result");
}
});
context.start();
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
示例8: testAdviceRoutePolicyRemoved
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
public void testAdviceRoutePolicyRemoved() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// remove the route policy so we can test without it
getOriginalRoute().setRoutePolicies(null);
}
});
getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:foo").message(0).header("MyRoutePolicy").isNull();
getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:bar").message(0).header("MyRoutePolicy").isNull();
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
示例9: testAdviceWithPolicy
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
public void testAdviceWithPolicy() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveById("b").after().to("mock:result");
}
});
context.start();
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
示例10: testAdviceCBR
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
public void testAdviceCBR() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveById("foo").after().to("mock:foo2");
weaveById("bar").after().to("mock:bar2");
}
});
getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:foo2").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:bar2").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:baz").expectedBodiesReceived("Hi World");
template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
template.sendBodyAndHeader("direct:start", "Bye World", "bar", "123");
template.sendBody("direct:start", "Hi World");
assertMockEndpointsSatisfied();
}
示例11: testAdviceToStringCBR
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
public void testAdviceToStringCBR() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveByToString("To[mock:foo]").after().to("mock:foo2");
weaveByToString("To[mock:bar]").after().to("mock:bar2");
}
});
getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:foo2").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:bar2").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:baz").expectedBodiesReceived("Hi World");
template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
template.sendBodyAndHeader("direct:start", "Bye World", "bar", "123");
template.sendBody("direct:start", "Hi World");
assertMockEndpointsSatisfied();
}
示例12: testNoErrorHandler
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
public void testNoErrorHandler() throws Exception {
try {
context.getRouteDefinition("route-a").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
errorHandler(loggingErrorHandler());
interceptSendToEndpoint("direct:bar")
.skipSendToOriginalEndpoint()
.throwException(new IllegalArgumentException("Forced"));
}
});
fail("Should have thrown an exception");
} catch (IllegalArgumentException e) {
assertEquals("You can not advice with error handlers. Remove the error handlers from the route builder.", e.getMessage());
}
}
示例13: testSimpleMultipleAdvice
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
public void testSimpleMultipleAdvice() throws Exception {
context.addRoutes(createRouteBuilder());
context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:resultA").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
}
});
}
});
context.getRouteDefinition("RouteB").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
}
});
context.start();
getMockEndpoint("mock:resultA").expectedMessageCount(1);
template.sendBody("direct:startA", "a trigger");
assertMockEndpointsSatisfied();
}
示例14: testMultipleAdviceWithExceptionThrown
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
public void testMultipleAdviceWithExceptionThrown() throws Exception {
context.addRoutes(createRouteBuilder());
context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:resultA").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new Exception("my exception");
}
});
}
});
context.start();
getMockEndpoint("mock:resultA").expectedMessageCount(0);
template.sendBody("direct:startA", "a trigger");
assertMockEndpointsSatisfied();
}
示例15: testSimpleMultipleAdvice
import org.apache.camel.builder.AdviceWithRouteBuilder; //导入依赖的package包/类
@Test
public void testSimpleMultipleAdvice() throws Exception {
context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:resultA").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
}
});
}
});
context.getRouteDefinition("RouteB").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
}
});
context.start();
getMockEndpoint("mock:resultA").expectedMessageCount(1);
template.sendBody("direct:startA", "a trigger");
assertMockEndpointsSatisfied();
}