Search in sources :

Example 1 with ProducerTemplate

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

the class CdiCamelFactory method producerTemplateFromUri.

private static ProducerTemplate producerTemplateFromUri(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension, Uri uri) {
    try {
        CamelContext context = uri.context().isEmpty() ? selectContext(ip, instance, extension) : selectContext(uri.context(), instance);
        ProducerTemplate producerTemplate = context.createProducerTemplate();
        Endpoint endpoint = context.getEndpoint(uri.value(), Endpoint.class);
        producerTemplate.setDefaultEndpoint(endpoint);
        return producerTemplate;
    } catch (Exception cause) {
        throw new InjectionException("Error injecting producer template annotated with " + uri + " into " + ip, cause);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) InjectionException(javax.enterprise.inject.InjectionException) FluentProducerTemplate(org.apache.camel.FluentProducerTemplate) ProducerTemplate(org.apache.camel.ProducerTemplate) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) InjectionException(javax.enterprise.inject.InjectionException)

Example 2 with ProducerTemplate

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

the class ProgrammaticLookupTest method sendMessageToInbound.

@Test
public void sendMessageToInbound() throws InterruptedException {
    ProducerTemplate inbound = producers.select(Uri.Literal.of("direct:inbound")).get();
    MockEndpoint outbound = endpoints.select(MockEndpoint.class, Uri.Literal.of("mock:outbound")).get();
    outbound.expectedMessageCount(1);
    outbound.expectedBodiesReceived("test");
    inbound.sendBody("test");
    assertIsSatisfied(2L, TimeUnit.SECONDS, outbound);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 3 with ProducerTemplate

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

the class ECDSASignatureTest 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 : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 4 with ProducerTemplate

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

the class SignatureTests 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 5 with ProducerTemplate

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

the class CxfEndpointBeansRouterTest method testCxfBusConfiguration.

@Test
public void testCxfBusConfiguration() throws Exception {
    // get the camelContext from application context
    CamelContext camelContext = ctx.getBean("camel", CamelContext.class);
    ProducerTemplate template = camelContext.createProducerTemplate();
    Exchange reply = template.request("cxf:bean:serviceEndpoint", new Processor() {

        public void process(final Exchange exchange) {
            final List<String> params = new ArrayList<String>();
            params.add("hello");
            exchange.getIn().setBody(params);
            exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "echo");
        }
    });
    Exception ex = reply.getException();
    assertTrue("Should get the fault here", ex instanceof org.apache.cxf.interceptor.Fault || ex instanceof HTTPException);
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) HTTPException(org.apache.cxf.transport.http.HTTPException) ArrayList(java.util.ArrayList) List(java.util.List) HTTPException(org.apache.cxf.transport.http.HTTPException) Test(org.junit.Test)

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