Search in sources :

Example 41 with ProducerTemplate

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

the class JettyJmsTwowayTest method testSendingRequest.

@Test
public void testSendingRequest() throws Exception {
    assertNotNull("the camelContext should not be null", camelContext);
    ProducerTemplate template = camelContext.createProducerTemplate();
    Exchange exchange = template.send(URL, new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("<hello>Willem</hello>");
            exchange.getIn().setHeader("Operation", "greetMe");
        }
    });
    assertEquals("get result ", "<response><hello>Willem</hello></response>", exchange.getOut().getBody(String.class));
    template.stop();
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) Test(org.junit.Test)

Example 42 with ProducerTemplate

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

the class JettyMulticastJmsFileTest method testJettyMulticastJmsFile.

@Test
public void testJettyMulticastJmsFile() throws Exception {
    TestSupport.deleteDirectory("target/jetty");
    ProducerTemplate template = camelContext.createProducerTemplate();
    String out = template.requestBody(URL, "Hello World", String.class);
    assertEquals("Bye World", out);
    template.stop();
    ConsumerTemplate consumer = camelContext.createConsumerTemplate();
    String in = consumer.receiveBody("jms:queue:foo", 5000, String.class);
    assertEquals("Hello World", in);
    String in2 = consumer.receiveBody("file://target/jetty?noop=true&readLock=none", 5000, String.class);
    assertEquals("Hello World", in2);
    consumer.stop();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ConsumerTemplate(org.apache.camel.ConsumerTemplate) Test(org.junit.Test)

Example 43 with ProducerTemplate

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

the class ContainerWideInterceptorTest method testTwo.

public void testTwo() throws Exception {
    int start = myInterceptor.getCount();
    MockEndpoint result = camel2.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedBodiesReceived("Bye World");
    ProducerTemplate template = camel2.createProducerTemplate();
    template.start();
    template.sendBody("direct:two", "Bye World");
    template.stop();
    result.assertIsSatisfied();
    // lets see if the counter is +2 since last (has 2 steps in the route)
    int delta = myInterceptor.getCount() - start;
    assertEquals("Should have been counted +2", 2, delta);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 44 with ProducerTemplate

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

the class SignatureAlgorithmTest method doSignatureRouteTest.

public Exchange doSignatureRouteTest(RouteBuilder builder, Exchange e, Map<String, Object> headers) throws Exception {
    CamelContext context = new DefaultCamelContext();
    try {
        context.addRoutes(builder);
        context.start();
        MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
        mock.setExpectedMessageCount(1);
        ProducerTemplate template = context.createProducerTemplate();
        if (e != null) {
            template.send("direct:in", e);
        } else {
            template.sendBodyAndHeaders("direct:in", payload, headers);
        }
        assertMockEndpointsSatisfied();
        return mock.getReceivedExchanges().get(0);
    } finally {
        context.stop();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 45 with ProducerTemplate

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

the class SignatureDigestMethodTest method doSignatureRouteTest.

public Exchange doSignatureRouteTest(RouteBuilder builder, Exchange e, Map<String, Object> headers) throws Exception {
    CamelContext context = new DefaultCamelContext();
    try {
        context.addRoutes(builder);
        context.start();
        MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
        mock.setExpectedMessageCount(1);
        ProducerTemplate template = context.createProducerTemplate();
        if (e != null) {
            template.send("direct:in", e);
        } else {
            template.sendBodyAndHeaders("direct:in", payload, headers);
        }
        assertMockEndpointsSatisfied();
        return mock.getReceivedExchanges().get(0);
    } finally {
        context.stop();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) 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