Java 类org.apache.camel.model.ChoiceDefinition 实例源码

项目:syndesis    文件:ChoiceHandler.java   
@Override
public Optional<ProcessorDefinition> handle(Choice step, ProcessorDefinition route, SyndesisRouteBuilder routeBuilder) {
    final CamelContext context = routeBuilder.getContext();
    final ChoiceDefinition choice = route.choice();

    List<Filter> filters = ObjectHelper.supplyIfEmpty(step.getFilters(), Collections::<Filter>emptyList);
    for (Filter filter : filters) {
        Predicate predicate = JsonSimpleHelpers.getMandatorySimplePredicate(context, filter, filter.getExpression());
        ChoiceDefinition when = choice.when(predicate);

        routeBuilder.addSteps(when, filter.getSteps());
    }

    Otherwise otherwiseStep = step.getOtherwise();
    if (otherwiseStep != null) {
        List<Step> otherwiseSteps = ObjectHelper.supplyIfEmpty(otherwiseStep.getSteps(), Collections::<Step>emptyList);
        if (!otherwiseSteps.isEmpty()) {
            routeBuilder.addSteps(choice.otherwise(), otherwiseSteps);
        }
    }

    return Optional.empty();
}
项目:syndesis-integration-runtime    文件:ChoiceHandler.java   
@Override
public ProcessorDefinition handle(Choice step, ProcessorDefinition route, SyndesisRouteBuilder routeBuilder) {
    final CamelContext context = routeBuilder.getContext();
    final ChoiceDefinition choice = route.choice();

    List<Filter> filters = ObjectHelper.supplyIfEmpty(step.getFilters(), Collections::emptyList);
    for (Filter filter : filters) {
        Predicate predicate = JsonSimpleHelpers.getMandatorySimplePredicate(context, filter, filter.getExpression());
        ChoiceDefinition when = choice.when(predicate);

        route = routeBuilder.addSteps(when, filter.getSteps());
    }

    Otherwise otherwiseStep = step.getOtherwise();
    if (otherwiseStep != null) {
        List<Step> otherwiseSteps = ObjectHelper.supplyIfEmpty(otherwiseStep.getSteps(), Collections::emptyList);
        if (!otherwiseSteps.isEmpty()) {
            route = routeBuilder.addSteps(choice.otherwise(), otherwiseSteps);
        }
    }

    return route;
}
项目:Camel    文件:CustomIdIssuesTest.java   
@Test
public void testCustomId() {
    RouteDefinition route = context.getRouteDefinition("myRoute");
    assertNotNull(route);
    assertTrue(route.hasCustomIdAssigned());

    FromDefinition from = route.getInputs().get(0);
    assertEquals("fromFile", from.getId());
    assertTrue(from.hasCustomIdAssigned());

    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("myChoice", choice.getId());
    assertTrue(choice.hasCustomIdAssigned());

    WhenDefinition when = choice.getWhenClauses().get(0);
    assertTrue(when.hasCustomIdAssigned());
    assertEquals("UK", when.getId());

    LogDefinition log = (LogDefinition) choice.getOtherwise().getOutputs().get(0);
    assertFalse(log.hasCustomIdAssigned());
}
项目:Camel    文件:CustomIdIssuesTest.java   
public void testCustomId() {
    RouteDefinition route = context.getRouteDefinition("myRoute");
    assertNotNull(route);
    assertTrue(route.hasCustomIdAssigned());

    FromDefinition from = route.getInputs().get(0);
    assertEquals("fromFile", from.getId());
    assertTrue(from.hasCustomIdAssigned());

    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("myChoice", choice.getId());
    assertTrue(choice.hasCustomIdAssigned());

    WhenDefinition when = choice.getWhenClauses().get(0);
    assertTrue(when.hasCustomIdAssigned());
    assertEquals("UK", when.getId());

    LogDefinition log = (LogDefinition) choice.getOtherwise().getOutputs().get(0);
    assertFalse(log.hasCustomIdAssigned());
}
项目:drinkwater-java    文件:TraceRouteBuilder.java   
public static ChoiceDefinition addServerReceivedTracing(IDrinkWaterService service,
                                                       ChoiceDefinition routeDefinition) {
    ChoiceDefinition answer = routeDefinition;
    if (!service.getConfiguration().getIsTraceEnabled()) {
        return answer;
    }

    answer = routeDefinition
            .setHeader(BeanOperationName)
            .method(ExtractHttpMethodFromExchange.class)
            .to(ROUTE_serverReceivedEvent);


    return answer;
}
项目:drinkwater-java    文件:TraceRouteBuilder.java   
public static ChoiceDefinition addServerReceivedTracing(IDrinkWaterService service,
                                                       ChoiceDefinition routeDefinition) {
    ChoiceDefinition answer = routeDefinition;
    if (!service.getConfiguration().getIsTraceEnabled()) {
        return answer;
    }

    answer = routeDefinition
            .setHeader(BeanOperationName)
            .method(ExtractHttpMethodFromExchange.class)
            .to(ROUTE_serverReceivedEvent);


    return answer;
}
项目:Camel    文件:AdviceWithWeaveByTypeCBRTest.java   
public void testWeaveByType() throws Exception {
    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            weaveByType(ChoiceDefinition.class).replace().to("mock:baz");
        }
    });

    getMockEndpoint("mock:baz").expectedMessageCount(1);

    template.sendBody("direct:start", "World");

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:TraceInitIdOnAllNodesTest.java   
public void testInitIdsOnAllNodes() throws Exception {
    getMockEndpoint("mock:camel").expectedBodiesReceived("Hello Camel");
    getMockEndpoint("mock:other").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:end").expectedMessageCount(2);

    template.sendBody("direct:start", "Hello Camel");
    template.sendBody("direct:start", "Hello World");

    assertMockEndpointsSatisfied();

    RouteDefinition route = context.getRouteDefinitions().get(0);
    assertNotNull(route);

    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("choice1", choice.getId());

    WhenDefinition when = (WhenDefinition) choice.getOutputs().get(0);
    assertEquals("when1", when.getId());

    LogDefinition log1 = (LogDefinition) when.getOutputs().get(0);
    assertEquals("log1", log1.getId());

    ToDefinition to1 = (ToDefinition) when.getOutputs().get(1);
    assertEquals("camel", to1.getId());

    OtherwiseDefinition other = (OtherwiseDefinition) choice.getOutputs().get(1);
    assertEquals("otherwise1", other.getId());

    LogDefinition log2 = (LogDefinition) other.getOutputs().get(0);
    assertEquals("log2", log2.getId());

    ToDefinition to2 = (ToDefinition) other.getOutputs().get(1);
    assertEquals("to1", to2.getId());

    ToDefinition to3 = (ToDefinition) other.getOutputs().get(2);
    assertEquals("foo", to3.getId());

    ToDefinition to4 = (ToDefinition) route.getOutputs().get(1);
    assertEquals("end", to4.getId());
}
项目:drinkwater-java    文件:RouteBuilders.java   
public static RouteBuilder mapRoutingRoutes(DrinkWaterApplication app, Service service) {

        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {

                String frontEndpoint = endpointFrom(service);

                String handlers = getHandlersForJetty(service);
                String handlersConfig = handlers == null ? "":"&handlers="+handlers;

                RouteDefinition frontRoute = from("jetty:" + frontEndpoint + "?matchOnUriPrefix=true&optionsEnabled=true" + handlersConfig);

                from("direct:SINK_OK_ENDPOINT").transform().constant("OK");

                frontRoute = enableCorsOnRoute(frontRoute, service);

                frontRoute.onException(UnauthorizedException.class)
                        .handled(true)
                        .setHeader("WWW-Authenticate").constant("TOKEN")
                        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(401))
                        .setBody().constant("Unauthorized");


                ChoiceDefinition choice = frontRoute.choice();

                choice.when(header(Exchange.HTTP_METHOD)
                        .isEqualTo("OPTIONS")).to("direct:SINK_OK_ENDPOINT").endChoice();

                //TODO : fix the way to get the target host
                service.getConfiguration().getRoutingMap().forEach(
                        (key, val) -> {

                            // IServiceConfiguration s = app.getServiceDefinition(val);
                            IDrinkWaterService serviceTemp = app.getDrinkWaterService(val);

                            //Issue #8
                            //TODO better correction needed.
                            String serviceHost = serviceTemp.getConfiguration().getServiceHost();
                            if (serviceTemp.getConfiguration().getScheme() == ServiceScheme.Routeur) {
                                try {
                                    serviceHost = endpointFrom(serviceTemp);
                                } catch (Exception e) {
                                    throw new RuntimeException();
                                }
                            }

                            ChoiceDefinition remapChoice = null;

                            if (!"default".equalsIgnoreCase(key)) {
                                remapChoice = choice.when(header(service.getConfiguration().getRoutingHeader()).contains(key));
                            } else {
                                remapChoice = choice.otherwise();
                            }

                            remapChoice = addServerReceivedTracing(service, remapChoice);
                            remapChoice.to("jetty:" + serviceHost + "?bridgeEndpoint=true&throwExceptionOnFailure=true");
                            addServerSentTracing(service, remapChoice);
                        }

                );

            }
        };
    }
项目:drinkwater-java    文件:RouteBuilders.java   
public static RouteBuilder mapRoutingRoutes(DrinkWaterApplication app, Service service) {

        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {

                String frontEndpoint = endpointFrom(service);

                String handlers = getHandlersForJetty(service);
                String handlersConfig = handlers == null ? "":"&handlers="+handlers;

                RouteDefinition frontRoute = from("jetty:" + frontEndpoint + "?matchOnUriPrefix=true&optionsEnabled=true" + handlersConfig);

                from("direct:SINK_OK_ENDPOINT").transform().constant("OK");

                frontRoute = enableCorsOnRoute(frontRoute, service);

                frontRoute.onException(UnauthorizedException.class)
                        .handled(true)
                        .setHeader("WWW-Authenticate").constant("TOKEN")
                        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(401))
                        .setBody().constant("Unauthorized");


                ChoiceDefinition choice = frontRoute.choice();

                choice.when(header(Exchange.HTTP_METHOD)
                        .isEqualTo("OPTIONS")).to("direct:SINK_OK_ENDPOINT").endChoice();

                //TODO : fix the way to get the target host
                service.getConfiguration().getRoutingMap().forEach(
                        (key, val) -> {

                            // IServiceConfiguration s = app.getServiceDefinition(val);
                            IDrinkWaterService serviceTemp = app.getDrinkWaterService(val);

                            //Issue #8
                            //TODO better correction needed.
                            String serviceHost = serviceTemp.getConfiguration().getServiceHost();
                            if (serviceTemp.getConfiguration().getScheme() == ServiceScheme.Routeur) {
                                try {
                                    serviceHost = endpointFrom(serviceTemp);
                                } catch (Exception e) {
                                    throw new RuntimeException();
                                }
                            }

                            ChoiceDefinition remapChoice = null;

                            if (!"default".equalsIgnoreCase(key)) {
                                remapChoice = choice.when(header(service.getConfiguration().getRoutingHeader()).contains(key));
                            } else {
                                remapChoice = choice.otherwise();
                            }

                            remapChoice = addServerReceivedTracing(service, remapChoice);
                            remapChoice.to("jetty:" + serviceHost + "?bridgeEndpoint=true&throwExceptionOnFailure=true");
                            addServerSentTracing(service, remapChoice);
                        }

                );

            }
        };
    }
项目:Camel    文件:ManagedChoice.java   
@Override
public ChoiceDefinition getDefinition() {
    return (ChoiceDefinition) super.getDefinition();
}
项目:Camel    文件:CamelGroovyMethods.java   
public static ChoiceDefinition when(ChoiceDefinition self, Closure<?> predicate) {
    return self.when(toExpression(predicate));
}
项目:Camel    文件:CamelGroovyMethods.java   
public static ChoiceDefinition when(ChoiceDefinition self, Closure<?> filter) {
    return self.when(toExpression(filter));
}