本文整理汇总了Java中org.apache.camel.model.RouteDefinition类的典型用法代码示例。如果您正苦于以下问题:Java RouteDefinition类的具体用法?Java RouteDefinition怎么用?Java RouteDefinition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RouteDefinition类属于org.apache.camel.model包,在下文中一共展示了RouteDefinition类的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: addServerReceivedTracing
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
public static ProcessorDefinition addServerReceivedTracing(IDrinkWaterService service,
RouteDefinition routeDefinition,
Method method) {
ProcessorDefinition answer = routeDefinition;
if (!service.getConfiguration().getIsTraceEnabled()) {
return answer;
}
answer = routeDefinition
.setHeader(BeanOperationName)
.constant(Operation.of(method))
.to(ROUTE_serverReceivedEvent);
return answer;
}
示例3: addMethodInvokedStartTrace
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
public static RouteDefinition addMethodInvokedStartTrace(
IDrinkWaterService service,
RouteDefinition routeDefinition,
Operation operation){
RouteDefinition answer = routeDefinition;
if (!service.getConfiguration().getIsTraceEnabled()) {
return answer;
}
answer = routeDefinition
.setHeader(BeanOperationName)
.constant(operation)
.to(ROUTE_MethodInvokedStartEvent);
return answer;
}
示例4: mapBeanClassRoutes
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
public static RouteBuilder mapBeanClassRoutes(DrinkWaterApplication app, Service service) {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
List<Method> methods = javaslang.collection.List.of(service.getConfiguration().getServiceClass().getDeclaredMethods());
// create an instance of the bean
Object beanToUse = BeanFactory.createBeanClass(app, service.getConfiguration(), service);
for (Method m : methods) {
if (Modifier.isPublic(m.getModifiers())) {
RouteDefinition def = from("direct:" + formatBeanMethodRoute(m));
def = addMethodInvokedStartTrace(service, def, Operation.of(m));
def.bean(beanToUse, formatBeanEndpointRoute(m), true);
addMethodInvokedEndTrace(service, def);
}
}
}
};
}
示例5: parseCamelContexts
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
protected static List<ContextDto> parseCamelContexts(CamelCatalog camelCatalog, File xmlFile) throws Exception {
List<ContextDto> camelContexts = new ArrayList<>();
RouteXml routeXml = new RouteXml();
XmlModel xmlModel = routeXml.unmarshal(xmlFile);
// TODO we don't handle multiple contexts inside an XML file!
CamelContextFactoryBean contextElement = xmlModel.getContextElement();
String name = contextElement.getId();
List<RouteDefinition> routeDefs = contextElement.getRoutes();
ContextDto context = new ContextDto(name);
camelContexts.add(context);
String key = name;
if (Strings.isNullOrBlank(key)) {
key = "_camelContext" + camelContexts.size();
}
context.setKey(key);
List<NodeDto> routes = createRouteDtos(camelCatalog, routeDefs, context);
context.setChildren(routes);
return camelContexts;
}
示例6: createRouteDtos
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
protected static List<NodeDto> createRouteDtos(CamelCatalog camelCatalog, List<RouteDefinition> routeDefs, ContextDto context) {
List<NodeDto> answer = new ArrayList<>();
Map<String, Integer> nodeCounts = new HashMap<>();
for (RouteDefinition def : routeDefs) {
RouteDto route = new RouteDto();
route.setId(def.getId());
route.setLabel(CamelModelHelper.getDisplayText(def));
route.setDescription(CamelModelHelper.getDescription(def));
answer.add(route);
route.defaultKey(context, nodeCounts);
addInputs(camelCatalog, route, def.getInputs());
addOutputs(camelCatalog, route, def.getOutputs());
}
return answer;
}
示例7: testAdviceWithInterceptFrom
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
public void testAdviceWithInterceptFrom() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptFrom().to("mock:from");
}
});
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:from").expectedBodiesReceived("World");
getMockEndpoint("mock:from").expectedHeaderReceived(Exchange.INTERCEPTED_ENDPOINT, "direct://start");
template.sendBody("direct:start", "World");
assertMockEndpointsSatisfied();
}
示例8: 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();
}
示例9: testOnException
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
public void testOnException() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("seda:*")
.skipSendToOriginalEndpoint()
.throwException(new ConnectException("Forced"));
}
});
getMockEndpoint("mock:local").expectedMessageCount(0);
getMockEndpoint("mock:seda").expectedMessageCount(0);
// we fail all redeliveries so after that we send to mock:exhausted
getMockEndpoint("mock:exhausted").expectedMessageCount(1);
try {
template.sendBody("direct:start", "Hello World");
fail("Should thrown an exception");
} catch (CamelExecutionException e) {
ConnectException cause = assertIsInstanceOf(ConnectException.class, e.getCause());
assertEquals("Forced", cause.getMessage());
}
assertMockEndpointsSatisfied();
}
示例10: testValidateId
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
public void testValidateId() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
RouteDefinition route = context.getRouteDefinition("myRoute");
assertNotNull(route);
// mock:result should be the only with the result as id
assertTrue(route.getOutputs().get(0).getId().equals("myValidate"));
assertFalse(route.getOutputs().get(1).getId().equals("result"));
assertTrue(route.getOutputs().get(2).getId().equals("result"));
assertTrue(route.getOutputs().get(3).getId().equals("after"));
}
示例11: testIssue
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
public void testIssue() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("seda:*")
.skipSendToOriginalEndpoint()
.throwException(new ConnectException("Forced"));
}
});
getMockEndpoint("mock:global").expectedMessageCount(0);
getMockEndpoint("mock:seda").expectedMessageCount(0);
// we fail all redeliveries so after that we send to mock:exhausted
getMockEndpoint("mock:exhausted").expectedMessageCount(1);
try {
template.sendBody("direct:start", "Hello World");
fail("Should thrown an exception");
} catch (CamelExecutionException e) {
ConnectException cause = assertIsInstanceOf(ConnectException.class, e.getCause());
assertEquals("Forced", cause.getMessage());
}
assertMockEndpointsSatisfied();
}
示例12: testXmlDSL
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
@Test
public void testXmlDSL() throws Exception {
CamelContext camelContext = new DefaultCamelContext();
// This is normally done by the Spring implemented registry, we keep it simple here...
TamayaPropertiesComponent props = new TamayaPropertiesComponent();
props.setTamayaOverrides(true);
camelContext.addComponent("properties", props);
// Read routes from XML DSL
InputStream is = getClass().getResourceAsStream("/META-INF/routes.xml");
RoutesDefinition routes = camelContext.loadRoutesDefinition(is);
for(RouteDefinition def: routes.getRoutes()) {
camelContext.addRouteDefinition(def);
}
camelContext.start();
Greeter greeter = new ProxyBuilder(camelContext).endpoint("direct:hello1").build(Greeter.class);
assertEquals("Good Bye from Apache Tamaya!", greeter.greet());
greeter = new ProxyBuilder(camelContext).endpoint("direct:hello2").build(Greeter.class);
assertEquals("Good Bye from Apache Tamaya!", greeter.greet());
greeter = new ProxyBuilder(camelContext).endpoint("direct:hello3").build(Greeter.class);
assertEquals("Good Bye from Apache Tamaya!", greeter.greet());
}
示例13: testAddRouteDefinitionsFromXmlIsPrepared
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
public void testAddRouteDefinitionsFromXmlIsPrepared() throws Exception {
RouteDefinition route = loadRoute("route1.xml");
assertNotNull(route);
assertEquals("foo", route.getId());
assertEquals(0, context.getRoutes().size());
context.addRouteDefinition(route);
assertEquals(1, context.getRoutes().size());
assertTrue("Route should be started", context.getRouteStatus("foo").isStarted());
// should be prepared, check parents has been set
assertNotNull("Parent should be set on outputs");
route = context.getRouteDefinition("foo");
for (ProcessorDefinition<?> output : route.getOutputs()) {
assertNotNull("Parent should be set on output", output.getParent());
assertEquals(route, output.getParent());
}
}
示例14: removeUrlFromCamelRoutes
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
private void removeUrlFromCamelRoutes(ApplicationOptions options) throws Exception {
String servicePath = options.getContextPath();
String toUri = null;
if (options.isRequiresSSL()) {
toUri = "https://" + InetAddress.getLocalHost().getHostAddress() + ":" + options.getHttpsPort() +
options.getContextPath() + "?bridgeEndpoint=true&throwExceptionOnFailure=false&matchOnUriPrefix=true";
} else {
toUri = "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + options.getPort() +
options.getContextPath() + "?bridgeEndpoint=true&throwExceptionOnFailure=false&matchOnUriPrefix=true";
}
final InputStream in = com.beyondj.gateway.support.JsonRuleBaseBuilder.newRuleBase().rule(servicePath, toUri).inputStream();
ModelCamelContext modelCamelContext = (ModelCamelContext) camelContext;
RouteDefinition routeDefinition = modelCamelContext.getRouteDefinition(GatewayRouter.GATEWAY_ROUTE_ID);
if (routeDefinition == null) {
int port = Integer.valueOf(
config.getProperty(SYSTEM_GATEWAY_ROUTE_PORT));
camelContext.addRoutes(new GatewayRouter(coreMetricsService, scalingDataService, port));
}
LoadBalancerDefinition loadBalancerDefinition = getLoadBalancerDefinition(options);
Map<String, HttpProxyRule> rules = JsonRuleBaseReader.parseJson(loadBalancerDefinition, in);
gatewayRulesService.removeGatewayRules(rules);
}
示例15: routeContextBean
import org.apache.camel.model.RouteDefinition; //导入依赖的package包/类
private SyntheticBean<?> routeContextBean(RouteContextDefinition definition, URL url) {
requireNonNull(definition.getId(),
() -> format("Missing [%s] attribute for imported bean [%s] from resource [%s]",
"id", "routeContext", url));
return new SyntheticBean<>(manager,
new SyntheticAnnotated(List.class,
Stream.of(List.class, new ListParameterizedType(RouteDefinition.class))
.collect(toSet()),
ANY, NamedLiteral.of(definition.getId())),
List.class,
new SyntheticInjectionTarget<>(definition::getRoutes), bean ->
"imported route context with "
+ "id [" + definition.getId() + "] "
+ "from resource [" + url + "] "
+ "with qualifiers " + bean.getQualifiers());
}