public static RoutesBuilder mapBeanRoutes(ServiceRepository serviceRepository, Service service) { return new RouteBuilder() { @Override public void configure() throws Exception { List<Method> methods = javaslang.collection.List.of(service.getConfiguration().getServiceClass().getDeclaredMethods()); // create an instance of the bean Object beanToUse = service.getConfiguration().getTargetBean(); for (Method m : methods) { if (Modifier.isPublic(m.getModifiers())) { from("direct:" + formatBeanMethodRoute(m)) .bean(beanToUse, formatBeanEndpointRoute(m), true); } } } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from(MILO_SERVER_ITEM_1).to(MOCK_TEST_1); from(MILO_SERVER_ITEM_2).to(MOCK_TEST_2); from(DIRECT_START_1).to(MILO_CLIENT_ITEM_C1_1); from(DIRECT_START_2).to(MILO_CLIENT_ITEM_C1_2); from(DIRECT_START_3).to(MILO_CLIENT_ITEM_C2_1); from(DIRECT_START_4).to(MILO_CLIENT_ITEM_C2_2); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { initProperties(); from("direct:download-sent") .to("isds:download?username={{isds.fo.login}}&password={{isds.fo.password}}&environment=test") .log("done"); from("direct:download-received") .to("isds:download?username={{isds.ovm.login}}&password={{isds.ovm.password}}" + "&environment=test&downloadListMessages=true") .log("done"); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { initProperties(); return new RouteBuilder() { @Override public void configure() throws Exception { from("isds:messages?environment=test&username={{isds.ovm.login}}" + "&password={{isds.ovm.password}}" + "&consumer.delay=1s" + "&filter=!read") .id(ROUTE_ID) .autoStartup(false) .log("new message in OVM inbox - id ${body.envelope.messageID}") .to(mockEndpoint.getEndpointUri()); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { final Funktion funktion = createFunktion(); if (isDumpFlowYAML()) { String fileNamePrefix = "target/funktion-tests/" + getClassNameAsPath() + "-" + getTestMethodName(); File file = new File(getBaseDir(), fileNamePrefix + ".yml"); file.getParentFile().mkdirs(); Funktions.saveConfig(funktion, file); Funktions.saveConfigJSON(funktion, new File(getBaseDir(), fileNamePrefix + ".json")); } return new FunktionRouteBuilder() { @Override protected Funktion loadFunktion() throws IOException { return funktion; } }; }
/** * Appends all the {@link org.apache.camel.builder.RouteBuilder} instances that can be found in the context */ public void appendBuilders(List<RoutesBuilder> list) { Map<String, RoutesBuilder> beans = applicationContext.getBeansOfType(RoutesBuilder.class, includeNonSingletons, true); for (Entry<String, RoutesBuilder> entry : beans.entrySet()) { Object bean = entry.getValue(); Object key = entry.getKey(); LOG.trace("Found RouteBuilder with id: {} -> {}", key, bean); // certain beans should be ignored if (shouldIgnoreBean(bean)) { LOG.debug("Ignoring RouteBuilder id: {}", key); continue; } if (!isFilteredClass(bean)) { LOG.debug("Ignoring filtered RouteBuilder id: {} as class: {}", key, bean.getClass()); continue; } LOG.debug("Adding instantiated RouteBuilder id: {} as class: {}", key, bean.getClass()); list.add((RoutesBuilder) bean); } }
private RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from("jetty:" + serviceEndpoint + "?matchOnUriPrefix=true&optionsEnabled=true") .routeId(SERVICE_ROUTE_ID) .process(ex -> { requestToService.copyFrom(ex.getIn()); if (processFromTest != null) { processFromTest.process(ex); } else { ex.getOut().copyFrom(responseFromService); } }); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { errorHandler(deadLetterChannel("mock:dead")); from("seda:start") // the FTP server is not running and therefore we should get an exception // and use 60s timeout // and turn on aggregation on exception as we have turned on bridge error handler, // so we want to run out custom aggregation strategy for exceptions as well .pollEnrich(uri, 60000, new MyAggregationStrategy(), true) .to("mock:result"); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("seda:a").routeId("start"); from("seda:a").routeId("a") .log("routing at ${routeId}") .recipientList(constant("seda:b,seda:c")) .log("End of routing"); from("seda:b").routeId("b") .log("routing at ${routeId}") .delay(simple("${random(1000,2000)}")); from("seda:c").routeId("c") .log("routing at ${routeId}") .delay(simple("${random(0,100)}")); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("seda:a").routeId("start"); from("seda:a").routeId("a") .log("routing at ${routeId}") .multicast() .to("seda:b") .to("seda:c") .end() .log("End of routing"); from("seda:b").routeId("b") .log("routing at ${routeId}") .delay(simple("${random(1000,2000)}")); from("seda:c").routeId("c") .log("routing at ${routeId}") .delay(simple("${random(0,100)}")); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from("seda:foo?concurrentConsumers=5").routeId("foo") .log("routing at ${routeId}") .delay(simple("${random(1000,2000)}")) .to("seda:bar"); from("seda:bar?concurrentConsumers=5").routeId("bar") .log("routing at ${routeId}") .delay(simple("${random(0,500)}")); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("seda:cat"); from("seda:cat").routeId("cat") .log("routing at ${routeId}") .delay(simple("${random(1000,2000)}")) .setBody().constant("Cat says hello Dog") .to("seda:dog"); from("seda:dog").routeId("dog") .log("routing at ${routeId}") .delay(simple("${random(0,500)}")) .setBody().constant("Dog say hello Cat and Camel"); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("seda:a").routeId("start"); from("seda:a").routeId("a") .log("routing at ${routeId}") .to("seda:b") .delay(2000) .to("seda:c") .log("End of routing"); from("seda:b").routeId("b") .log("routing at ${routeId}") .delay(simple("${random(1000,2000)}")); from("seda:c").routeId("c") .log("routing at ${routeId}") .delay(simple("${random(0,100)}")); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").recipientList(constant("seda:a,seda:b,seda:c")).routeId("start"); from("seda:a").routeId("a") .log("routing at ${routeId}"); from("seda:b").routeId("b") .log("routing at ${routeId}") .delay(simple("${random(1000,2000)}")); from("seda:c").routeId("c") .log("routing at ${routeId}") .delay(simple("${random(0,100)}")); } }; }
/** * Appends all the {@link org.apache.camel.builder.RouteBuilder} instances that can be found on the classpath */ public void appendBuilders(List<RoutesBuilder> list) throws IllegalAccessException, InstantiationException { Set<Class<?>> classes = resolver.findImplementations(RoutesBuilder.class, packages); for (Class<?> aClass : classes) { LOG.trace("Found RouteBuilder class: {}", aClass); // certain beans should be ignored if (shouldIgnoreBean(aClass)) { LOG.debug("Ignoring RouteBuilder class: {}", aClass); continue; } if (!isValidClass(aClass)) { LOG.debug("Ignoring invalid RouteBuilder class: {}", aClass); continue; } // type is valid so create and instantiate the builder RoutesBuilder builder = instantiateBuilder(aClass); LOG.debug("Adding instantiated RouteBuilder: {}", builder); list.add(builder); } }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .serviceCall() .name(SERVICE_NAME) .etcdConfiguration() .component("http") .loadBalancer("roundrobin") .serverListStrategy("ondemand") .end() .to("log:org.apache.camel.component.etcd.processor.service?level=INFO&showAll=true&multiline=true") .to("mock:result"); servers.forEach(s -> fromF("jetty:http://%s:%d", s.get("address"), s.get("port")) .transform().simple("${in.body} on " + s.get("port")) ); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { LOGGER.debug("Creating new test route"); from(PRODUCER_URI + "?listOnJoin=true&onReply=true") .choice() .when(header("irc.messageType").isEqualToIgnoreCase("REPLY")) .filter(header("irc.num").isEqualTo(IRC_RPL_NAMREPLY)) .to("mock:result").stop(); } }; }
protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() { LZFDataFormat dataFormat = new LZFDataFormat(); dataFormat.setUsingParallelCompression(true); from("direct:textToLzf") .marshal().lzf(); from("direct:unMarshalTextToLzf") .marshal().lzf() .unmarshal().lzf() .to("mock:unMarshalTextToLzf"); from("direct:parallelUnMarshalTextToLzf") .marshal(dataFormat) .unmarshal(dataFormat) .to("mock:parallelUnMarshalTextToLzf"); } }; }
protected void setupCamelContext(final BundleContext bundleContext, final String camelContextId) throws Exception { // Set up CamelContext if (camelContextId != null) { context.setNameStrategy(new ExplicitCamelContextNameStrategy(camelContextId)); } // TODO: allow to configure these options and not hardcode context.setUseMDCLogging(true); context.setUseBreadcrumb(true); // Add routes for (RoutesBuilder route : getRouteBuilders()) { context.addRoutes(configure(context, route, log)); } // ensure we publish this CamelContext to the OSGi service registry context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundleContext)); }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from(ENDPOINT_DIRECT) .routeId("AggregatingRouteOne") .aggregate(header(CORRELATOR)) .aggregationRepository(createAggregateRepository()) .aggregationStrategy(EhcacheAggregationRepositoryRoutesTest.this::aggregate) .completionSize(VALUES.length) .to("log:org.apache.camel.component.ehcache.processor.aggregate?level=INFO&showAll=true&multiline=true") .to(ENDPOINT_MOCK); } }; }
/** * Appends all the {@link org.apache.camel.builder.RouteBuilder} bean instances that can be found in the manager. */ void appendBuilders(List<RoutesBuilder> list) { for (Bean<?> bean : manager.getBeans(RoutesBuilder.class, ANY)) { logger.trace("Found RouteBuilder bean {}", bean); // certain beans should be ignored if (shouldIgnoreBean(bean)) { logger.debug("Ignoring RouteBuilder {}", bean); continue; } if (!isFilteredClass(bean)) { logger.debug("Ignoring filtered RouteBuilder {}", bean); continue; } logger.debug("Adding instantiated RouteBuilder {}", bean); Object instance = manager.getReference(bean, RoutesBuilder.class, manager.createCreationalContext(bean)); list.add((RoutesBuilder) instance); } }
/** * Appends all the {@link org.apache.camel.builder.RouteBuilder} instances that can be found on the classpath */ void appendBuilders(List<RoutesBuilder> list) throws IllegalAccessException, InstantiationException { Set<Class<?>> classes = resolver.findImplementations(RoutesBuilder.class, packages); for (Class<?> aClass : classes) { logger.trace("Found RouteBuilder class: {}", aClass); // certain beans should be ignored if (shouldIgnoreBean(aClass)) { logger.debug("Ignoring RouteBuilder class: {}", aClass); continue; } if (!isValidClass(aClass)) { logger.debug("Ignoring invalid RouteBuilder class: {}", aClass); continue; } // type is valid so create and instantiate the builder @SuppressWarnings("unchecked") RoutesBuilder builder = instantiateBuilder((Class<? extends RoutesBuilder>) aClass); logger.debug("Adding instantiated RouteBuilder: {}", builder); list.add(builder); } }
private boolean addRouteToContext(Bean<?> routeBean, Bean<?> contextBean, BeanManager manager, AfterDeploymentValidation adv) { try { CamelContext context = getReference(manager, CamelContext.class, contextBean); try { Object route = getReference(manager, Object.class, routeBean); if (route instanceof RoutesBuilder) { context.addRoutes((RoutesBuilder) route); } else if (route instanceof RouteContainer) { context.addRouteDefinitions(((RouteContainer) route).getRoutes()); } else { throw new IllegalArgumentException( "Invalid routes type [" + routeBean.getBeanClass().getName() + "], " + "must be either of type RoutesBuilder or RouteContainer!"); } return true; } catch (Exception cause) { adv.addDeploymentProblem( new InjectionException( "Error adding routes of type [" + routeBean.getBeanClass().getName() + "] " + "to Camel context [" + context.getName() + "]", cause)); } } catch (Exception exception) { adv.addDeploymentProblem(exception); } return false; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { ZipFileDataFormat zf = new ZipFileDataFormat(); zf.setUsingIterator(true); from("file://target/zip-unmarshal?noop=true&include=.*zip") .to("mock:input") .unmarshal(zf) .split(bodyAs(Iterator.class)).streaming() .convertBodyTo(String.class) .to("mock:end") .end(); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .serviceCall().name("myService") // lets update quick so we do not have to sleep so much in the tests .ribbonConfiguration().serverListStrategy(servers).clientProperty("ServerListRefreshInterval", "250").end() .to("mock:result"); from("jetty:http://localhost:9090").routeId("9090") .to("mock:9090") .transform().constant("9090"); from("jetty:http://localhost:9091").routeId("9091") .to("mock:9091") .transform().constant("9091"); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { // setup a static ribbon server list with these 2 servers to start with RibbonServiceCallStaticServerListStrategy servers = new RibbonServiceCallStaticServerListStrategy(); servers.addServer("localhost", 9090); servers.addServer("localhost", 9091); from("direct:start") .serviceCall().name("myService").ribbonConfiguration().serverListStrategy(servers).end() .to("mock:result"); from("jetty:http://localhost:9090") .to("mock:9090") .transform().constant("9090"); from("jetty:http://localhost:9091") .to("mock:9091") .transform().constant("9091"); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { KubernetesConfigurationDefinition config = new KubernetesConfigurationDefinition(); config.setLookup("environment"); // register configuration context.setServiceCallConfiguration(config); from("direct:start") .serviceCall("cdi-camel-jetty") .serviceCall("cdi-camel-jetty") .to("mock:result"); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { KubernetesConfigurationDefinition config = new KubernetesConfigurationDefinition(); config.setMasterUrl("http://172.28.128.80:8080"); config.setUsername("admin"); config.setPassword("admin"); config.setNamespace("default"); config.setLookup("client"); // lets use the built-in round robin (random is default) config.setLoadBalancerRef("roundrobin"); // register configuration context.setServiceCallConfiguration(config); from("direct:start") .serviceCall("cdi-camel-jetty") .serviceCall("cdi-camel-jetty") .to("mock:result"); } }; }
public static RoutesBuilder mapCronRoutes(String groupName, DrinkWaterApplication app, Service service) { return new RouteBuilder() { @Override public void configure() throws Exception { boolean jobActive = service.safeLookupProperty(Boolean.class, "job.activated", true); if (jobActive) { Object bean = BeanFactory.createBean(app, service.getConfiguration(), service); String cronExpression = service.getConfiguration().getCronExpression(); long interval = service.getConfiguration().getRepeatInterval(); cronExpression = service.lookupProperty(service.getConfiguration().getCronExpression() + ":" + cronExpression); interval = service.safeLookupProperty(Long.class, "job.interval", interval); String enpoint = "quartz2://" + groupName + "/" + service.getConfiguration().getServiceName() + "?fireNow=true"; if (cronExpression == null) { cronExpression = cronExpression.replaceAll(" ", "+"); enpoint += "&cron=" + cronExpression; } else { enpoint += "&trigger.repeatInterval=" + interval; } //camel needs + instead of white space //TODO : check correctness of expression see camel doc here the job must have only one method !!!! from(enpoint).bean(bean); } } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new SyndesisRouteBuilder("") { @Override protected SyndesisModel loadModel() throws Exception { return createSyndesis(); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { from("direct:start") .to("sql-stored-connector:DEMO_ADD( INTEGER ${body[a]}, INTEGER ${body[b]}, OUT INTEGER c)"); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { from("sql-stored-start-connector:DEMO_OUT( OUT INTEGER c)") .to("mock:result"); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() { from("direct:start") .to("my-bean-proxy") .to("mock:result"); } }; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { final String path = getClass().getSimpleName() + ".yaml"; final RoutesBuilder builder = new SyndesisRouteBuilder("classpath:" + path); return builder; }
@Override protected RoutesBuilder createRouteBuilder() throws Exception { final String path = getClass().getSimpleName() + "-" + getTestMethodName() + ".yaml"; final RoutesBuilder builder = new SyndesisRouteBuilder("classpath:" + path); return builder; }