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;
}
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\""));
}
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());
}
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);
}
}
Aggregations