Search in sources :

Example 1 with LogComponent

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;
}
Also used : HashMap(java.util.HashMap) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) LogComponent(org.apache.camel.component.log.LogComponent) HashMap(java.util.HashMap) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with LogComponent

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\""));
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) EndpointConfiguration(org.apache.camel.EndpointConfiguration) LogComponent(org.apache.camel.component.log.LogComponent) Test(org.junit.Test)

Example 3 with LogComponent

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());
}
Also used : CamelContext(org.apache.camel.CamelContext) LogComponent(org.apache.camel.component.log.LogComponent) Component(org.apache.camel.Component) LogComponent(org.apache.camel.component.log.LogComponent)

Example 4 with LogComponent

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
    }
}
Also used : DirectComponent(org.apache.camel.component.direct.DirectComponent) LogComponent(org.apache.camel.component.log.LogComponent)

Example 5 with LogComponent

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"));
}
Also used : LogComponent(org.apache.camel.component.log.LogComponent)

Aggregations

LogComponent (org.apache.camel.component.log.LogComponent)5 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CamelContext (org.apache.camel.CamelContext)1 Component (org.apache.camel.Component)1 ComponentConfiguration (org.apache.camel.ComponentConfiguration)1 EndpointConfiguration (org.apache.camel.EndpointConfiguration)1 DirectComponent (org.apache.camel.component.direct.DirectComponent)1 Test (org.junit.Test)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 Lazy (org.springframework.context.annotation.Lazy)1