public void testMultipleLifecycleStrategies() throws Exception { CamelContext context = createCamelContext(); context.start(); Component log = new LogComponent(); context.addComponent("log", log); context.addEndpoint("log:/foo", log.createEndpoint("log://foo")); context.removeComponent("log"); context.stop(); List<String> expectedEvents = Arrays.asList("onContextStart", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onComponentAdd", "onEndpointAdd", "onComponentRemove", "onContextStop"); assertEquals(expectedEvents, dummy1.getEvents()); assertEquals(expectedEvents, dummy2.getEvents()); }
public static void main(String[] args) throws Exception { SimpleRegistry registry = new SimpleRegistry(); // add POJOs to the registry here using registry.put("name", <object reference>) CamelContext context = new DefaultCamelContext(registry); context.addComponent("mylogger", new LogComponent()); context.addRoutes(new LogMessageOnTimerEventRoute()); context.start(); // let the Camel runtime do its job for 5 seconds Thread.sleep(5000); // shutdown context.stop(); }
@Bean @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(LogComponent.class) public LogComponent configureLogComponent(CamelContext camelContext, LogComponentConfiguration configuration) throws Exception { LogComponent component = new LogComponent(); component.setCamelContext(camelContext); Map<String, Object> parameters = new HashMap<>(); IntrospectionSupport.getProperties(configuration, parameters, null, false); IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters); return component; }
public void testHasComponent() { DefaultCamelContext ctx = new DefaultCamelContext(); ctx.disableJMX(); assertNull(ctx.hasComponent("log")); ctx.addComponent("log", new LogComponent()); assertNotNull(ctx.hasComponent("log")); }
public void testGetComponent() { DefaultCamelContext ctx = new DefaultCamelContext(); ctx.disableJMX(); ctx.addComponent("log", new LogComponent()); LogComponent log = ctx.getComponent("log", LogComponent.class); assertNotNull(log); try { ctx.addComponent("direct", new DirectComponent()); ctx.getComponent("log", DirectComponent.class); fail("Should have thrown exception"); } catch (IllegalArgumentException e) { // expected } }
@Bean(name="log") LogComponent getLogComponent(){ return new LogComponent(); }