org.apache.camel.builder.Builder Java Examples

The following examples show how to use org.apache.camel.builder.Builder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SplitAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
    String languageName = language;
    String expressionDefinition = expression;

    if (ObjectHelper.isEmpty(languageName) && ObjectHelper.isEmpty(expressionDefinition)) {
        route = route.split(Builder.body());
    } else if (ObjectHelper.isNotEmpty(expressionDefinition)) {

        if (ObjectHelper.isEmpty(languageName)) {
            languageName = "simple";
        }

        // A small hack until https://issues.apache.org/jira/browse/CAMEL-12079
        // gets fixed so we can support the 'bean::method' annotation as done by
        // Function step definition
        if ("bean".equals(languageName) && expressionDefinition.contains("::")) {
            expressionDefinition = expressionDefinition.replace("::", "?method=");
        }

        final Language splitLanguage = context.resolveLanguage(languageName);
        final Expression splitExpression = splitLanguage.createExpression(expressionDefinition);

        route = route.split(splitExpression).aggregationStrategy(new UseOriginalAggregationStrategy(null, false));
    }

    return Optional.of(route);
}
 
Example #2
Source File: SplitStepHandler.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"PMD.AvoidReassigningParameters", "PMD.AvoidDeeplyNestedIfStmts"})
@Override
public Optional<ProcessorDefinition<?>> handle(Step step, ProcessorDefinition<?> route, IntegrationRouteBuilder builder, String flowIndex, String stepIndex) {
    ObjectHelper.notNull(route, "route");

    SplitExpression splitExpression;
    String languageName = step.getConfiguredProperties().get("language");
    String expressionDefinition = step.getConfiguredProperties().get("expression");

    if (step.hasUnifiedJsonSchemaOutputShape()) {
        // we have to split the nested unified body property by default.
        splitExpression = new SplitExpression(new UnifiedJsonBodyExpression(Builder.body()));
    } else if (ObjectHelper.isNotEmpty(expressionDefinition)) {
        if (ObjectHelper.isEmpty(languageName)) {
            languageName = "simple";
        }

        // A small hack until https://issues.apache.org/jira/browse/CAMEL-12079
        // gets fixed so we can support the 'bean::method' annotation as done by
        // Function step definition
        if ("bean".equals(languageName) && expressionDefinition.contains("::")) {
            expressionDefinition = expressionDefinition.replace("::", "?method=");
        }

        final Language language = builder.getContext().resolveLanguage(languageName);
        splitExpression = new SplitExpression(language.createExpression(expressionDefinition));
    } else {
        splitExpression = new SplitExpression(Builder.body());
    }

    AggregateStepHandler.AggregationOption aggregation = Optional.ofNullable(step.getConfiguredProperties().get("aggregationStrategy"))
            .map(AggregateStepHandler.AggregationOption::valueOf)
            .orElse(AggregateStepHandler.AggregationOption.body);

    route = route.split(splitExpression).aggregationStrategy(aggregation.getStrategy(step.getConfiguredProperties()));

    return Optional.of(route);
}
 
Example #3
Source File: QuteTestBase.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
protected static ValueBuilder body() {
    return Builder.body();
}
 
Example #4
Source File: CommandDTOTest.java    From hacep with Apache License 2.0 4 votes vote down vote up
@Test
public void testInputCommand() throws Exception {
    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
                @Override
                public void configure() throws Exception {
                    replaceFromWith("direct:test");
                    mockEndpoints("direct:execute-command");
                }
            }
    );
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:NOME_COMMAND")
                    .to("mock:results");
        }
    });

    String input = "{\n" +
            "  \"command\": \"NOME_COMMAND\",\n" +
            "  \"params\": [\n" +
            "    {\n" +
            "      \"key\": \"NOME_CHIAVE1\",\n" +
            "      \"value\": \"VALORE1\"\n" +
            "    },\n" +
            "    {\n" +
            "      \"key\": \"NOME_CHIAVE2\",\n" +
            "      \"value\": \"VALORE2\"\n" +
            "    }\n" +
            "  ]\n" +
            "}\n";

    context.start();

    getMockEndpoint("mock:direct:execute-command", false).expectedMessageCount(1);
    getMockEndpoint("mock:direct:execute-command", false)
            .message(0)
            .predicate(isInstanceOf(body(), Command.class))
            .predicate(isEqualTo(Builder.simple("${body.command}"), Builder.constant("NOME_COMMAND")))
            .predicate(isEqualTo(Builder.simple("${body.params?.size}"), Builder.constant(2)))
            .predicate(isInstanceOf(Builder.simple("${body.params[0]}"), KeyValueParam.class))
            .predicate(isEqualTo(Builder.simple("${body.params[0].key}"), Builder.constant("NOME_CHIAVE1")))
            .predicate(isEqualTo(Builder.simple("${body.params[0].value}"), Builder.constant("VALORE1")))
            .predicate(isInstanceOf(Builder.simple("${body.params[1]}"), KeyValueParam.class))
            .predicate(isEqualTo(Builder.simple("${body.params[1].key}"), Builder.constant("NOME_CHIAVE2")))
            .predicate(isEqualTo(Builder.simple("${body.params[1].value}"), Builder.constant("VALORE2")));

    getMockEndpoint("mock:results", false).expectedMessageCount(1);

    sendBody("direct:test", input);

    assertMockEndpointsSatisfied(1, TimeUnit.MINUTES);
}