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);
}
}
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()");
}
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()");
}
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();
}
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();
}
Aggregations