当前位置: 首页>>代码示例>>Java>>正文


Java RouteDefinition类代码示例

本文整理汇总了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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:RouteScopedErrorHandlerAndOnExceptionTest.java

示例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;
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:17,代码来源:TraceRouteBuilder.java

示例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;
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:18,代码来源:TraceRouteBuilder.java

示例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);

                    }
                }
            }
        };
    }
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:23,代码来源:RouteBuilders.java

示例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;
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:22,代码来源:CamelXmlHelper.java

示例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;
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:17,代码来源:CamelXmlHelper.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:AdviceWithIssueTest.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:AdviceWithTwoRoutesOnExceptionTest.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:RouteScopedErrorHandlerAndOnExceptionTest.java

示例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"));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:ValidateIdTest.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:RouteScopedOnExceptionWithInterceptSendToEndpointIssueTest.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-tamaya-sandbox,代码行数:22,代码来源:TamayaPropertyResolverTest.java

示例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());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:CamelContextAddRouteDefinitionsFromXmlTest.java

示例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);
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:27,代码来源:SystemGatewayActor.java

示例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());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:XmlCdiBeanFactory.java


注:本文中的org.apache.camel.model.RouteDefinition类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。