本文整理匯總了Java中org.apache.camel.EndpointInject類的典型用法代碼示例。如果您正苦於以下問題:Java EndpointInject類的具體用法?Java EndpointInject怎麽用?Java EndpointInject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
EndpointInject類屬於org.apache.camel包,在下文中一共展示了EndpointInject類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: shouldDeployDefaultCamelContext
import org.apache.camel.EndpointInject; //導入依賴的package包/類
private boolean shouldDeployDefaultCamelContext(Set<Bean<?>> beans) {
return beans.stream()
// Is there a Camel bean with the @Default qualifier?
// Excluding internal components...
.filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
.filter(hasType(CamelContextAware.class).or(hasType(Component.class))
.or(hasType(RouteContainer.class).or(hasType(RoutesBuilder.class))))
.map(Bean::getQualifiers)
.flatMap(Set::stream)
.filter(isEqual(DEFAULT))
.findAny()
.isPresent()
// Or a bean with Camel annotations?
|| concat(camelBeans.stream().map(AnnotatedType::getFields),
camelBeans.stream().map(AnnotatedType::getMethods))
.flatMap(Set::stream)
.map(Annotated::getAnnotations)
.flatMap(Set::stream)
.filter(isAnnotationType(Consume.class).and(a -> ((Consume) a).context().isEmpty())
.or(isAnnotationType(BeanInject.class).and(a -> ((BeanInject) a).context().isEmpty()))
.or(isAnnotationType(EndpointInject.class).and(a -> ((EndpointInject) a).context().isEmpty()))
.or(isAnnotationType(Produce.class).and(a -> ((Produce) a).context().isEmpty()))
.or(isAnnotationType(PropertyInject.class).and(a -> ((PropertyInject) a).context().isEmpty())))
.findAny()
.isPresent()
// Or an injection point for Camel primitives?
|| beans.stream()
// Excluding internal components...
.filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
.map(Bean::getInjectionPoints)
.flatMap(Set::stream)
.filter(ip -> getRawType(ip.getType()).getName().startsWith("org.apache.camel"))
.map(InjectionPoint::getQualifiers)
.flatMap(Set::stream)
.filter(isAnnotationType(Uri.class).or(isAnnotationType(Mock.class)).or(isEqual(DEFAULT)))
.findAny()
.isPresent();
}
示例2: setterInjection
import org.apache.camel.EndpointInject; //導入依賴的package包/類
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());
}
}
示例3: testEndpointInjectProducerTemplate
import org.apache.camel.EndpointInject; //導入依賴的package包/類
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();
}
示例4: testEndpointInjectProducer
import org.apache.camel.EndpointInject; //導入依賴的package包/類
public void testEndpointInjectProducer() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointBeanProducer bean = new MyEndpointBeanProducer();
Method method = bean.getClass().getMethod("setProducer", Producer.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());
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("Hello World");
bean.send(exchange);
assertMockEndpointsSatisfied();
}
示例5: testEndpointInjectPollingConsumer
import org.apache.camel.EndpointInject; //導入依賴的package包/類
public void testEndpointInjectPollingConsumer() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointBeanPollingConsumer bean = new MyEndpointBeanPollingConsumer();
Method method = bean.getClass().getMethod("setConsumer", PollingConsumer.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);
}
template.sendBody("seda:foo", "Hello World");
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
assertNotNull(bean.getConsumer());
Exchange exchange = bean.consume();
template.send("mock:result", exchange);
assertMockEndpointsSatisfied();
}
示例6: testEndpointInjectProducerTemplateField
import org.apache.camel.EndpointInject; //導入依賴的package包/類
public void testEndpointInjectProducerTemplateField() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointInjectProducerTemplate bean = new MyEndpointInjectProducerTemplate();
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();
}
示例7: testEndpointInjectProducerTemplateFieldNoDefaultEndpoint
import org.apache.camel.EndpointInject; //導入依賴的package包/類
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();
}
示例8: testEndpointInjectProducerTemplateFieldNameUnknown
import org.apache.camel.EndpointInject; //導入依賴的package包/類
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());
}
}
示例9: testEndpointInjectProducerTemplateFieldUrlUnknown
import org.apache.camel.EndpointInject; //導入依賴的package包/類
public void testEndpointInjectProducerTemplateFieldUrlUnknown() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointInjectProducerTemplateUrlUnknown bean = new MyEndpointInjectProducerTemplateUrlUnknown();
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 (ResolveEndpointFailedException e) {
assertEquals("Failed to resolve endpoint: xxx://foo due to: No component found with scheme: xxx", e.getMessage());
}
}
示例10: testEndpointInjectBothUriAndRef
import org.apache.camel.EndpointInject; //導入依賴的package包/類
public void testEndpointInjectBothUriAndRef() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointBothUriAndRef bean = new MyEndpointBothUriAndRef();
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 (IllegalArgumentException e) {
assertEquals("Both uri and name is provided, only either one is allowed: uri=seda:foo, ref=myEndpoint", e.getMessage());
}
}
示例11: setterInjection
import org.apache.camel.EndpointInject; //導入依賴的package包/類
protected void setterInjection(Method method, Object bean, String beanName) {
PropertyInject propertyInject = method.getAnnotation(PropertyInject.class);
if (propertyInject != null && matchContext(propertyInject.context())) {
setterPropertyInjection(method, propertyInject.value(), propertyInject.defaultValue(), bean, beanName);
}
BeanInject beanInject = method.getAnnotation(BeanInject.class);
if (beanInject != null && matchContext(beanInject.context())) {
setterBeanInjection(method, beanInject.value(), bean, beanName);
}
EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
if (endpointInject != null && matchContext(endpointInject.context())) {
setterInjection(method, bean, beanName, endpointInject.uri(), endpointInject.ref(), endpointInject.property());
}
Produce produce = method.getAnnotation(Produce.class);
if (produce != null && matchContext(produce.context())) {
setterInjection(method, bean, beanName, produce.uri(), produce.ref(), produce.property());
}
}
示例12: processAnnotatedType
import org.apache.camel.EndpointInject; //導入依賴的package包/類
private void processAnnotatedType(@Observes ProcessAnnotatedType<?> pat) {
if (pat.getAnnotatedType().isAnnotationPresent(Vetoed.class)) {
pat.veto();
}
if (hasAnnotation(pat.getAnnotatedType(), Converter.class)) {
converters.add(pat.getAnnotatedType().getJavaClass());
}
if (hasAnnotation(pat.getAnnotatedType(), BeanInject.class, Consume.class, EndpointInject.class, Produce.class, PropertyInject.class)) {
camelBeans.add(pat.getAnnotatedType());
}
if (hasAnnotation(pat.getAnnotatedType(), Consume.class)) {
eagerBeans.add(pat.getAnnotatedType());
}
if (hasAnnotation(pat.getAnnotatedType(), ImportResource.class)) {
resources.add(pat.getAnnotatedType().getAnnotation(ImportResource.class));
}
}
示例13: injectFields
import org.apache.camel.EndpointInject; //導入依賴的package包/類
/**
* A strategy method to allow implementations to perform some custom JBI
* based injection of the POJO
*
* @param bean the bean to be injected
*/
protected void injectFields(final Object bean, final String beanName) {
ReflectionHelper.doWithFields(bean.getClass(), new ReflectionHelper.FieldCallback() {
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
PropertyInject propertyInject = field.getAnnotation(PropertyInject.class);
if (propertyInject != null && getPostProcessorHelper().matchContext(propertyInject.context())) {
injectFieldProperty(field, propertyInject.value(), propertyInject.defaultValue(), bean, beanName);
}
BeanInject beanInject = field.getAnnotation(BeanInject.class);
if (beanInject != null && getPostProcessorHelper().matchContext(beanInject.context())) {
injectFieldBean(field, beanInject.value(), bean, beanName);
}
EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
if (endpointInject != null && getPostProcessorHelper().matchContext(endpointInject.context())) {
injectField(field, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), bean, beanName);
}
Produce produce = field.getAnnotation(Produce.class);
if (produce != null && getPostProcessorHelper().matchContext(produce.context())) {
injectField(field, produce.uri(), produce.ref(), produce.property(), bean, beanName);
}
}
});
}
示例14: injectFields
import org.apache.camel.EndpointInject; //導入依賴的package包/類
/**
* A strategy method to allow implementations to perform some custom JBI
* based injection of the POJO
*
* @param bean the bean to be injected
*/
protected void injectFields(final Object bean, final String beanName) {
Class<?> clazz = bean.getClass();
do {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
PropertyInject propertyInject = field.getAnnotation(PropertyInject.class);
if (propertyInject != null && matchContext(propertyInject.context())) {
injectFieldProperty(field, propertyInject.value(), propertyInject.defaultValue(), bean, beanName);
}
BeanInject beanInject = field.getAnnotation(BeanInject.class);
if (beanInject != null && matchContext(beanInject.context())) {
injectFieldBean(field, beanInject.value(), bean, beanName);
}
EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
if (endpointInject != null && matchContext(endpointInject.context())) {
injectField(field, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), bean, beanName);
}
Produce produce = field.getAnnotation(Produce.class);
if (produce != null && matchContext(produce.context())) {
injectField(field, produce.uri(), produce.ref(), produce.property(), bean, beanName);
}
}
clazz = clazz.getSuperclass();
} while (clazz != null && clazz != Object.class);
}
示例15: provide
import org.apache.camel.EndpointInject; //導入依賴的package包/類
public Object provide(EndpointInject inject, TypeLiteral<?> typeLiteral, Field field) {
Class<?> type = field.getType();
String injectionPointName = field.getName();
String uri = inject.uri();
String endpointRef = inject.ref();
String property = inject.property();
return getInjectionValue(type, uri, endpointRef, property, injectionPointName, null, null);
}