org.apache.camel.builder.PredicateBuilder Java Examples
The following examples show how to use
org.apache.camel.builder.PredicateBuilder.
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: 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 #3
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 #4
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 #5
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 #6
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 #7
Source File: QuickfixIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void sendMessage() throws Exception { final CountDownLatch logonLatch = new CountDownLatch(2); final CountDownLatch receivedMessageLatch = new CountDownLatch(1); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { // Release latch when session logon events are received // We expect two events, one for the trader session and one for the market session from("quickfix:quickfix/inprocess.cfg"). filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)). bean(new CountDownLatchDecrementer("logon", logonLatch)); // For all received messages, print the JSON-formatted message to stdout from("quickfix:quickfix/inprocess.cfg"). filter(PredicateBuilder.or( header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AdminMessageReceived), header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived))). bean(new QuickfixjMessageJsonPrinter()); // If the market session receives an email then release the latch from("quickfix:quickfix/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER"). filter(header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EMAIL)). bean(new CountDownLatchDecrementer("message", receivedMessageLatch)); } }); camelctx.start(); try { Assert.assertTrue("Logon succeed", logonLatch.await(5L, TimeUnit.SECONDS)); String marketUri = "quickfix:quickfix/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET"; Endpoint endpoint = camelctx.getEndpoint(marketUri); Producer producer = endpoint.createProducer(); Email email = createEmailMessage("Example"); Exchange exchange = endpoint.createExchange(ExchangePattern.InOnly); exchange.getIn().setBody(email); producer.process(exchange); Assert.assertTrue("Message reached market", receivedMessageLatch.await(5L, TimeUnit.SECONDS)); } finally { camelctx.close(); } }