use of org.apache.camel.component.log.LogComponent in project camel by apache.
the class LogComponentAutoConfiguration method configureLogComponent.
@Lazy
@Bean(name = "log-component")
@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);
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
Object value = entry.getValue();
Class<?> paramClass = value.getClass();
if (paramClass.getName().endsWith("NestedConfiguration")) {
Class nestedClass = null;
try {
nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
HashMap<String, Object> nestedParameters = new HashMap<>();
IntrospectionSupport.getProperties(value, nestedParameters, null, false);
Object nestedProperty = nestedClass.newInstance();
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
entry.setValue(nestedProperty);
} catch (NoSuchFieldException e) {
}
}
}
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
return component;
}
use of org.apache.camel.component.log.LogComponent in project camel by apache.
the class LogComponentConfigurationAndDocumentationTest method testComponentConfiguration.
@Test
public void testComponentConfiguration() throws Exception {
LogComponent comp = context.getComponent("log", LogComponent.class);
EndpointConfiguration conf = comp.createConfiguration("log:foo?level=DEBUG");
assertEquals("DEBUG", conf.getParameter("level"));
ComponentConfiguration compConf = comp.createComponentConfiguration();
String json = compConf.createParameterJsonSchema();
assertNotNull(json);
assertTrue(json.contains("\"loggerName\": { \"kind\": \"path\", \"displayName\": \"Logger Name\", \"group\": \"producer\", \"required\": true"));
assertTrue(json.contains("\"level\": { \"kind\": \"parameter\", \"displayName\": \"Level\", \"group\": \"producer\", \"type\": \"string\""));
assertTrue(json.contains("\"showBody\": { \"kind\": \"parameter\", \"displayName\": \"Show Body\", \"group\": \"formatting\", \"label\": \"formatting\""));
}
use of org.apache.camel.component.log.LogComponent in project camel by apache.
the class MultipleLifecycleStrategyTest method testMultipleLifecycleStrategies.
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", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onComponentAdd", "onEndpointAdd", "onComponentRemove", "onContextStop");
assertEquals(expectedEvents, dummy1.getEvents());
assertEquals(expectedEvents, dummy2.getEvents());
}
use of org.apache.camel.component.log.LogComponent in project camel by apache.
the class DefaultCamelContextTest method testGetComponent.
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
}
}
use of org.apache.camel.component.log.LogComponent in project camel by apache.
the class DefaultCamelContextTest method testHasComponent.
public void testHasComponent() {
DefaultCamelContext ctx = new DefaultCamelContext();
ctx.disableJMX();
assertNull(ctx.hasComponent("log"));
ctx.addComponent("log", new LogComponent());
assertNotNull(ctx.hasComponent("log"));
}
Aggregations