/** * Camel routes that uses undertow to expose a HTTP service */ @Singleton public class HelloRoute extends RouteBuilder { @Inject @Uri("undertow:http://0.0.0.0:8080/") private Endpoint undertow; @Inject private HelloBean hello; @Override public void configure() throws Exception { from(undertow).bean(hello); } }
/** * Camel routes that uses undertow to expose a HTTP service */ @Singleton public class HelloRoute extends RouteBuilder { @Inject @Uri("undertow:http://0.0.0.0:8080/") private Endpoint undertow; @Inject private HelloBean hello; @Override public void configure() throws Exception { from(undertow).bean(hello); } }
/** * A basic route that exposes a HTTP service. * This route uses CDI dependency injection. */ @Singleton public class HelloRoute extends RouteBuilder { // use CDI @Inject to inject the bean of type HelloBean @Inject private HelloBean hello; // use camel-cdi @Uri to inject the endpoint @Inject @Uri("jetty:http://localhost:8080/hello") private Endpoint jetty; @Override public void configure() throws Exception { from(jetty) // call the sayHello method on the hello bean .bean(hello, "sayHello"); } }
/** * A basic route that exposes a HTTP service. * This route uses CDI dependency injection. */ @Singleton public class HelloRoute extends RouteBuilder { // use CDI @Inject to inject the bean of type HelloBean @Inject private HelloBean hello; // use camel-cdi @Uri to inject the endpoint // use undertow as HTTP server as WildFly Swarm comes out of the box with Undertow @Inject @Uri("undertow:http://localhost:8080/hello") private Endpoint undertow; @Override public void configure() throws Exception { from(undertow) // call the sayHello method on the hello bean .bean(hello, "sayHello"); } }
/** * Configures all our Camel routes, components, endpoints and beans */ @ContextName("myCdiRestCamelContext") public class MyRoutes extends RouteBuilder { @Inject @Uri("timer:foo?period=5000") private Endpoint inputEndpoint; @Inject @Uri("http:{{service:QUICKSTART_REST:localhost:8080}}/cxf/customerservice/customers/123") private Endpoint restEndpoint; @Inject @Uri("log:output?showExchangePattern=false&showBodyType=false&showStreams=true") private Endpoint resultEndpoint; @Override public void configure() throws Exception { // you can configure the route rule with Java DSL here from(inputEndpoint) .to(restEndpoint) .to(resultEndpoint); } }
@Produces @Default @Uri("") // Qualifiers are dynamically added in CdiCamelExtension private static FluentProducerTemplate fluentProducerTemplate(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) { return getQualifierByType(ip, Uri.class) .map(uri -> fluentProducerTemplateFromUri(ip, instance, extension, uri)) .orElseGet(() -> defaultFluentProducerTemplate(ip, instance, extension)); }
@Produces @Default @Uri("") // Qualifiers are dynamically added in CdiCamelExtension private static ProducerTemplate producerTemplate(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) { return getQualifierByType(ip, Uri.class) .map(uri -> producerTemplateFromUri(ip, instance, extension, uri)) .orElseGet(() -> defaultProducerTemplate(ip, instance, extension)); }
@Uri("jms:topic:helloServiceQueueOut") private ProducerTemplate producer;
@Uri("direct:continue") @ContextName("simple") private Endpoint directEP;
@Uri("") @Produces // Qualifiers are dynamically added in CdiCamelExtension private static Endpoint endpoint(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) { Uri uri = getQualifierByType(ip, Uri.class).get(); try { CamelContext context = uri.context().isEmpty() ? selectContext(ip, instance, extension) : selectContext(uri.context(), instance); return context.getEndpoint(uri.value(), Endpoint.class); } catch (Exception cause) { throw new InjectionException("Error injecting endpoint annotated with " + uri + " into " + ip, cause); } }
@Uri("") @Produces @Typed(MockEndpoint.class) // Qualifiers are dynamically added in CdiCamelExtension private static MockEndpoint mockEndpointFromUri(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) { Uri uri = getQualifierByType(ip, Uri.class).get(); try { CamelContext context = uri.context().isEmpty() ? selectContext(ip, instance, extension) : selectContext(uri.context(), instance); return context.getEndpoint(uri.value(), MockEndpoint.class); } catch (Exception cause) { throw new InjectionException("Error injecting mock endpoint annotated with " + uri + " into " + ip, cause); } }