/** * A spring based REST service using {@link RestController}. */ @RestController public class GeoRestController { @EndpointInject(uri = "log:foo") // TODO: fix me in future Camel release private FluentProducerTemplate template; @RequestMapping("/country/{city}") public Object address(@PathVariable(name = "city") String city) { // use Camel's geocoder to get location about the city return template.to("geocoder:address:" + city).request(); } }
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()); } }
.anyMatch(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())))
/** * Camel routes */ @Singleton public class HelloRoute extends RouteBuilder { // we can inject Camel endpoints (or also just use the uris directly in the Java DSL below) @EndpointInject(uri = "timer:foo?period=5s") private Endpoint input; @EndpointInject(uri = "log:output") private Endpoint output; @Override public void configure() throws Exception { from(input) // lookup bean with name helloBean .bean("helloBean") .to(output); } }
if (endpointInject != null) { try { injectField(field, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), endpointInject.context(), bean, beanName); } catch (Exception cause) { throw new InjectionException("Injection of [" + endpointInject + "] for field [" + field + "] failed!", cause);
@EndpointInject(ref = "fileEndpoint") private Endpoint file; @EndpointInject(ref = "httpEndpoint") private Endpoint http; @EndpointInject(ref = "ftpEndpoint") private Endpoint ftp;
@EndpointInject(ref = "fileEndpoint") private Endpoint file; @EndpointInject(ref = "httpEndpoint") private Endpoint http; @EndpointInject(ref = "ftpEndpoint") private Endpoint ftp;
@EndpointInject ProducerTemplate producer;
@EndpointInject(uri = "direct:sendMessage", context = "sinkClient") private ProducerTemplate template; @EndpointInject(uri = "direct:sendMessage", context = "sinkClient") private Endpoint endpoint;
@EndpointInject(uri = "direct:executeRpc", context = "rpcClient") private ProducerTemplate template; @EndpointInject(uri = "direct:executeRpc", context = "rpcClient") private Endpoint endpoint;
@EndpointInject(uri = "direct:executeRpc", context = "rpcClient") private ProducerTemplate template; @EndpointInject(uri = "direct:executeRpc", context = "rpcClient") private Endpoint endpoint;
/** * Spring REST endpoint */ @RestController @RequestMapping("/spring") public class HelloRestController { /** * Inject Camel producer to use camel-geocoder to find location where we are */ @EndpointInject(uri = "geocoder:address:current") private FluentProducerTemplate producer; /** * HTTP GET method */ @RequestMapping(method = RequestMethod.GET, value = "/hello", produces = "text/plain") public String hello() { // call Camel to find our location, the returned string is in JSon format String where = producer.request(String.class); return "Hello from Spring Boot and Camel. We are at: " + where; } }
public class SplitInlineTest extends SyndesisTestSupport { public static final String START_URI = "direct:start"; public static final String RESULTS_URI = "mock:results"; @EndpointInject(uri = RESULTS_URI) protected MockEndpoint resultsEndpoint; @Test public void testStep() throws Exception { resultsEndpoint.expectedBodiesReceived("a","b","c"); template.sendBody(START_URI, "a,b,c"); MockEndpoint.assertIsSatisfied(resultsEndpoint); logMessagesReceived(resultsEndpoint); } @Override protected void addSyndesisFlows(SyndesisModel syndesis) { syndesis.createFlow() .endpoint(START_URI) .splitInline("tokenize", ",") .endpoint(RESULTS_URI); } }
public static final String RESULTS_URI = "mock:results"; @EndpointInject(uri = RESULTS_URI) protected MockEndpoint resultsEndpoint;
public static final String RESULTS_URI = "mock:results"; @EndpointInject(uri = RESULTS_URI) protected MockEndpoint resultsEndpoint;
public static final String RESULTS_URI = "mock:results"; @EndpointInject(uri = RESULTS_URI) protected MockEndpoint resultsEndpoint;
public static final String ALL_MESSAGES_URI = "mock:allMessages"; @EndpointInject(uri = MATCHED_URI) protected MockEndpoint matchedEndpoint; @EndpointInject(uri = ALL_MESSAGES_URI) protected MockEndpoint allMessagesEndpoint;
@EndpointInject(uri = RESULTS_URI) protected MockEndpoint resultEndpoint;
@EndpointInject(uri = RESULTS_URI) protected MockEndpoint resultEndpoint;