Search in sources :

Example 1 with SedaComponent

use of org.apache.camel.component.seda.SedaComponent in project camel by apache.

the class SedaComponentAutoConfiguration method configureSedaComponent.

@Lazy
@Bean(name = "seda-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(SedaComponent.class)
public SedaComponent configureSedaComponent(CamelContext camelContext, SedaComponentConfiguration configuration) throws Exception {
    SedaComponent component = new SedaComponent();
    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 : SedaComponent(org.apache.camel.component.seda.SedaComponent) HashMap(java.util.HashMap) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) 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 SedaComponent

use of org.apache.camel.component.seda.SedaComponent in project camel by apache.

the class SedaComponentConfigurationAndDocumentationTest method testComponentConfiguration.

@Test
public void testComponentConfiguration() throws Exception {
    SedaComponent comp = context.getComponent("seda", SedaComponent.class);
    EndpointConfiguration conf = comp.createConfiguration("seda:foo?blockWhenFull=true");
    assertEquals("true", conf.getParameter("blockWhenFull"));
    ComponentConfiguration compConf = comp.createComponentConfiguration();
    String json = compConf.createParameterJsonSchema();
    assertNotNull(json);
    assertTrue(json.contains("\"concurrentConsumers\": { \"kind\": \"parameter\", \"displayName\": \"Concurrent Consumers\", \"group\": \"consumer\", \"label\": \"consumer\""));
    assertTrue(json.contains("\"timeout\": { \"kind\": \"parameter\", \"displayName\": \"Timeout\", \"group\": \"producer\", \"label\": \"producer\""));
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) SedaComponent(org.apache.camel.component.seda.SedaComponent) EndpointConfiguration(org.apache.camel.EndpointConfiguration) Test(org.junit.Test)

Example 3 with SedaComponent

use of org.apache.camel.component.seda.SedaComponent in project camel by apache.

the class ComponentResolvePropertyPlaceholdersTest method testPropertiesComponentEndpoint.

public void testPropertiesComponentEndpoint() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            SedaComponent seda = new SedaComponent();
            seda.setQueueSize(propertyInject("myQueueSize", int.class));
            context.addComponent("seda", seda);
            from("seda:start").to("mock:{{cool.result}}");
        }
    });
    context.start();
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("seda:start", "Hello World");
    assertMockEndpointsSatisfied();
    SedaComponent seda = context.getComponent("seda", SedaComponent.class);
    assertNotNull(seda);
    assertEquals(10, seda.getQueueSize());
}
Also used : SedaComponent(org.apache.camel.component.seda.SedaComponent) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 4 with SedaComponent

use of org.apache.camel.component.seda.SedaComponent in project camel by apache.

the class ComponentConfigurationTest method testConfigureAnExistingSedaEndpoint.

/**
     * Shows how we can use the configuration to get and set parameters directly on the endpoint
     * for a {@link UriEndpointComponent}
     */
@Test
public void testConfigureAnExistingSedaEndpoint() throws Exception {
    SedaEndpoint endpoint = context.getEndpoint("seda:cheese?concurrentConsumers=5", SedaEndpoint.class);
    SedaComponent component = endpoint.getComponent();
    ComponentConfiguration configuration = component.createComponentConfiguration();
    assertEquals("concurrentConsumers", 5, endpoint.getConcurrentConsumers());
    assertEquals("concurrentConsumers", 5, configuration.getEndpointParameter(endpoint, "concurrentConsumers"));
    // lets try set and get some valid parameters
    configuration.setEndpointParameter(endpoint, "concurrentConsumers", 10);
    Object concurrentConsumers = configuration.getEndpointParameter(endpoint, "concurrentConsumers");
    assertEquals("endpoint.concurrentConsumers", 10, concurrentConsumers);
    configuration.setEndpointParameter(endpoint, "size", 1000);
    Object size = configuration.getEndpointParameter(endpoint, "size");
    assertEquals("endpoint.size", 1000, size);
    // lets try set an invalid parameter
    try {
        configuration.setEndpointParameter(endpoint, "doesNotExist", 1000);
        fail("Should have got InvalidPropertyException thrown!");
    } catch (InvalidPropertyException e) {
        LOG.info("Got expected exception: " + e);
    }
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) SedaComponent(org.apache.camel.component.seda.SedaComponent) SedaEndpoint(org.apache.camel.component.seda.SedaEndpoint) InvalidPropertyException(org.apache.camel.InvalidPropertyException) Test(org.junit.Test)

Aggregations

SedaComponent (org.apache.camel.component.seda.SedaComponent)4 ComponentConfiguration (org.apache.camel.ComponentConfiguration)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 EndpointConfiguration (org.apache.camel.EndpointConfiguration)1 InvalidPropertyException (org.apache.camel.InvalidPropertyException)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 SedaEndpoint (org.apache.camel.component.seda.SedaEndpoint)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