Search in sources :

Example 1 with DirectComponent

use of org.apache.camel.component.direct.DirectComponent in project camel by apache.

the class RefComponentTest method bindToRegistry.

private void bindToRegistry(JndiRegistry jndi) throws Exception {
    Component comp = new DirectComponent();
    comp.setCamelContext(context);
    Endpoint slow = comp.createEndpoint("direct:somename");
    Consumer consumer = slow.createConsumer(new Processor() {

        public void process(Exchange exchange) throws Exception {
            template.send("mock:result", exchange);
        }
    });
    consumer.start();
    // bind our endpoint to the registry for ref to lookup
    jndi.bind("foo", slow);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Consumer(org.apache.camel.Consumer) DirectComponent(org.apache.camel.component.direct.DirectComponent) Component(org.apache.camel.Component) DirectComponent(org.apache.camel.component.direct.DirectComponent)

Example 2 with DirectComponent

use of org.apache.camel.component.direct.DirectComponent in project camel by apache.

the class DirectComponentConfigurationAndDocumentationTest method testComponentConfiguration.

@Test
public void testComponentConfiguration() throws Exception {
    DirectComponent comp = context.getComponent("direct", DirectComponent.class);
    EndpointConfiguration conf = comp.createConfiguration("direct:foo?block=true");
    assertEquals("true", conf.getParameter("block"));
    ComponentConfiguration compConf = comp.createComponentConfiguration();
    String json = compConf.createParameterJsonSchema();
    assertNotNull(json);
    assertTrue(json.contains("\"name\": { \"kind\": \"path\", \"displayName\": \"Name\", \"group\": \"common\", \"required\": true, \"type\": \"string\""));
    assertTrue(json.contains("\"timeout\": { \"kind\": \"parameter\", \"displayName\": \"Timeout\", \"group\": \"producer\", \"label\": \"producer\", \"type\": \"integer\""));
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) EndpointConfiguration(org.apache.camel.EndpointConfiguration) DirectComponent(org.apache.camel.component.direct.DirectComponent) Test(org.junit.Test)

Example 3 with DirectComponent

use of org.apache.camel.component.direct.DirectComponent in project camel by apache.

the class DirectComponentAutoConfiguration method configureDirectComponent.

@Lazy
@Bean(name = "direct-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(DirectComponent.class)
public DirectComponent configureDirectComponent(CamelContext camelContext, DirectComponentConfiguration configuration) throws Exception {
    DirectComponent component = new DirectComponent();
    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) DirectComponent(org.apache.camel.component.direct.DirectComponent) 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 4 with DirectComponent

use of org.apache.camel.component.direct.DirectComponent 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)

Aggregations

DirectComponent (org.apache.camel.component.direct.DirectComponent)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Component (org.apache.camel.Component)1 ComponentConfiguration (org.apache.camel.ComponentConfiguration)1 Consumer (org.apache.camel.Consumer)1 Endpoint (org.apache.camel.Endpoint)1 EndpointConfiguration (org.apache.camel.EndpointConfiguration)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 LogComponent (org.apache.camel.component.log.LogComponent)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)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