Search in sources :

Example 1 with Processor

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

the class XmlErrorHandlerFactoryBean method setProperties.

private void setProperties(DefaultErrorHandlerBuilder builder) throws Exception {
    if (nonNull(handler.getDeadLetterHandleNewException())) {
        builder.setDeadLetterHandleNewException(handler.getDeadLetterHandleNewException());
    }
    builder.setDeadLetterUri(handler.getDeadLetterUri());
    builder.setExecutorServiceRef(handler.getExecutorServiceRef());
    builder.setRetryWhileRef(handler.getRetryWhileRef());
    if (nonNull(handler.getUseOriginalMessage())) {
        builder.setUseOriginalMessage(handler.getUseOriginalMessage());
    }
    if (isNotEmpty(handler.getOnExceptionOccurredRef())) {
        Processor processor = getReferenceByName(manager, handler.getOnExceptionOccurredRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onExceptionOccurredRef")));
        builder.setOnExceptionOccurred(processor);
    }
    if (isNotEmpty(handler.getOnPrepareFailureRef())) {
        Processor processor = getReferenceByName(manager, handler.getOnPrepareFailureRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onPrepareFailureRef")));
        builder.setOnPrepareFailure(processor);
    }
    if (isNotEmpty(handler.getOnRedeliveryRef())) {
        Processor processor = getReferenceByName(manager, handler.getOnRedeliveryRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onRedeliveryRef")));
        builder.setOnRedelivery(processor);
    }
    if (nonNull(handler.getRedeliveryPolicy())) {
        RedeliveryPolicyFactoryBean policy = handler.getRedeliveryPolicy();
        policy.setBeanManager(manager);
        builder.setRedeliveryPolicy(policy.getObject());
    }
    if (isNotEmpty(handler.getRedeliveryPolicyRef())) {
        RedeliveryPolicy policy = getReferenceByName(manager, handler.getRedeliveryPolicyRef(), RedeliveryPolicy.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getRedeliveryPolicyRef(), "redeliveryPolicyRef")));
        builder.setRedeliveryPolicy(policy);
    }
}
Also used : Processor(org.apache.camel.Processor) RedeliveryPolicyFactoryBean(org.apache.camel.cdi.xml.RedeliveryPolicyFactoryBean) RedeliveryPolicy(org.apache.camel.processor.RedeliveryPolicy) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException)

Example 2 with Processor

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

the class CacheBasedTokenReplacerTest method testCacheBasedTokenReplacer.

@Test
public void testCacheBasedTokenReplacer() throws Exception {
    log.debug("Beginning Test ---> testCacheBasedTokenReplacer()");
    resultEndpoint.expectedMessageCount(1);
    List<String> keys = new ArrayList<String>();
    keys.add("novel");
    keys.add("author");
    keys.add("number");
    keys.add("quote");
    for (final String key : keys) {
        producerTemplate.send(new Processor() {

            public void process(Exchange exchange) throws Exception {
                exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
                Message in = exchange.getIn();
                in.setHeader(CacheConstants.CACHE_OPERATION, CacheConstants.CACHE_OPERATION_ADD);
                in.setHeader(CacheConstants.CACHE_KEY, key);
                if (key.equalsIgnoreCase("novel")) {
                    in.setBody("Rubaiyat");
                } else if (key.equalsIgnoreCase("author")) {
                    in.setBody("Omar Khayyam");
                } else if (key.equalsIgnoreCase("number")) {
                    in.setBody("one");
                } else {
                    in.setBody(quote);
                }
            }
        });
    }
    resultEndpoint.assertIsSatisfied();
    log.debug("Completed Test ---> testCacheBasedTokenReplacer()");
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Example 3 with Processor

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

the class CacheBasedXPathElementReplacerTest method testCacheBasedXPathElementReplacer.

@Test
public void testCacheBasedXPathElementReplacer() throws Exception {
    log.debug("Beginning Test ---> testCacheBasedXPathElementReplacer()");
    resultEndpoint.expectedMessageCount(1);
    List<String> keys = new ArrayList<String>();
    keys.add("book1");
    keys.add("book2");
    keys.add("XML_FRAGMENT");
    for (final String key : keys) {
        producerTemplate.send(new Processor() {

            public void process(Exchange exchange) throws Exception {
                exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
                Message in = exchange.getIn();
                in.setHeader(CacheConstants.CACHE_OPERATION, CacheConstants.CACHE_OPERATION_ADD);
                in.setHeader(CacheConstants.CACHE_KEY, key);
                if (key.equalsIgnoreCase("book1")) {
                    in.setBody(book1);
                } else if (key.equalsIgnoreCase("book2")) {
                    in.setBody(book2);
                } else {
                    in.setBody(xmlFragment);
                }
            }
        });
    }
    resultEndpoint.assertIsSatisfied();
    log.debug("Completed Test ---> testCacheBasedXPathElementReplacer()");
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Example 4 with Processor

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

the class CassandraComponentConsumerTest method testConsumeAll.

@Test
public void testConsumeAll() throws Exception {
    if (!canTest()) {
        return;
    }
    MockEndpoint mock = getMockEndpoint("mock:resultAll");
    mock.expectedMinimumMessageCount(1);
    mock.whenAnyExchangeReceived(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Object body = exchange.getIn().getBody();
            assertTrue(body instanceof List);
        }
    });
    mock.await(1, TimeUnit.SECONDS);
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) List(java.util.List) Test(org.junit.Test)

Example 5 with Processor

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

the class CassandraComponentConsumerTest method testConsumeOne.

@Test
public void testConsumeOne() throws Exception {
    if (!canTest()) {
        return;
    }
    MockEndpoint mock = getMockEndpoint("mock:resultOne");
    mock.expectedMinimumMessageCount(1);
    mock.whenAnyExchangeReceived(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Object body = exchange.getIn().getBody();
            assertTrue(body instanceof Row);
        }
    });
    mock.await(1, TimeUnit.SECONDS);
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Aggregations

Processor (org.apache.camel.Processor)1467 Exchange (org.apache.camel.Exchange)1368 Test (org.junit.Test)634 RouteBuilder (org.apache.camel.builder.RouteBuilder)543 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)164 Message (org.apache.camel.Message)119 ArrayList (java.util.ArrayList)65 HashMap (java.util.HashMap)64 IOException (java.io.IOException)55 CamelExecutionException (org.apache.camel.CamelExecutionException)52 Endpoint (org.apache.camel.Endpoint)46 Map (java.util.Map)45 File (java.io.File)38 List (java.util.List)34 Producer (org.apache.camel.Producer)33 DefaultExchange (org.apache.camel.impl.DefaultExchange)29 SendProcessor (org.apache.camel.processor.SendProcessor)26 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)26 CountDownLatch (java.util.concurrent.CountDownLatch)24 Expression (org.apache.camel.Expression)24