Search in sources :

Example 86 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class CamelGreeterFileDomTest method testCamelGreeter.

@Test
public void testCamelGreeter() throws Exception {
    TestSupport.deleteDirectory("target/greeter/response");
    assertNotNull(camelContext);
    ProducerTemplate template = camelContext.createProducerTemplate();
    Object result = template.requestBody("direct:start", REQUEST);
    template.stop();
    assertEquals("The result is wrong.", "Hello Willem", result);
    File file = new File("target/greeter/response/response.txt");
    assertTrue("File " + file + " should be there.", file.exists());
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) File(java.io.File) Test(org.junit.Test)

Example 87 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class CamelGreeterTest method testMocksAreValid.

@Test
public void testMocksAreValid() throws Exception {
    assertNotNull(camelContext);
    assertNotNull(resultEndpoint);
    ProducerTemplate template = camelContext.createProducerTemplate();
    template.sendBodyAndHeader("jms:requestQueue", "Willem", CxfConstants.OPERATION_NAME, "greetMe");
    // Sleep a while and wait for the message whole processing
    Thread.sleep(4000);
    template.stop();
    MockEndpoint.assertIsSatisfied(camelContext);
    List<Exchange> list = resultEndpoint.getReceivedExchanges();
    assertEquals("Should get one message", list.size(), 1);
    for (Exchange exchange : list) {
        String result = (String) exchange.getIn().getBody();
        assertEquals("Get the wrong result ", result, "Hello Willem");
    }
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Test(org.junit.Test)

Example 88 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class JettyJmsTest method testMocksAreValid.

@Test
public void testMocksAreValid() throws Exception {
    assertNotNull(resultEndpoint);
    resultEndpoint.reset();
    ProducerTemplate template = camelContext.createProducerTemplate();
    template.sendBodyAndHeader(URL, "Hello form Willem", "Operation", "greetMe");
    // Sleep a while and wait for the message whole processing
    Thread.sleep(4000);
    template.stop();
    MockEndpoint.assertIsSatisfied(camelContext);
    List<Exchange> list = resultEndpoint.getReceivedExchanges();
    assertEquals("Should get one message", list.size(), 1);
    for (Exchange exchange : list) {
        Object result = exchange.getIn().getBody();
        assertEquals("Should get the request", "Hello form Willem", result);
        assertEquals("Should get the header", "greetMe", exchange.getIn().getHeader("Operation"));
    }
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Test(org.junit.Test)

Example 89 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project java-design-patterns by iluwatar.

the class App method main.

/**
   * Program entry point
   */
public static void main(String[] args) throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:origin").multicast().to("mock:foo", "mock:bar", "stream:out");
        }
    });
    ProducerTemplate template = context.createProducerTemplate();
    context.start();
    context.getRoutes().stream().forEach(r -> LOGGER.info(r.toString()));
    template.sendBody("direct:origin", "Hello from origin");
    context.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 90 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project quickstarts by jboss-switchyard.

the class HL7Client method testSendA19.

public void testSendA19() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    HL7MLLPCodec codec = new HL7MLLPCodec();
    codec.setCharset("iso-8859-1");
    codec.setConvertLFtoCR(true);
    registry.put("hl7codec", codec);
    CamelContext camelContext = new DefaultCamelContext(registry);
    camelContext.start();
    ProducerTemplate template = camelContext.createProducerTemplate();
    String line1 = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4";
    String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";
    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);
    template.requestBody("mina2:tcp://127.0.0.1:" + MINA2_PORT + "?sync=true&codec=#hl7codec", in.toString());
    template.stop();
    camelContext.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) HL7MLLPCodec(org.apache.camel.component.hl7.HL7MLLPCodec) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Aggregations

ProducerTemplate (org.apache.camel.ProducerTemplate)130 Test (org.junit.Test)58 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)53 CamelContext (org.apache.camel.CamelContext)48 Exchange (org.apache.camel.Exchange)36 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)27 Deployment (org.activiti.engine.test.Deployment)16 RouteBuilder (org.apache.camel.builder.RouteBuilder)16 Processor (org.apache.camel.Processor)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 HashMap (java.util.HashMap)7 Task (org.activiti.engine.task.Task)7 Endpoint (org.apache.camel.Endpoint)7 File (java.io.File)6 ArrayList (java.util.ArrayList)5 Message (org.apache.camel.Message)4 List (java.util.List)3 ExecutorService (java.util.concurrent.ExecutorService)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 ConsumerTemplate (org.apache.camel.ConsumerTemplate)3