Java Code Examples for org.apache.camel.impl.DefaultCamelContext#setRegistry()

The following examples show how to use org.apache.camel.impl.DefaultCamelContext#setRegistry() . 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: CamelMailetContainerModule.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Singleton
@Provides
public DefaultCamelContext provideCamelContext() {
    DefaultCamelContext camelContext = new DefaultCamelContext();
    camelContext.disableJMX();
    camelContext.setRegistry(new SimpleRegistry());
    return camelContext;
}
 
Example 2
Source File: ChoiceStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testChoiceStep() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder integrationRoute = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "flow")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(CHOICE_STEP)
                .stepKind(StepKind.choice)
                .putConfiguredProperty("flows", "[" +
                                    "{\"condition\": \"${body} contains 'Hello'\", \"flow\": \"hello-flow\"}," +
                                    "{\"condition\": \"${body} contains 'Bye'\", \"flow\": \"bye-flow\"}" +
                                "]")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "result")
                        .build())
                    .build())
                .build()
        );

        final RouteBuilder helloRoute = new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:hello-flow")
                        .to("mock:hello");
            }
        };

        final RouteBuilder byeRoute = new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:bye-flow")
                        .to("mock:bye");
            }
        };

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(helloRoute);
        context.addRoutes(byeRoute);
        context.addRoutes(integrationRoute);

        SimpleRegistry beanRegistry = new SimpleRegistry();
        beanRegistry.bind("bodyLogger", new BodyLogger.Default());
        context.setRegistry(beanRegistry);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
        final MockEndpoint helloResult = context.getEndpoint("mock:hello", MockEndpoint.class);
        final MockEndpoint byeResult = context.getEndpoint("mock:bye", MockEndpoint.class);

        final List<String> messages = Arrays.asList("Hello Camel!", "Bye Camel!", "And Now for Something Completely Different");

        result.expectedBodiesReceived(messages);
        helloResult.expectedBodiesReceived("Hello Camel!");
        byeResult.expectedBodiesReceived("Bye Camel!");

        for (String message : messages) {
            template.sendBody("direct:flow", message);
        }

        result.assertIsSatisfied();
        helloResult.assertIsSatisfied();
        byeResult.assertIsSatisfied();

        verify(activityTracker, times(3)).startTracking(any(Exchange.class));
        verifyActivityStepTracking(CHOICE_STEP, 3);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verify(activityTracker, times(3)).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 3
Source File: ChoiceStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testChoiceStepWithRuleBasedConditions() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder integrationRoute = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                        .id(START_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("direct")
                                        .putConfiguredProperty("name", "flow")
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(CHOICE_STEP)
                        .stepKind(StepKind.choice)
                        .putConfiguredProperty("routingScheme", "mock")
                        .putConfiguredProperty("flows", "[" +
                                    "{\"condition\": \"\", \"path\": \"text\", \"op\": \"contains\", \"value\": \"Hello\", \"flow\": \"hello-flow\"}," +
                                    "{\"condition\": \"\", \"path\": \"text\", \"op\": \"contains\", \"value\": \"Bye\", \"flow\": \"bye-flow\"}" +
                                "]")
                        .build(),
                new Step.Builder()
                        .id(MOCK_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("mock")
                                        .putConfiguredProperty("name", "result")
                                        .build())
                                .build())
                        .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(integrationRoute);

        SimpleRegistry beanRegistry = new SimpleRegistry();
        beanRegistry.bind("bodyLogger", new BodyLogger.Default());
        context.setRegistry(beanRegistry);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
        final MockEndpoint helloResult = context.getEndpoint("mock:hello-flow", MockEndpoint.class);
        final MockEndpoint byeResult = context.getEndpoint("mock:bye-flow", MockEndpoint.class);

        final List<String> messages = Arrays.asList("{\"text\": \"Hello Camel!\"}", "{\"text\": \"Bye Camel!\"}", "{\"text\": \"And Now for Something Completely Different\"}");

        result.expectedBodiesReceived(messages);
        helloResult.expectedBodiesReceived("{\"text\": \"Hello Camel!\"}");
        byeResult.expectedBodiesReceived("{\"text\": \"Bye Camel!\"}");

        for (String message : messages) {
            template.sendBody("direct:flow", message);
        }

        result.assertIsSatisfied();
        helloResult.assertIsSatisfied();
        byeResult.assertIsSatisfied();

        verify(activityTracker, times(3)).startTracking(any(Exchange.class));
        verifyActivityStepTracking(CHOICE_STEP, 3);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verify(activityTracker, times(3)).finishTracking(any(Exchange.class));

    } finally {
        context.stop();
    }
}
 
Example 4
Source File: SplitStepHandlerJsonTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
/**
 * Test subsequent split/aggregate where a 1st split operates on a initial collection of elements and a
 * 2nd split operates on a completely new collection provided by some mock endpoint.
 * direct -> split -> log -> aggregate -> bean:myMock -> split -> log -> aggregate -> mock
 */
@Test
public void testSubsequentSplitAggregate() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = new IntegrationRouteBuilder(
                "classpath:/syndesis/integration/subsequent-split.json",
                Resources.loadServices(IntegrationStepHandler.class)
        );

        // Set up the camel context
        context.addRoutes(routes);

        SimpleRegistry beanRegistry = new SimpleRegistry();
        beanRegistry.bind("bodyLogger", new BodyLogger.Default());
        beanRegistry.bind("myMock", (Processor) exchange -> exchange.getIn().setBody(Arrays.asList("d", "e", "f")));
        context.setRegistry(beanRegistry);

        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class);
        final List<String> body = Arrays.asList("a", "b", "c");

        result.expectedMessageCount(1);

        template.sendBody("direct:expression", body);

        result.assertIsSatisfied();
        List<?> bodyReceived = result.getExchanges().get(0).getIn().getBody(List.class);
        assertThat(bodyReceived).hasSize(3);
        assertThat(bodyReceived.get(0)).isEqualTo("d");
        assertThat(bodyReceived.get(1)).isEqualTo("e");
        assertThat(bodyReceived.get(2)).isEqualTo("f");
    } finally {
        context.stop();
    }
}
 
Example 5
Source File: SplitStepHandlerJsonTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private static void addBodyLogger(DefaultCamelContext context) {
    SimpleRegistry beanRegistry = new SimpleRegistry();
    beanRegistry.bind("bodyLogger", new BodyLogger.Default());
    context.setRegistry(beanRegistry);
}
 
Example 6
Source File: LogStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldAddLogStepActivityLogging() throws Exception {
    final ActivityTracker activityTracker = Mockito.mock(ActivityTracker.class);
    final DefaultCamelContext context = new DefaultCamelContext();

    doAnswer(invocation -> {
        ActivityTracker.initializeTracking(invocation.getArgument(0));
        return null;
    }).when(activityTracker).startTracking(any(Exchange.class));

    doAnswer(invocation -> {
        LOGGER.debug(JsonSupport.toJsonObject(invocation.getArguments()));
        return null;
    }).when(activityTracker).track(any());

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                        .id(START_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("direct")
                                        .putConfiguredProperty("name", "start")
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(LOG_STEP)
                        .stepKind(StepKind.log)
                        .putConfiguredProperty("bodyLoggingEnabled", "true")
                        .putConfiguredProperty("customText", "Log me baby one more time")
                        .build(),
                new Step.Builder()
                        .id(MOCK_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("mock")
                                        .putConfiguredProperty("name", "result")
                                        .build())
                                .build())
                        .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);

        SimpleRegistry beanRegistry = new SimpleRegistry();
        beanRegistry.bind("bodyLogger", new BodyLogger.Default());
        context.setRegistry(beanRegistry);

        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        List<String> messages = Arrays.asList("Hi", "Hello");

        result.expectedBodiesReceived(messages);

        for (Object body : messages) {
            template.sendBody("direct:start", body);
        }

        result.assertIsSatisfied();

        verify(activityTracker, times(messages.size())).startTracking(any(Exchange.class));
        verify(activityTracker, times(messages.size())).track(eq("exchange"), anyString(), eq("step"), eq(START_STEP), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker).track(eq("exchange"), anyString(), eq("step"), eq(LOG_STEP), eq("id"), anyString(), eq("message"), eq("Body: [Hi] Log me baby one more time"));
        verify(activityTracker).track(eq("exchange"), anyString(), eq("step"), eq(LOG_STEP), eq("id"), anyString(), eq("message"), eq("Body: [Hello] Log me baby one more time"));
        verify(activityTracker, times(messages.size())).track(eq("exchange"), anyString(), eq("step"), eq(LOG_STEP), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker, times(messages.size())).track(eq("exchange"), anyString(), eq("step"), eq(MOCK_STEP), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker, times(6)).track(eq("exchange"), anyString(), eq("step"), anyString(), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker, times(messages.size())).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}