org.apache.camel.Predicate Java Examples
The following examples show how to use
org.apache.camel.Predicate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompoundPredicateTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { // build a compound predicate using the PredicateBuilder Predicate valid = PredicateBuilder.and( // this xpath must return true xpath("/book/title = 'Camel in Action'"), // this simple must return true simple("${header.source} == 'batch'"), // this method call predicate must return false (as we use not) not(method(CompoundPredicateTest.class, "isAuthor"))); // use the predicate in the route using the validate eip from("direct:start") .validate(valid) .to("mock:valid"); } }; }
Example #2
Source File: MainRoute.java From container with Apache License 2.0 | 6 votes |
@Override public void configure() throws Exception { // Predicates to check if a operation should be invoked, if an // invocation has finished or if the results of an invocation should be // returned. Checking is based on the APPLICATION_BUS_METHOD header final Predicate INVOKE_PREDICATE = header(ApplicationBusConstants.APPLICATION_BUS_METHOD.toString()).isEqualTo(ApplicationBusConstants.APPLICATION_BUS_METHOD_INVOKE.toString()); final Predicate IS_FINISHED_PREDICATE = header(ApplicationBusConstants.APPLICATION_BUS_METHOD.toString()).isEqualTo(ApplicationBusConstants.APPLICATION_BUS_METHOD_IS_FINISHED.toString()); final Predicate GET_RESULT_PREDICATE = header(ApplicationBusConstants.APPLICATION_BUS_METHOD.toString()).isEqualTo(ApplicationBusConstants.APPLICATION_BUS_METHOD_GET_RESULT.toString()); from(ApplicationBusServiceImpl.ENDPOINT).choice().when(INVOKE_PREDICATE).to(INVOKE_ENDPOINT) .when(IS_FINISHED_PREDICATE).to(IS_FINISHED_ENDPOINT) .when(GET_RESULT_PREDICATE).to(GET_RESULT_ENDPOINT).end(); }
Example #3
Source File: TikaIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void detectDoc() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("tika:detect").to("mock:result"); } }); MockEndpoint resultEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); try { camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); File document = new File("src/test/resources/tika/test.doc"); template.sendBody("direct:start", document); resultEndpoint.setExpectedMessageCount(1); resultEndpoint.expectedMessagesMatches(new Predicate() { @Override public boolean matches(Exchange exchange) { Object body = exchange.getIn().getBody(String.class); Assert.assertThat(body, instanceOf(String.class)); Assert.assertThat((String) body, containsString("application/x-tika-msoffice")); return true; } }); resultEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #4
Source File: TikaIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void parseGif() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("tika:parse").to("mock:result"); } }); MockEndpoint resultEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); try { camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); File document = new File("src/test/resources/tika/testGIF.gif"); template.sendBody("direct:start", document); resultEndpoint.setExpectedMessageCount(1); resultEndpoint.expectedMessagesMatches(new Predicate() { @Override public boolean matches(Exchange exchange) { Object body = exchange.getIn().getBody(String.class); Map<String, Object> headerMap = exchange.getIn().getHeaders(); Assert.assertThat(body, instanceOf(String.class)); Assert.assertThat((String) body, containsString("<body")); Assert.assertThat(headerMap.get(Exchange.CONTENT_TYPE), equalTo("image/gif")); return true; } }); resultEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #5
Source File: TikaIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void parseDocWithRegistryConfig() throws Exception { CamelContext camelctx = new DefaultCamelContext(createRegistryWithEmptyConfig()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("tika:parse?tikaConfig=#testConfig").to("mock:result"); } }); MockEndpoint resultEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); try { ProducerTemplate template = camelctx.createProducerTemplate(); camelctx.start(); File document = new File("src/test/resources/tika/test.doc"); template.sendBody("direct:start", document); resultEndpoint.setExpectedMessageCount(1); resultEndpoint.expectedMessagesMatches(new Predicate() { @Override public boolean matches(Exchange exchange) { Object body = exchange.getIn().getBody(String.class); Map<String, Object> headerMap = exchange.getIn().getHeaders(); Assert.assertThat(body, instanceOf(String.class)); Assert.assertThat((String) body, containsString("<body")); Assert.assertThat(headerMap.get(Exchange.CONTENT_TYPE), equalTo("application/msword")); return true; } }); resultEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #6
Source File: TikaIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void parseDocWithEmptyRegistryConfig() throws Exception { CamelContext camelctx = new DefaultCamelContext(createRegistryWithEmptyConfig()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("tika:parse?tikaConfig=#testConfig").to("mock:result"); } }); MockEndpoint resultEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); try { camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); File document = new File("src/test/resources/tika/test.doc"); template.sendBody("direct:start", document); resultEndpoint.setExpectedMessageCount(1); resultEndpoint.expectedMessagesMatches(new Predicate() { @Override public boolean matches(Exchange exchange) { Object body = exchange.getIn().getBody(String.class); Map<String, Object> headerMap = exchange.getIn().getHeaders(); Assert.assertThat(body, instanceOf(String.class)); Assert.assertThat((String) body, containsString("<body")); Assert.assertThat(headerMap.get(Exchange.CONTENT_TYPE), equalTo("application/msword")); return true; } }); resultEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #7
Source File: AbstractFilterStepHandler.java From syndesis with Apache License 2.0 | 5 votes |
@Override public Optional<ProcessorDefinition<?>> handle(Step step, ProcessorDefinition<?> route, IntegrationRouteBuilder builder, String flowIndex, String stepIndex) { ObjectHelper.notNull(route, "route"); final String expression = ObjectHelper.notNull(getFilterExpression(step), "expression"); final CamelContext context = builder.getContext(); final Predicate predicate = new JsonSimplePredicate(expression, context); final FilterDefinition filter = route.filter(predicate); return Optional.of(filter); }
Example #8
Source File: FunktionRouteBuilder.java From funktion-connectors with Apache License 2.0 | 5 votes |
protected Predicate getMandatoryPredicate(Step step, String expression, String language) { Objects.requireNonNull(expression, "No expression specified for step " + step); Language jsonpath = getLanguage(language); Predicate answer = jsonpath.createPredicate(expression); Objects.requireNonNull(answer, "No predicate created from: " + expression); return answer; }
Example #9
Source File: TikaIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void detectGif() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("tika:detect").to("mock:result"); } }); MockEndpoint resultEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); try { camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); File document = new File("src/test/resources/tika/testGIF.gif"); template.sendBody("direct:start", document); resultEndpoint.setExpectedMessageCount(1); resultEndpoint.expectedMessagesMatches(new Predicate() { @Override public boolean matches(Exchange exchange) { Object body = exchange.getIn().getBody(String.class); Assert.assertThat(body, instanceOf(String.class)); Assert.assertThat((String) body, containsString("image/gif")); return true; } }); resultEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #10
Source File: CamelRegistryTest.java From camel-quarkus with Apache License 2.0 | 5 votes |
@Test public void testLookupCustomServices() { assertThat(registry.lookupByNameAndType("my-df", DataFormat.class)).isNotNull(); assertThat(registry.lookupByNameAndType("my-language", Language.class)).isNotNull(); assertThat(registry.lookupByNameAndType("my-component", Component.class)).isNotNull(); assertThat(registry.lookupByNameAndType("my-predicate", Predicate.class)).isNotNull(); assertThat(registry.lookupByNameAndType("my-processor", Processor.class)).isNotNull(); }
Example #11
Source File: Route.java From container with Apache License 2.0 | 5 votes |
@Override public void configure() throws Exception { final Predicate OK = header(Exchange.HTTP_RESPONSE_CODE).isEqualTo(200); final Predicate PENDING = PredicateBuilder.and(OK, body().isEqualTo(PENDING_STRING)); final Predicate RESULT_RECEIVED = PredicateBuilder.and(OK, PredicateBuilder.not(PENDING)); final SimpleBuilder INVOKE_ENDPOINT = simple("${header." + ApplicationBusConstants.INVOCATION_ENDPOINT_URL.toString() + "}" + APPINVOKER_ENDPOINT_SUFFIX); final SimpleBuilder POLL_ENDPOINT = simple("${header.Location}"); final RequestProcessor requestProcessor = new RequestProcessor(); final ResponseProcessor responseProcessor = new ResponseProcessor(); from(ApplicationBusJsonHttpPluginServiceImpl.ENDPOINT).process(requestProcessor) .setHeader(Exchange.HTTP_METHOD, constant("POST")) .setHeader(Exchange.CONTENT_TYPE, constant("application/json")) .setHeader(Exchange.HTTP_URI, INVOKE_ENDPOINT) .to(DUMMY_ENDPOINT).choice() .when(header(Exchange.HTTP_RESPONSE_CODE).isEqualTo(202)) .setHeader(Exchange.HTTP_URI, POLL_ENDPOINT) .to("direct:polling").endChoice().otherwise() .to("direct:throwException"); from("direct:polling").setHeader(Exchange.HTTP_METHOD, constant("GET")).to(DUMMY_ENDPOINT) .convertBodyTo(String.class).choice().when(PENDING).delay(5000).to("direct:polling") .endChoice().when(RESULT_RECEIVED).process(responseProcessor).endChoice().otherwise() .to("direct:throwException"); from("direct:throwException").process(exchange -> exchange.getIn().setBody(new ApplicationBusExternalException( exchange.getIn().getBody(String.class)))); }
Example #12
Source File: Route.java From container with Apache License 2.0 | 5 votes |
@Override public void configure() throws Exception { final URL wsdlURL = this.getClass().getClassLoader().getResource("wsdl/SoapAPI.wsdl"); // CXF Endpoint final String SOAP_ENDPOINT = "cxf:" + ENDPOINT + "?wsdlURL=" + wsdlURL.toString() + "&serviceName={http://opentosca.org/appinvoker/}AppInvokerSoapWebServiceService&portName=" + PORT.toString() + "&dataFormat=PAYLOAD&loggingFeatureEnabled=true"; final ValueBuilder APP_BUS_ENDPOINT = new ValueBuilder(method(ApplicationBusServiceHandler.class, "getApplicationBusRoutingEndpoint")); final Predicate APP_BUS_ENDPOINT_EXISTS = PredicateBuilder.isNotNull(APP_BUS_ENDPOINT); final ClassLoader cl = org.opentosca.bus.application.api.soaphttp.model.ObjectFactory.class.getClassLoader(); final JAXBContext jc = JAXBContext.newInstance("org.opentosca.bus.application.api.soaphttp.model", cl); final JaxbDataFormat jaxb = new JaxbDataFormat(jc); final Processor requestProcessor = new RequestProcessor(); final Processor responseProcessor = new ResponseProcessor(); from(SOAP_ENDPOINT).unmarshal(jaxb).process(requestProcessor).choice().when(APP_BUS_ENDPOINT_EXISTS) //FIXME this recipientList should be replaced with a directly injected service reference .recipientList(APP_BUS_ENDPOINT).to("direct:handleResponse").endChoice().otherwise() .to("direct:handleException"); // handle exception if Application Bus is not running or wasn't bound from("direct:handleException") .throwException(new ApplicationBusInternalException("It seems like the Application Bus is not running.")) .to("direct:handleResponse"); // handle response from("direct:handleResponse").process(responseProcessor).marshal(jaxb); }
Example #13
Source File: MyPredicateInlineRoute.java From camel-cookbook-examples with Apache License 2.0 | 5 votes |
@Override public void configure() throws Exception { from("direct:start") .filter(new Predicate() { @Override public boolean matches(Exchange exchange) { final String body = exchange.getIn().getBody(String.class); return ((body != null) && body.contains("Boston")); } }) .to("mock:boston"); }
Example #14
Source File: Route.java From container with Apache License 2.0 | 4 votes |
@Override public void configure() throws Exception { final URL wsdlURL = this.getClass().getClassLoader().getResource("wsdl/invoker.wsdl"); // CXF Endpoints final String INVOKE_ENDPOINT = "cxf:" + ENDPOINT + "?wsdlURL=" + wsdlURL.toString() + "&serviceName={http://siserver.org/wsdl}InvokerService&portName=" + Route.PORT.toString() + "&dataFormat=PAYLOAD&loggingFeatureEnabled=true"; final String CALLBACK_ENDPOINT = "cxf:${header[ReplyTo]}?wsdlURL=" + wsdlURL.toString() + "&headerFilterStrategy=#dropAllMessageHeadersStrategy" + "&serviceName={http://siserver.org/wsdl}CallbackService&portName={http://siserver.org/wsdl}CallbackPort" + "&dataFormat=PAYLOAD&loggingFeatureEnabled=true"; // Checks if invoke is sync or async final Predicate MESSAGEID = header("MessageID").isNotNull(); final Predicate REPLYTO = header("ReplyTo").isNotNull(); final Predicate ASYNC = PredicateBuilder.and(MESSAGEID, REPLYTO); final ClassLoader cl = org.opentosca.bus.management.api.soaphttp.model.ObjectFactory.class.getClassLoader(); final JAXBContext jc = JAXBContext.newInstance("org.opentosca.bus.management.api.soaphttp.model", cl); final JaxbDataFormat requestJaxb = new JaxbDataFormat(jc); final JaxbDataFormat responseJaxb = new JaxbDataFormat(jc); responseJaxb.setPartClass("org.opentosca.bus.management.api.soaphttp.model.InvokeResponse"); responseJaxb.setPartNamespace(new QName("http://siserver.org/schema", "invokeResponse")); final Processor requestProcessor = new RequestProcessor(csarStorageService, containerEngine); final Processor responseProcessor = new ResponseProcessor(); this.from(INVOKE_ENDPOINT) .unmarshal(requestJaxb) .process(requestProcessor) .choice().when(IS_INVOKE_IA) .bean(managementBusService, "invokeIA") .when(IS_INVOKE_PLAN) .bean(managementBusService, "invokePlan") .end(); this.from("direct-vm:" + RequestProcessor.MB_MANAGEMENT_SOAPHTTP_API_ID).process(responseProcessor).marshal(responseJaxb).choice().when(ASYNC) .recipientList(this.simple(CALLBACK_ENDPOINT)).end(); }
Example #15
Source File: TikaIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void parseOdtWithEncoding() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("tika:parse?tikaParseOutputEncoding=" + StandardCharsets.UTF_16.name()) .to("mock:result"); } }); MockEndpoint resultEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); try { camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); File document = new File("src/test/resources/tika/testOpenOffice2.odt"); template.sendBody("direct:start", document); resultEndpoint.setExpectedMessageCount(1); resultEndpoint.expectedMessagesMatches(new Predicate() { @Override public boolean matches(Exchange exchange) { Object body = exchange.getIn().getBody(String.class); Map<String, Object> headerMap = exchange.getIn().getHeaders(); Assert.assertThat(body, instanceOf(String.class)); Charset detectedCharset = null; try { InputStream bodyIs = new ByteArrayInputStream( ((String) body).getBytes(StandardCharsets.UTF_16)); UniversalEncodingDetector encodingDetector = new UniversalEncodingDetector(); detectedCharset = encodingDetector.detect(bodyIs, new Metadata()); } catch (IOException e1) { throw new RuntimeException(e1); } Assert.assertThat(detectedCharset.name(), startsWith(StandardCharsets.UTF_16.name())); Assert.assertThat(headerMap.get(Exchange.CONTENT_TYPE), equalTo("application/vnd.oasis.opendocument.text")); return true; } }); resultEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #16
Source File: TikaIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void parseDoc() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("tika:parse").to("mock:result"); } }); MockEndpoint resultEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); try { camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); File document = new File("src/test/resources/tika/test.doc"); template.sendBody("direct:start", document); resultEndpoint.setExpectedMessageCount(1); resultEndpoint.expectedMessagesMatches(new Predicate() { @Override public boolean matches(Exchange exchange) { Object body = exchange.getIn().getBody(String.class); Map<String, Object> headerMap = exchange.getIn().getHeaders(); Assert.assertThat(body, instanceOf(String.class)); Charset detectedCharset = null; try { InputStream bodyIs = new ByteArrayInputStream(((String) body).getBytes()); UniversalEncodingDetector encodingDetector = new UniversalEncodingDetector(); detectedCharset = encodingDetector.detect(bodyIs, new Metadata()); } catch (IOException e1) { throw new RuntimeException(e1); } Assert.assertThat((String) body, containsString("test")); Assert.assertThat(detectedCharset.name(), startsWith(Charset.defaultCharset().name())); Assert.assertThat(headerMap.get(Exchange.CONTENT_TYPE), equalTo("application/msword")); return true; } }); resultEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #17
Source File: Route.java From container with Apache License 2.0 | 4 votes |
@Override public void configure() throws Exception { final ValueBuilder APP_BUS_ENDPOINT = new ValueBuilder(method(ApplicationBusServiceHandler.class, "getApplicationBusRoutingEndpoint")); final Predicate APP_BUS_ENDPOINT_EXISTS = PredicateBuilder.isNotNull(APP_BUS_ENDPOINT); final InvocationRequestProcessor invocationRequestProcessor = new InvocationRequestProcessor(); final InvocationResponseProcessor invocationResponseProcessor = new InvocationResponseProcessor(); final IsFinishedRequestProcessor isFinishedRequestProcessor = new IsFinishedRequestProcessor(); final IsFinishedResponseProcessor isFinishedResponseProcessor = new IsFinishedResponseProcessor(); final GetResultRequestProcessor getResultRequestProcessor = new GetResultRequestProcessor(); final GetResultResponseProcessor getResultResponseProcessor = new GetResultResponseProcessor(); final ExceptionProcessor exceptionProcessor = new ExceptionProcessor(); // handle exceptions onException(Exception.class).handled(true).setBody(property(Exchange.EXCEPTION_CAUGHT)) .process(exceptionProcessor); // invoke route from("restlet:" + Route.BASE_ENDPOINT + Route.INVOKE_ENDPOINT + "?restletMethod=post") .process(invocationRequestProcessor).to(Route.TO_APP_BUS_ENDPOINT).choice() .when(property(Exchange.EXCEPTION_CAUGHT).isNull()).process(invocationResponseProcessor).removeHeaders("*") .otherwise().process(exceptionProcessor); // isFinished route from("restlet:" + Route.BASE_ENDPOINT + Route.POLL_ENDPOINT + "?restletMethod=get") .process(isFinishedRequestProcessor).to(Route.TO_APP_BUS_ENDPOINT).process(isFinishedResponseProcessor) .removeHeaders("*"); // getResult route from("restlet:" + Route.BASE_ENDPOINT + Route.GET_RESULT_ENDPOINT + "?restletMethod=get") .process(getResultRequestProcessor).to(Route.TO_APP_BUS_ENDPOINT).process(getResultResponseProcessor) .removeHeaders("*"); // applicationBus route, throws exception if Application Bus is not // running or wasn't binded from(Route.TO_APP_BUS_ENDPOINT).choice().when(APP_BUS_ENDPOINT_EXISTS).recipientList(APP_BUS_ENDPOINT) .endChoice().otherwise().to("direct:handleException"); // handle exception if Application Bus is not running or wasn't binded from("direct:handleException") .throwException(new ApplicationBusInternalException("The Application Bus is not running.")); }
Example #18
Source File: Route.java From container with Apache License 2.0 | 4 votes |
@Override public void configure() throws Exception { final ValueBuilder APP_BUS_ENDPOINT = new ValueBuilder(this.method(ApplicationBusServiceHandler.class, "getApplicationBusRoutingEndpoint")); final Predicate APP_BUS_ENDPOINT_EXISTS = PredicateBuilder.isNotNull(APP_BUS_ENDPOINT); final InvocationRequestProcessor invocationRequestProcessor = new InvocationRequestProcessor(); final InvocationResponseProcessor invocationResponseProcessor = new InvocationResponseProcessor(); final IsFinishedRequestProcessor isFinishedRequestProcessor = new IsFinishedRequestProcessor(); final IsFinishedResponseProcessor isFinishedResponseProcessor = new IsFinishedResponseProcessor(); final GetResultRequestProcessor getResultRequestProcessor = new GetResultRequestProcessor(); final GetResultResponseProcessor getResultResponseProcessor = new GetResultResponseProcessor(); final ExceptionProcessor exceptionProcessor = new ExceptionProcessor(); // handle exceptions this.onException(Exception.class).handled(true).setBody(property(Exchange.EXCEPTION_CAUGHT)) .process(exceptionProcessor); // INVOKE ROUTES // invoke route (for ServiceInstance) this.from("restlet:" + Route.BASE_ENDPOINT + Route.INVOKE_ENDPOINT_SI + "?restletMethod=post") .to("direct:invoke"); // invoke route (for NodeInstance) this.from("restlet:" + Route.BASE_ENDPOINT + Route.INVOKE_ENDPOINT_NI + "?restletMethod=post") .to("direct:invoke"); // invoke route this.from("direct:invoke").process(invocationRequestProcessor).to(Route.TO_APP_BUS_ENDPOINT).choice() .when(property(Exchange.EXCEPTION_CAUGHT).isNull()).process(invocationResponseProcessor).removeHeaders("*") .otherwise().process(exceptionProcessor); // IS FINISHED ROUTES // isFinished route (for ServiceInstance) this.from("restlet:" + Route.BASE_ENDPOINT + Route.POLL_ENDPOINT_SI + "?restletMethod=get") .to("direct:isFinished"); // isFinished route (for NodeInstance) this.from("restlet:" + Route.BASE_ENDPOINT + Route.POLL_ENDPOINT_NI + "?restletMethod=get") .to("direct:isFinished"); // isFinished route this.from("direct:isFinished").process(isFinishedRequestProcessor).to(Route.TO_APP_BUS_ENDPOINT) .process(isFinishedResponseProcessor).removeHeaders("*"); // GET RESULT ROUTES // getResult route (for ServiceInstance) this.from("restlet:" + Route.BASE_ENDPOINT + Route.GET_RESULT_ENDPOINT_SI + "?restletMethod=get") .to("direct:getResult"); // getResult route (for NodeInstance) this.from("restlet:" + Route.BASE_ENDPOINT + Route.GET_RESULT_ENDPOINT_NI + "?restletMethod=get") .to("direct:getResult"); // getResult route this.from("direct:getResult").process(getResultRequestProcessor).to(Route.TO_APP_BUS_ENDPOINT) .process(getResultResponseProcessor).removeHeaders("*"); // applicationBus route, throws exception if Application Bus is not // running or wasn't binded this.from(Route.TO_APP_BUS_ENDPOINT).choice().when(APP_BUS_ENDPOINT_EXISTS).recipientList(APP_BUS_ENDPOINT) .endChoice().otherwise().to("direct:handleException"); // handle exception if Application Bus is not running or wasn't binded this.from("direct:handleException") .throwException(new ApplicationBusInternalException("The Application Bus is not running.")); }
Example #19
Source File: RouteBuilder.java From smsrouter with GNU General Public License v3.0 | 4 votes |
@Override public void configure() throws Exception { /** * Log some information about the configuration. */ logger.info("Parsing locally supplied numbers " + "using context country: {}", localCountry); logger.info("Parsing SMSC supplied numbers using " + "context country: {}", smscCountry); logger.info("Throttling allows {} request(s) per {}ms", throttleRequestsPerPeriod, throttleTimePeriodMillis); /** * Create some Processor instances that will be used in the routes. */ CountryClassifier origin = new CountryClassifier(localCountry, "SMSOrigin"); CountryClassifier destination = new CountryClassifier(localCountry, "SMSDestination"); Predicate blacklistedDestination = new Blacklist(blacklistCountries, "SMSDestinationCountryISO2"); SourceOverride sourceOverride = new SourceOverride(overrides, destination.getCountryHeaderName(), origin.getParsedHeaderName()); SmppAddressing smppAddressing = new SmppAddressing(smscCountry, origin.getParsedHeaderName(), destination.getParsedHeaderName()); /** * Create some strings that will be used in the Camel routes */ String log = "log:org.smsrouter?level=INFO"; String logWarn = "log:org.smsrouter?level=WARN"; String smppUriTemplate = "smpp://{{smpp.username}}@{{smpp.host}}:{{smpp.port}}" + "?password={{smpp.password}}" + "&systemType={{smpp.system-type}}" + "&enquireLinkTimer={{smpp.link-timer}}" + "&typeOfNumber=1" + "&numberingPlanIndicator=1"; String smppUriProducer = smppUriTemplate + "®isteredDelivery=1"; String smppUriConsumer = smppUriTemplate; String dlq = "activemq:smsrouter.outbox.failed"; /** * This Camel route handles messages going out to the SMS world */ from("activemq:smsrouter.outbox") .errorHandler(deadLetterChannel(dlq)) .onException(SmppException.class) .maximumRedeliveries(0) .end() .removeHeaders("CamelSmpp*")//In case it started as SMS elsewhere .process(origin) .process(destination) .choice() .when(blacklistedDestination) .to(dlq) .otherwise() .process(sourceOverride) .process(smppAddressing) .throttle(throttleRequestsPerPeriod) .timePeriodMillis(throttleTimePeriodMillis) .to(smppUriProducer) //.to("mock:foo") .setBody(simple("The SMSC accepted the message" + " for ${header.CamelSmppDestAddr}" + " and assigned SMPP ID: ${header.CamelSmppId}")) .to(log); /** * This Camel route handles messages coming to us from the SMS world */ from(smppUriConsumer) .threads(1, 1) .choice() .when(simple("${header.CamelSmppMessageType} == 'DeliveryReceipt'")) .setBody(simple("Message delivery receipt" + " for SMPP ID ${header.CamelSmppId}")) .to(log) .when(simple("${header.CamelSmppMessageType} == 'DeliverSm'")) .process(smppAddressing) .setHeader("SMSOrigin", header("SMSOriginE164")) .removeHeaders("Camel*") .to("activemq:smsrouter.inbox") .setBody(simple("Message from ${header.SMSOriginE164}" + " to ${header.SMSDestinationE164}: ${body}")) .to(log) .otherwise() .setBody(simple("Unhandled event type: ${header.CamelSmppMessageType}")) .to(logWarn); }
Example #20
Source File: ChoiceStepHandler.java From syndesis with Apache License 2.0 | 4 votes |
private static Predicate getPredicate(String conditionExpression, CamelContext context) { return new JsonSimplePredicate(conditionExpression, context); }
Example #21
Source File: ExpressionNodeMixIn.java From camel-k-runtime with Apache License 2.0 | 4 votes |
@JsonIgnore private void setExpression(Predicate predicate) { }
Example #22
Source File: CamelRegistryTest.java From camel-quarkus with Apache License 2.0 | 4 votes |
@Override public Predicate createPredicate(String expression) { return null; }
Example #23
Source File: CamelRegistryTest.java From camel-quarkus with Apache License 2.0 | 4 votes |
@Named("my-predicate") @Produces public Predicate predicate() { return e -> false; }