@Override public void configure() throws Exception { LOG.debug("Started REST data stream source at port {}.", port); from("netty4-http:http://0.0.0.0:" + port + "/?matchOnUriPrefix=true&httpMethodRestrict=OPTIONS,GET,POST,PUT,DELETE"). choice(). when(header(HTTP_METHOD).isEqualTo("OPTIONS")).setBody().constant("").endChoice(). otherwise(). setHeader(CONTENT_TYPE).constant(contentType). process( exc -> { String requestUri = exc.getIn().getHeader(HTTP_URI, String.class); LOG.debug("Processing request URI: {}", requestUri); String trimmedUri = removeEnd(requestUri, "/"); LOG.debug("Trimmed request URI: {}", trimmedUri); String busChannel = trimmedUri.substring(1).replaceAll("\\/", "."); exc.setProperty("target", "amqp:" + busChannel); }).toD("${property.target}").endChoice(). end(). process(exc -> { exc.getIn().setHeader("Access-Control-Allow-Origin", "*"); exc.getIn().setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); }); }
public void exposeAnnotatedBeans() { for (Map.Entry<String, Object> bean : findBeansWithRestOperations(routeBuilder.getContext().getRegistry()).entrySet()) { for (Method method : findRestOperations(bean.getValue().getClass())) { String uri = "/" + bean.getKey() + "/" + method.getName(); boolean isGet = true; int parametersCount = method.getParameterCount(); if (parametersCount > 0) { Class<?> lastParameterType = method.getParameterTypes()[parametersCount - 1]; if (lastParameterType != String.class && lastParameterType != Character.class && lastParameterType != char.class && lastParameterType != Integer.class && lastParameterType != int.class && lastParameterType != Long.class && lastParameterType != long.class && lastParameterType != Float.class && lastParameterType != float.class && lastParameterType != Double.class && lastParameterType != double.class) { isGet = false; parametersCount--; } } for (int i = 0; i < parametersCount; i++) { uri += "/{p" + i + "}"; } routeBuilder.rest(uri).verb(isGet ? "GET" : "POST").route().process(restParametersBindingProcessor()). to("bean:" + bean.getKey() + "?method=" + method.getName() + "&multiParameterArray=true"). choice().when(routeBuilder.header("CAMEL_REST_VOID_OPERATION").isNotNull()).setBody().constant("").endChoice(); } } }
/** * Lets configure the Camel routing rules using Java code... */ public void configure() { // TODO create Camel routes here. // here is a sample which processes the input files // (leaving them in place - see the 'noop' flag) // then performs content based routing on the message // using XPath from("file:src/data?noop=true"). choice(). when(xpath("/person/city = 'London'")).to("file:target/messages/uk"). otherwise().to("file:target/messages/others"); } }
/** * Lets configure the Camel routing rules using Java code... */ public void configure() { // TODO create Camel routes here. // here is a sample which processes the input files // (leaving them in place - see the 'noop' flag) // then performs content based routing on the message // using XPath from("file:src/data?noop=true"). choice(). when(xpath("/person/city = 'London'")).to("file:target/messages/uk"). otherwise().to("file:target/messages/others"); } }
/** * Let's configure the Camel routing rules using Java code... */ public void configure() { // here is a sample which processes the input files // (leaving them in place - see the 'noop' flag) // then performs content based routing on the message using XPath from("file:src/data?noop=true&recusive=true") .choice() .when(xpath("/person/city = 'London'")) .to("log:uk?showall=true") .to("file:target/messages/uk") .otherwise() .to("file:target/messages/others"); }
public void configure() { from("file:src/data?noop=true") .choice() .when(xpath("/recipe = 'cookie'")) .log("Cookie message") .to("file:target/messages/cookies") .otherwise() .log("Other message") .to("file:target/messages/others"); }
@Override public void configure() throws Exception { from("file://source") .choice() .when(simple("${in.header.CamelFileName} contains 'widget.txt'")) .to("file://widget") .when(simple("${in.header.CamelFileName} contains 'gadget.txt'")) .to("file://gadget") .otherwise() .to("log://org.apache.camel.howto"); } }
@Override public void configure() throws Exception { from("direct:start") .choice() .when(body().isEqualTo("orange")) .to("mock:oranges") .when(body().isEqualTo("apple")) .to("mock:apples"); }
public void configure() { from("timer:foo?period=5000&synchronous=true") .transform(simple("${random(1000)}")) .choice() .when(simple("${body} > 500")) .log("High number ${body}") .to("mock:high") .otherwise() .log("Low number ${body}") .to("mock:low"); }
/** * * @throws Exception */ @Override public void configure() throws Exception { for (int i = 0; i<endpoints.size();i++){ from(endpoints.get(i)).routeId("Node2MatcherRoute"+brokerUri+i) .choice() .when(header("methodName").isEqualTo("needCreated")) .to("bean:matcherProtocolMatcherServiceJMSBased?method=needCreated") .when(header("methodName").isEqualTo("needActivated")) .to("bean:matcherProtocolMatcherServiceJMSBased?method=needActivated") .when(header("methodName").isEqualTo("needDeactivated")) .to("bean:matcherProtocolMatcherServiceJMSBased?method=needDeactivated") .otherwise() .to("log:Message Type Not Supported"); } }
@Override public void configure() throws Exception { logger.info("Configure Recurrent Route 'To Target'"); RouteDefinition rtDef; if (RouterConstants.CONFIG_TYPE_KAFKA.equals(configType)) { rtDef = from((KafkaEndpoint) getEndpointURI(RouterConstants.DIRECTION_TO, RouterConstants.DIRECT_IMPORT_DEPOSIT_BUFFER)); } else { rtDef = from((String) getEndpointURI(RouterConstants.DIRECTION_TO, RouterConstants.DIRECT_IMPORT_DEPOSIT_BUFFER)); } rtDef.choice() .when(header(RouterConstants.HEADER_FAILED_MESSAGE).isNull()) .unmarshal(jacksonDataFormat) .process(unomiStorageProcessor) .otherwise() .log(LoggingLevel.DEBUG, "Failed message, skip processing!") .end() .aggregate(constant(true), new ArrayListAggregationStrategy()) .completionPredicate(exchangeProperty("CamelSplitComplete").isEqualTo("true")) .eagerCheckCompletion() .process(importRouteCompletionProcessor) .to("log:org.apache.unomi.router?level=DEBUG"); }
@Override public void configure() throws Exception { //NOSONAR super.configure(); // initial route RouteDefinition route = appendSplitterRoutes( appendFilterRoutes( from(endpoints.getInputUri()) ) ); // main processing route addInterimProc(route .setHeader(PLUGIN_ID, constant(pluginId)) .log(DEBUG, format("===> INPUT FOR %s ${exchangeId} ${in.header.bodyClass}, correlationKey: ${in.header.correlationKey}", pluginId)) .process(getProcessor())) .choice() .when(body().isNull()) .log(DEBUG, pluginId + " output is NULL, skipping next routes") .stop() .otherwise() .log(DEBUG, format("===> ROUTE %s ===> %s", endpoints.getInputUri(), endpoints.getProducerUri())) .to(endpoints.getProducerUri()) .routeId(endpoints.getInputRouteId()); }
@Override public void configure() { // load file orders from src/data into the JMS queue from("file:src/data?noop=true").to("jms:incomingOrders"); // content-based router from("jms:incomingOrders") .process(new Processor() { public void process(Exchange exchange) throws Exception { System.out.println("Received order: " + exchange.getIn().getBody(String.class)); } }) .choice() .when(header("CamelFileName").endsWith(".xml")) .to("jms:xmlOrders") .when(header("CamelFileName").regex("^.*(csv|csl)$")) .to("jms:csvOrders") .otherwise() .to("jms:badOrders"); } });
.choice() .when(header("CamelFileName").endsWith(".xml")) .to("jms:xmlOrders")
@Override public void configure() { // load file orders from src/data into the JMS queue from("file:src/data?noop=true").to("jms:incomingOrders"); // content-based router from("jms:incomingOrders") .choice() .when(header("CamelFileName").endsWith(".xml")) .to("jms:xmlOrders") .when(header("CamelFileName").endsWith(".csv")) .to("jms:csvOrders"); // test that our route is working from("jms:xmlOrders").process(new Processor() { public void process(Exchange exchange) throws Exception { System.out.println("Received XML order: " + exchange.getIn().getHeader("CamelFileName")); } }); from("jms:csvOrders").process(new Processor() { public void process(Exchange exchange) throws Exception { System.out.println("Received CSV order: " + exchange.getIn().getHeader("CamelFileName")); } }); } });
@Override public void configure() { // load file orders from src/data into the JMS queue from("file:src/data?noop=true").to("jms:incomingOrders"); // content-based router from("jms:incomingOrders") .choice() .when(header("CamelFileName").endsWith(".xml")) .to("jms:xmlOrders") .when(header("CamelFileName").regex("^.*(csv|csl)$")) .to("jms:csvOrders") .otherwise() .to("jms:badOrders"); // lets filter out the test messages from("jms:xmlOrders").filter(xpath("/order[not(@test)]")) .process(new Processor() { public void process(Exchange exchange) throws Exception { System.out.println("Received XML order: " + exchange.getIn().getHeader("CamelFileName")); } }); } });
.choice() .when(header("CamelFileName").endsWith(".xml")) .to("jms:topic:xmlOrders")
.choice() .when(header("CamelFileName").endsWith(".xml")) .to("jms:topic:xmlOrders")
.choice() .when(header("CamelFileName").endsWith(".xml")) .to("jms:xmlOrders")
@Override public void configure() throws Exception { // use vertx instance on the Camel vertx component getContext().getComponent("vertx", VertxComponent.class).setVertx(vertx); // initialize the list of games which is called when a new client connects to Vert.X backend from("direct:init-games").routeId("init-games") .log("Init games event") .to("goal:games.csv") // the frontend expect one message per game so split .split(body()) .to("vertx:games"); // the route for handling live score updates from the goal // component which is published to vertx addresses from("goal:goals.csv").routeId("livescore").autoStartup(false) .log("Goal event: ${header.action} -> ${body}") .choice() .when(header("action").isEqualTo("clock")) .to("vertx:clock") .when(header("action").isEqualTo("goal")) .to("vertx:goals"); // consume from vertx control address when the user clicks the control buttons // then we want to start/suspend the livescore route accordingly from("vertx:control").routeId("control") .log("Control event: ${body}") .toD("controlbus:route?routeId=livescore&async=true&action=${body}"); }