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

The following examples show how to use org.apache.camel.impl.DefaultCamelContext#setName() . 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: DecanterTraceEventHandlerTest.java    From karaf-decanter with Apache License 2.0 6 votes vote down vote up
private DefaultCamelContext createCamelContext(TraceEventHandler handler) throws Exception {
    RouteBuilder builder = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").routeId("test-route").to("log:foo");
        }
    };
    DefaultCamelContext camelContext = new DefaultCamelContext();
    camelContext.setName("test-context");
    camelContext.addRoutes(builder);
    Tracer tracer = new Tracer();
    tracer.setEnabled(true);
    tracer.setTraceOutExchanges(true);
    tracer.setLogLevel(LoggingLevel.OFF);
    tracer.addTraceHandler(handler);
    camelContext.setTracing(true);
    camelContext.setDefaultTracer(tracer);
    camelContext.start();
    return camelContext;
}
 
Example 2
Source File: DecanterEventNotifierTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
private DefaultCamelContext createCamelContext(DecanterEventNotifier notifier) throws Exception {
    RouteBuilder builder = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").routeId("test-route").to("log:foo");
        }
    };

    DefaultCamelContext camelContext = new DefaultCamelContext();
    camelContext.setName("test-context");
    camelContext.addRoutes(builder);
    camelContext.getManagementStrategy().addEventNotifier(notifier);
    camelContext.start();
    return camelContext;
}
 
Example 3
Source File: SwaggerIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testSwagger() throws Exception {
    DefaultCamelContext camelctx = new DefaultCamelContext();
    camelctx.setName("swagger-test");
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            restConfiguration().component("undertow")
                .contextPath("swagger-tests")
                .host("localhost")
                .port(8080)
                .apiContextPath("/api-doc")
                .apiProperty("api.title", "User API")
                .apiProperty("api.version", "1.2.3")
                .apiProperty("cors", "true");
            rest("/hello")
                .get("/{name}").description("A user object").outType(User.class).to("direct:hello")
                .produces(MediaType.APPLICATION_JSON)
                .consumes(MediaType.APPLICATION_JSON);
            from("direct:hello").transform(simple("Hello ${header.name}"));
        }
    });

    camelctx.start();
    try {
        HttpRequest.HttpResponse result = HttpRequest.get("http://localhost:8080/swagger-tests/hello/Kermit").getResponse();
        Assert.assertEquals("Hello Kermit", result.getBody());

        result = HttpRequest.get("http://localhost:8080/swagger-tests/api-doc").getResponse();
        Assert.assertEquals(HttpURLConnection.HTTP_OK, result.getStatusCode());
        Assert.assertTrue("Contains substr: " + result.getBody(), result.getBody().contains("\"name\" : \"hello\""));
    } finally {
        camelctx.close();
    }
}
 
Example 4
Source File: CamelContextProducerB.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Produces
@ApplicationScoped
CamelContext customize() {
    DefaultCamelContext camelctx = new DefaultCamelContext();
    camelctx.setName("context-producer-b");
    return camelctx;
}
 
Example 5
Source File: CamelContextProducerA.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Produces
@ApplicationScoped
CamelContext customize() {
    DefaultCamelContext camelctx = new DefaultCamelContext();
    camelctx.setName("context-producer-a");
    return camelctx;
}
 
Example 6
Source File: CustomCamelContextFactory.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    camelctx = new DefaultCamelContext();
    camelctx.setName("manual-context");
    try {
        camelctx.start();
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
 
Example 7
Source File: CamelCollectorTest.java    From karaf-decanter with Apache License 2.0 4 votes vote down vote up
@Test
public void testTracer() throws Exception {
    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-collector-camel", new RolePrincipal("admin")));

    // add a event handler
    List<Event> received = new ArrayList();
    EventHandler eventHandler = new EventHandler() {
        @Override
        public void handleEvent(Event event) {
            received.add(event);
        }
    };
    Hashtable serviceProperties = new Hashtable();
    serviceProperties.put(EventConstants.EVENT_TOPIC, "decanter/collect/*");
    bundleContext.registerService(EventHandler.class, eventHandler, serviceProperties);

    // create route with tracer
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    DecanterTraceEventHandler handler = new DecanterTraceEventHandler();
    handler.setEventAdmin(eventAdmin);

    RouteBuilder routeBuilder = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:test").routeId("route-test").to("log:foo");
        }
    };
    DefaultCamelContext camelContext = new DefaultCamelContext();
    camelContext.setName("context-test");
    camelContext.addRoutes(routeBuilder);
    Tracer tracer = new Tracer();
    tracer.setEnabled(true);
    tracer.setTraceOutExchanges(true);
    tracer.setLogLevel(LoggingLevel.OFF);
    tracer.addTraceHandler(handler);
    camelContext.setTracing(true);
    camelContext.setDefaultTracer(tracer);
    camelContext.start();

    // send a exchange into the route
    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBodyAndHeader("direct:test", "This is a test", "testHeader", "testValue");

    // TODO two events ?
    Assert.assertEquals(2, received.size());

    Assert.assertEquals("decanter/collect/camel/tracer", received.get(0).getTopic());
    Assert.assertEquals("context-test", received.get(0).getProperty("camelContextName"));
    Assert.assertEquals("InOnly", received.get(0).getProperty("exchangePattern"));
    Assert.assertEquals("camelTracer", received.get(0).getProperty("type"));
    Assert.assertEquals("log://foo", received.get(0).getProperty("toNode"));
    Assert.assertEquals("route-test", received.get(0).getProperty("routeId"));
    Assert.assertEquals("direct://test", received.get(0).getProperty("fromEndpointUri"));
    Assert.assertEquals("root", received.get(0).getProperty("karafName"));
    Assert.assertEquals("This is a test", received.get(0).getProperty("inBody"));
    Assert.assertEquals("String", received.get(0).getProperty("inBodyType"));
}
 
Example 8
Source File: CamelCollectorTest.java    From karaf-decanter with Apache License 2.0 4 votes vote down vote up
@Test
public void testEventNotifier() throws Exception {
    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-collector-camel", new RolePrincipal("admin")));

    // add a event handler
    List<Event> received = new ArrayList();
    EventHandler eventHandler = new EventHandler() {
        @Override
        public void handleEvent(Event event) {
            received.add(event);
        }
    };
    Hashtable serviceProperties = new Hashtable();
    serviceProperties.put(EventConstants.EVENT_TOPIC, "decanter/collect/*");
    bundleContext.registerService(EventHandler.class, eventHandler, serviceProperties);

    // create route with notifier
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    DecanterEventNotifier notifier  = new DecanterEventNotifier();
    notifier.setEventAdmin(eventAdmin);

    RouteBuilder builder = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:test").routeId("route-test").to("log:foo");
        }
    };

    DefaultCamelContext camelContext = new DefaultCamelContext();
    camelContext.setName("context-test");
    camelContext.addRoutes(builder);
    camelContext.getManagementStrategy().addEventNotifier(notifier);
    camelContext.start();

    // send a exchange into the route
    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBodyAndHeader("direct:test", "This is a test", "testHeader", "testValue");

    Assert.assertTrue(received.size() >= 5);

    // camel context starting
    Assert.assertEquals("decanter/collect/camel/event", received.get(0).getTopic());
    Assert.assertEquals("root", received.get(0).getProperty("karafName"));
    Assert.assertEquals("org.apache.camel.management.event.CamelContextStartingEvent", received.get(0).getProperty("eventType"));
    Assert.assertEquals("context-test", received.get(0).getProperty("camelContextName"));
    Assert.assertEquals("camelEvent", received.get(0).getProperty("type"));

    // add route
    Assert.assertEquals("decanter/collect/camel/event", received.get(1).getTopic());
    Assert.assertEquals("root", received.get(1).getProperty("karafName"));
    Assert.assertEquals("org.apache.camel.management.event.RouteAddedEvent", received.get(1).getProperty("eventType"));
    Assert.assertEquals("context-test", received.get(1).getProperty("camelContextName"));
    Assert.assertEquals("route-test", received.get(1).getProperty("routeId"));
    Assert.assertEquals("camelEvent", received.get(1).getProperty("type"));

    // route started
    Assert.assertEquals("decanter/collect/camel/event", received.get(2).getTopic());
    Assert.assertEquals("root", received.get(2).getProperty("karafName"));
    Assert.assertEquals("org.apache.camel.management.event.RouteStartedEvent", received.get(2).getProperty("eventType"));
    Assert.assertEquals("context-test", received.get(2).getProperty("camelContextName"));
    Assert.assertEquals("route-test", received.get(2).getProperty("routeId"));
    Assert.assertEquals("camelEvent", received.get(2).getProperty("type"));

    // camel context started
    Assert.assertEquals("decanter/collect/camel/event", received.get(3).getTopic());
    Assert.assertEquals("root", received.get(3).getProperty("karafName"));
    Assert.assertEquals("org.apache.camel.management.event.CamelContextStartedEvent", received.get(3).getProperty("eventType"));
    Assert.assertEquals("context-test", received.get(3).getProperty("camelContextName"));
    Assert.assertEquals("camelEvent", received.get(3).getProperty("type"));

    // exchange sending
    Assert.assertEquals("decanter/collect/camel/event", received.get(4).getTopic());
    Assert.assertEquals("root", received.get(4).getProperty("karafName"));
    Assert.assertEquals("org.apache.camel.management.event.ExchangeSendingEvent", received.get(4).getProperty("eventType"));
    Assert.assertEquals("context-test", received.get(4).getProperty("camelContextName"));
    Assert.assertEquals("direct://test", received.get(4).getProperty("fromEndpointUri"));
    Assert.assertEquals("This is a test", received.get(4).getProperty("inBody"));
    Assert.assertEquals("String", received.get(4).getProperty("inBodyType"));
}
 
Example 9
Source File: CamelAppenderTest.java    From karaf-decanter with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws Exception {
    final List<Exchange> exchanges = new ArrayList<>();
    // create route
    RouteBuilder routeBuilder = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct-vm:decanter").process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    exchanges.add(exchange);
                }
            });
        }
    };
    DefaultCamelContext camelContext = new DefaultCamelContext();
    camelContext.setName("context-test");
    camelContext.addRoutes(routeBuilder);
    camelContext.start();

    Thread.sleep(1000);

    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-appender-camel", new RolePrincipal("admin")));

    Thread.sleep(2000);

    // send event
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    HashMap<String, String> data = new HashMap<>();
    data.put("foo", "bar");
    Event event = new Event("decanter/collect/test", data);
    eventAdmin.sendEvent(event);

    Assert.assertEquals(1, exchanges.size());

    HashMap<String, Object> received = exchanges.get(0).getIn().getBody(HashMap.class);
    Assert.assertEquals("decanter/collect/test", received.get("event.topics"));
    Assert.assertEquals("bar", received.get("foo"));
}