本文整理汇总了Java中org.apache.camel.model.RouteDefinition.adviceWith方法的典型用法代码示例。如果您正苦于以下问题:Java RouteDefinition.adviceWith方法的具体用法?Java RouteDefinition.adviceWith怎么用?Java RouteDefinition.adviceWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.model.RouteDefinition
的用法示例。
在下文中一共展示了RouteDefinition.adviceWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testErrorHandler
import org.apache.camel.model.RouteDefinition; //导入方法依赖的package包/类
public void testErrorHandler() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("seda:*")
.skipSendToOriginalEndpoint()
.throwException(new FileNotFoundException("Forced"));
}
});
getMockEndpoint("mock:local").expectedMessageCount(1);
getMockEndpoint("mock:seda").expectedMessageCount(0);
getMockEndpoint("mock:exhausted").expectedMessageCount(0);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
示例2: testAdviceWithOnException
import org.apache.camel.model.RouteDefinition; //导入方法依赖的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();
}
示例3: testAdviceRoutePolicyRemoved
import org.apache.camel.model.RouteDefinition; //导入方法依赖的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();
}
示例4: testHttpInterceptSendToEndpoint
import org.apache.camel.model.RouteDefinition; //导入方法依赖的package包/类
@Test
public void testHttpInterceptSendToEndpoint() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("http*").to("mock:http").skipSendToOriginalEndpoint();
}
});
getMockEndpoint("mock:http").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
示例5: testInterceptSendToEndpoint
import org.apache.camel.model.RouteDefinition; //导入方法依赖的package包/类
public void testInterceptSendToEndpoint() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.loadBalance().failover()
.to("seda:end1", "seda:end2");
}
});
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new RouteBuilder() {
public void configure() throws Exception {
interceptSendToEndpoint("seda:end1")
.skipSendToOriginalEndpoint()
.to("mock:end");
}
});
context.start();
getMockEndpoint("mock:end").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
示例6: testAdviceWithA
import org.apache.camel.model.RouteDefinition; //导入方法依赖的package包/类
public void testAdviceWithA() throws Exception {
RouteDefinition route = context.getRouteDefinition("a");
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock://a")
.skipSendToOriginalEndpoint()
.throwException(new IllegalArgumentException("Forced"));
}
});
getMockEndpoint("mock:a").expectedMessageCount(0);
getMockEndpoint("mock:error").expectedMessageCount(1);
getMockEndpoint("mock:error").message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
template.sendBody("direct:a", "Hello World");
assertMockEndpointsSatisfied();
}
示例7: testAdviceCBR
import org.apache.camel.model.RouteDefinition; //导入方法依赖的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();
}
示例8: testAdviceToStringCBR
import org.apache.camel.model.RouteDefinition; //导入方法依赖的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();
}
示例9: testFailover
import org.apache.camel.model.RouteDefinition; //导入方法依赖的package包/类
public void testFailover() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:a")
.loadBalance().failover(IOException.class)
.to("mock:a")
.to("mock:b")
.end();
}
});
RouteDefinition routeDefinition = context.getRouteDefinitions().get(0);
routeDefinition.adviceWith(context, new AdviceWithRouteBuilder());
context.start();
getMockEndpoint("mock:a").expectedMessageCount(0);
getMockEndpoint("mock:b").expectedBodiesReceived("Intercepted SQL!");
template.sendBody("direct:a", "foo");
assertMockEndpointsSatisfied();
}
示例10: testAdviceWithOnException
import org.apache.camel.model.RouteDefinition; //导入方法依赖的package包/类
public void testAdviceWithOnException() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
onException(IllegalArgumentException.class)
.handled(true)
.to("mock:error");
}
});
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:error").expectedBodiesReceived("Kaboom");
template.sendBody("direct:start", "World");
template.sendBody("direct:start", "Kaboom");
assertMockEndpointsSatisfied();
}
示例11: testAdviceWithB
import org.apache.camel.model.RouteDefinition; //导入方法依赖的package包/类
public void testAdviceWithB() throws Exception {
RouteDefinition route = context.getRouteDefinition("b");
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock://b")
.skipSendToOriginalEndpoint()
.throwException(new IllegalArgumentException("Forced"));
}
});
getMockEndpoint("mock:b").expectedMessageCount(0);
getMockEndpoint("mock:error").expectedMessageCount(1);
getMockEndpoint("mock:error").message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
template.sendBody("direct:b", "Hello World");
assertMockEndpointsSatisfied();
}
示例12: testAdviceWithInterceptSendToEndpoint
import org.apache.camel.model.RouteDefinition; //导入方法依赖的package包/类
public void testAdviceWithInterceptSendToEndpoint() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:result").to("mock:to");
}
});
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:to").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:to").expectedHeaderReceived(Exchange.INTERCEPTED_ENDPOINT, "mock://result");
template.sendBody("direct:start", "World");
assertMockEndpointsSatisfied();
}
示例13: testAdviceWithInterceptSendToEndpoint
import org.apache.camel.model.RouteDefinition; //导入方法依赖的package包/类
public void testAdviceWithInterceptSendToEndpoint() throws Exception {
RouteDefinition route = context.getRouteDefinition("foo");
route.adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("{{cool.mock}}:res*").to("mock:foo");
}
});
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
示例14: testAdviceWithAB
import org.apache.camel.model.RouteDefinition; //导入方法依赖的package包/类
public void testAdviceWithAB() throws Exception {
RouteDefinition route = context.getRouteDefinition("a");
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock://a")
.skipSendToOriginalEndpoint()
.throwException(new IllegalArgumentException("Forced"));
}
});
route = context.getRouteDefinition("b");
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock://b")
.skipSendToOriginalEndpoint()
.throwException(new IllegalArgumentException("Forced"));
}
});
getMockEndpoint("mock:a").expectedMessageCount(0);
getMockEndpoint("mock:b").expectedMessageCount(0);
getMockEndpoint("mock:error").expectedMessageCount(2);
getMockEndpoint("mock:error").message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
getMockEndpoint("mock:error").message(1).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
template.sendBody("direct:a", "Hello World");
template.sendBody("direct:b", "Bye World");
assertMockEndpointsSatisfied();
}
示例15: testIssue
import org.apache.camel.model.RouteDefinition; //导入方法依赖的package包/类
public void testIssue() throws Exception {
final Predicate fail = PredicateBuilder.or(
header(Exchange.REDELIVERY_COUNTER).isNull(),
header(Exchange.REDELIVERY_COUNTER).isLessThan(5));
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("seda:*")
.skipSendToOriginalEndpoint()
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
invoked.incrementAndGet();
if (fail.matches(exchange)) {
throw new ConnectException("Forced");
}
}
}).to("mock:ok");
}
});
getMockEndpoint("mock:global").expectedMessageCount(0);
getMockEndpoint("mock:ok").expectedMessageCount(1);
getMockEndpoint("mock:exhausted").expectedMessageCount(0);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// 5 retry + 1 ok
assertEquals(6, invoked.get());
}
开发者ID:HydAu,项目名称:Camel,代码行数:35,代码来源:TwoRouteScopedOnExceptionWithInterceptSendToEndpointIssueWithPredicateTest.java