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