use of org.apache.camel.EndpointInject in project camel by apache.
the class DefaultCamelBeanPostProcessor method setterInjection.
protected void setterInjection(Method method, Object bean, String beanName) {
PropertyInject propertyInject = method.getAnnotation(PropertyInject.class);
if (propertyInject != null && getPostProcessorHelper().matchContext(propertyInject.context())) {
setterPropertyInjection(method, propertyInject.value(), propertyInject.defaultValue(), bean, beanName);
}
BeanInject beanInject = method.getAnnotation(BeanInject.class);
if (beanInject != null && getPostProcessorHelper().matchContext(beanInject.context())) {
setterBeanInjection(method, beanInject.value(), bean, beanName);
}
EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
if (endpointInject != null && getPostProcessorHelper().matchContext(endpointInject.context())) {
setterInjection(method, bean, beanName, endpointInject.uri(), endpointInject.ref(), endpointInject.property());
}
Produce produce = method.getAnnotation(Produce.class);
if (produce != null && getPostProcessorHelper().matchContext(produce.context())) {
setterInjection(method, bean, beanName, produce.uri(), produce.ref(), produce.property());
}
}
use of org.apache.camel.EndpointInject in project camel by apache.
the class CamelPostProcessorHelperTest method testEndpointInjectProducerTemplateFieldNameUnknown.
public void testEndpointInjectProducerTemplateFieldNameUnknown() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointInjectProducerTemplateNameUnknown bean = new MyEndpointInjectProducerTemplateNameUnknown();
Field field = bean.getClass().getField("producer");
EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
Class<?> type = field.getType();
String propertyName = "producer";
try {
helper.getInjectionValue(type, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), propertyName, bean, "foo");
fail("Should throw exception");
} catch (NoSuchBeanException e) {
assertEquals("No bean could be found in the registry for: unknown of type: org.apache.camel.Endpoint", e.getMessage());
}
}
use of org.apache.camel.EndpointInject in project camel by apache.
the class CamelPostProcessorHelperTest method testEndpointInjectProducerTemplateFieldNoDefaultEndpoint.
public void testEndpointInjectProducerTemplateFieldNoDefaultEndpoint() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointInjectProducerTemplateNoDefaultEndpoint bean = new MyEndpointInjectProducerTemplateNoDefaultEndpoint();
Field field = bean.getClass().getField("producer");
EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
Class<?> type = field.getType();
String propertyName = "producer";
Object value = helper.getInjectionValue(type, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), propertyName, bean, "foo");
field.set(bean, value);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("Hello World");
bean.send(exchange);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.EndpointInject in project camel by apache.
the class CamelPostProcessorHelperTest method testEndpointInjectProducerTemplate.
public void testEndpointInjectProducerTemplate() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointInjectBeanProducerTemplate bean = new MyEndpointInjectBeanProducerTemplate();
Method method = bean.getClass().getMethod("setProducer", ProducerTemplate.class);
EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
Class<?>[] parameterTypes = method.getParameterTypes();
for (Class<?> type : parameterTypes) {
String propertyName = ObjectHelper.getPropertyName(method);
Object value = helper.getInjectionValue(type, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), propertyName, bean, "foo");
ObjectHelper.invokeMethod(method, bean, value);
}
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
assertNotNull(bean.getProducer());
bean.send("Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.EndpointInject in project camel by apache.
the class CamelPostProcessorHelperTest method testEndpointInjectFluentProducerTemplateField.
public void testEndpointInjectFluentProducerTemplateField() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointInjectFluentProducerTemplate bean = new MyEndpointInjectFluentProducerTemplate();
Field field = bean.getClass().getField("producer");
EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
Class<?> type = field.getType();
String propertyName = "producer";
Object value = helper.getInjectionValue(type, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), propertyName, bean, "foo");
field.set(bean, value);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("Hello World");
bean.send(exchange);
assertMockEndpointsSatisfied();
}
Aggregations