Search in sources :

Example 6 with FluentProducerTemplate

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

the class FluentProducerTemplateAutoRegisterTest method testHasFluentTemplate.

@Test
public void testHasFluentTemplate() {
    assertNotNull("Should have injected a fluent producer template", template);
    FluentProducerTemplate lookup = context.getRegistry().lookupByNameAndType("fluentTemplate", FluentProducerTemplate.class);
    assertNotNull("Should lookup fluent producer template", lookup);
}
Also used : FluentProducerTemplate(org.apache.camel.FluentProducerTemplate) Test(org.junit.Test)

Example 7 with FluentProducerTemplate

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

the class FluentProducerTemplateTest method testFromCamelContext.

public void testFromCamelContext() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Bye World");
    FluentProducerTemplate fluent = context.createFluentProducerTemplate();
    Object result = fluent.withBody("Hello World").to("direct:in").request();
    assertMockEndpointsSatisfied();
    assertEquals("Bye World", result);
    assertSame(context, fluent.getCamelContext());
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) FluentProducerTemplate(org.apache.camel.FluentProducerTemplate)

Example 8 with FluentProducerTemplate

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

the class FluentProducerTemplateTest method testNoEndpoint.

public void testNoEndpoint() throws Exception {
    FluentProducerTemplate fluent = context.createFluentProducerTemplate();
    try {
        fluent.withBody("Hello World").send();
        fail("Should have thrown exception");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        fluent.withBody("Hello World").request();
        fail("Should have thrown exception");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : FluentProducerTemplate(org.apache.camel.FluentProducerTemplate)

Example 9 with FluentProducerTemplate

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

the class CamelPostProcessorHelper method createInjectionFluentProducerTemplate.

/**
     * Factory method to create a
     * {@link org.apache.camel.FluentProducerTemplate} to be injected into a
     * POJO
     */
protected FluentProducerTemplate createInjectionFluentProducerTemplate(String endpointUri, String endpointRef, String endpointProperty, String injectionPointName, Object bean) {
    // endpoint is optional for this injection point
    Endpoint endpoint = getEndpointInjection(bean, endpointUri, endpointRef, endpointProperty, injectionPointName, false);
    CamelContext context = endpoint != null ? endpoint.getCamelContext() : getCamelContext();
    FluentProducerTemplate answer = new DefaultFluentProducerTemplate(context);
    answer.setDefaultEndpoint(endpoint);
    // start the template so its ready to use
    try {
        // no need to defer the template as it can adjust to the endpoint at runtime
        startService(answer, context, bean, null);
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
    return answer;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultFluentProducerTemplate(org.apache.camel.builder.DefaultFluentProducerTemplate) Endpoint(org.apache.camel.Endpoint) DefaultFluentProducerTemplate(org.apache.camel.builder.DefaultFluentProducerTemplate) FluentProducerTemplate(org.apache.camel.FluentProducerTemplate) NoSuchBeanException(org.apache.camel.NoSuchBeanException) ProxyInstantiationException(org.apache.camel.ProxyInstantiationException)

Aggregations

FluentProducerTemplate (org.apache.camel.FluentProducerTemplate)9 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)5 CamelContext (org.apache.camel.CamelContext)2 Endpoint (org.apache.camel.Endpoint)2 InjectionException (javax.enterprise.inject.InjectionException)1 UnsatisfiedResolutionException (javax.enterprise.inject.UnsatisfiedResolutionException)1 Exchange (org.apache.camel.Exchange)1 NoSuchBeanException (org.apache.camel.NoSuchBeanException)1 ProxyInstantiationException (org.apache.camel.ProxyInstantiationException)1 DefaultFluentProducerTemplate (org.apache.camel.builder.DefaultFluentProducerTemplate)1 Test (org.junit.Test)1