/** * Create a new Dispatcher instance. * @param context Camel context instance * @param reference dispatch for this reference */ public ExchangeDispatcher(ModelCamelContext context, ServiceReference reference) { _context = context; _reference = reference; _producer = context.createProducerTemplate(); }
/** * Create a new Dispatcher instance. * @param context Camel context instance * @param reference dispatch for this reference */ public ExchangeDispatcher(ModelCamelContext context, ServiceReference reference) { _context = context; _reference = reference; _producer = context.createProducerTemplate(); }
template = context.createProducerTemplate(); template.start(); fluentTemplate = context.createFluentProducerTemplate();
@Override public void sendEvent(Object req) { getContext().createProducerTemplate().asyncSendBody("direct:sendAlexInOnly", req); }
@Override public <T> ListenableFuture<T> sendRequest(Object req, final Class<? extends T> cls) { final SettableFuture<T> result = SettableFuture.create(); SynchronizationAdapter adapter = new SynchronizationAdapter() { @Override public void onComplete(Exchange exchange) { result.set(exchange.getIn().getBody(cls)); super.onComplete(exchange); } @Override public void onFailure(Exchange exchange) { result.setException(exchange.getException(Exception.class)); super.onFailure(exchange); } }; getContext().createProducerTemplate().asyncCallbackRequestBody("direct:sendAlexInOut", req, adapter); return result; } }
public void restartTimer() throws Exception { getContext().createProducerTemplate().asyncSendBody("direct:startTimer", ""); }
@Override public boolean run(String line) { if (!line.contains("latexmlc")) return false; HashMap<String, String> props = parse(line); String latexmlCmd = CommUtils.SerializeToQuery(props); getContext().createProducerTemplate().sendBodyAndHeader("direct:compileLaTeXML", latexmlCmd, "JMSCorrelationID", props.get("source")); return false; } };
public GetSelectionResponse getCurrentSelection() { Exchange e = new DefaultExchange(getContext()); e.getIn().setBody(new GetSelection()); getContext().createProducerTemplate().send("direct:sendAnnotationAlexInOut", e); return e.getOut().getBody(GetSelectionResponse.class); }
@Override public List<String> getAnnotationIDs() { Exchange e = new DefaultExchange(getContext()); e.getIn().setBody(new GetAnnotations()); getContext().createProducerTemplate().send("direct:sendAnnotationAlexInOut", e); GetAnnotationsResponse resp = e.getOut().getBody(GetAnnotationsResponse.class); return resp.getId(); } }
@Override public void persist(String id) { Exchange e = new DefaultExchange(getContext()); PersistSelection sel = new PersistSelection(); sel.setId(id); e.getIn().setBody(sel); getContext().createProducerTemplate().send("direct:sendAnnotationAlex", e); }
@Test public void sqlStoredStartConnectorTest() throws Exception { String jsonBody = "{\"a\":20,\"b\":30}"; ProducerTemplate template = context.createProducerTemplate(); String result = template.requestBody("direct:start", jsonBody, String.class); Assertions.assertThat(result).isEqualTo("{\"c\":50}"); } }
@Override public void navigateTo(String id) { NavigateTo navTo = new NavigateTo(); navTo.setId(id); getContext().createProducerTemplate().sendBody("direct:sendAnnotationAlex", navTo); }
@Test public void sqlStoredStartConnectorTest() throws Exception { String jsonBody = "{\"a\":20,\"b\":30}"; ProducerTemplate template = context.createProducerTemplate(); String result = template.requestBody("direct:start", jsonBody, String.class); Assertions.assertThat(result).isEqualTo("{\"c\":50}"); } }
@Test public void test1() throws Exception { String cmd = ""; cmd += "<batch-execution lookup=\"ksession1\">\n"; cmd += " <insert out-identifier=\"salaboy\">\n"; cmd += " <org.kie.pipeline.camel.Person>\n"; cmd += " <name>salaboy</name>\n"; cmd += " </org.kie.pipeline.camel.Person>\n"; cmd += " </insert>\n"; cmd += " <fire-all-rules/>\n"; cmd += "</batch-execution>\n"; Object object = this.context.createProducerTemplate().requestBody("direct://http", cmd); logger.debug("{}", object); }
@Test public void test1() throws Exception { String cmd = ""; cmd += "<batch-execution lookup=\"ksession1\">\n"; cmd += " <insert out-identifier=\"salaboy\">\n"; cmd += " <org.drools.pipeline.camel.Person>\n"; cmd += " <name>salaboy</name>\n"; cmd += " </org.drools.pipeline.camel.Person>\n"; cmd += " </insert>\n"; cmd += " <fire-all-rules/>\n"; cmd += "</batch-execution>\n"; Object object = this.context.createProducerTemplate().requestBody( "direct://http", cmd ); System.out.println( object ); }
public void test1() throws Exception { String cmd = ""; cmd += "<batch-execution lookup=\"ksession1\">\n"; cmd += " <insert out-identifier=\"salaboy\">\n"; cmd += " <org.drools.pipeline.camel.Person>\n"; cmd += " <name>salaboy</name>\n"; cmd += " </org.drools.pipeline.camel.Person>\n"; cmd += " </insert>\n"; cmd += " <fire-all-rules/>\n"; cmd += "</batch-execution>\n"; Object object = this.context.createProducerTemplate().requestBody( "direct://http", cmd ); System.out.println( object ); assertTrue( object.toString().contains( "fact-handle identifier=\"salaboy\"" ) ); String cmd2 = ""; cmd2 += "<batch-execution lookup=\"ksession2\">\n"; cmd2 += " <insert out-identifier=\"salaboy\">\n"; cmd2 += " <org.drools.pipeline.camel.Person>\n"; cmd2 += " <name>salaboy</name>\n"; cmd2 += " </org.drools.pipeline.camel.Person>\n"; cmd2 += " </insert>\n"; cmd2 += " <fire-all-rules/>\n"; cmd2 += "</batch-execution>\n"; Object object2 = this.context.createProducerTemplate().requestBody( "direct://http", cmd2 ); System.out.println( object2 ); assertTrue( object2.toString().contains( "fact-handle identifier=\"salaboy\"" ) ); }
@Test public void test1() throws Exception { KieSession kieSession = (KieSession)applicationContext.getBean("ksession1"); kieSession.setGlobal("out", System.out); String cmd = ""; cmd += "<batch-execution lookup=\"ksession1\">\n"; cmd += " <insert out-identifier=\"vkiran\">\n"; cmd += " <org.drools.example.api.namedkiesession.Message>\n"; cmd += " <name>HAL</name>\n"; cmd += " <text>Hello, HAL. Do you read me, HAL?</text>\n"; cmd += " </org.drools.example.api.namedkiesession.Message>\n"; cmd += " </insert>\n"; cmd += " <fire-all-rules/>\n"; cmd += "</batch-execution>\n"; Object object = this.context.createProducerTemplate().requestBody("direct://http", cmd); logger.debug(object.toString()); }
@Test public void test1() throws Exception { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName( "http://soap.jax.drools.org", "execute", "ns1" ); body.addBodyElement( payloadName ); String cmd = ""; cmd += "<batch-execution lookup=\"ksession1\">\n"; cmd += " <insert out-identifier=\"salaboy\" disconnected=\"true\">\n"; cmd += " <org.drools.pipeline.camel.Person>\n"; cmd += " <name>salaboy</name>\n"; cmd += " <age>27</age>\n"; cmd += " </org.drools.pipeline.camel.Person>\n"; cmd += " </insert>\n"; cmd += " <fire-all-rules/>\n"; cmd += "</batch-execution>\n"; body.addTextNode( cmd ); Object object = this.context.createProducerTemplate().requestBody( "direct://http", soapMessage ); OutputStream out = new ByteArrayOutputStream(); out = new ByteArrayOutputStream(); soapMessage = (SOAPMessage) object; soapMessage.writeTo( out ); String response = out.toString(); assertTrue( response.contains( "fact-handle identifier=\"salaboy\"" ) ); }
@Test public void sqlStoredStartConnectorTest() throws Exception { MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(1); mock.expectedBodiesReceived("{\"c\":60}"); ProducerTemplate template = context.createProducerTemplate(); template.sendBody("direct:start", null); mock.assertIsSatisfied(); } }
@Test public void sqlStartConnectorTest() throws Exception { MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(2); mock.expectedMessagesMatches( exchange -> validateProperty(exchange, "ID", "1"), exchange -> validateProperty(exchange, "ID", "2") ); ProducerTemplate template = context.createProducerTemplate(); template.sendBody("direct:start", null); mock.assertIsSatisfied(); }