use of org.apache.camel.spi.Policy in project camel by apache.
the class TransactedDefinition method createProcessor.
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
Policy policy = resolvePolicy(routeContext);
ObjectHelper.notNull(policy, "policy", this);
// before wrap
policy.beforeWrap(routeContext, this);
// create processor after the before wrap
Processor childProcessor = this.createChildProcessor(routeContext, true);
// wrap
Processor target = policy.wrap(routeContext, childProcessor);
if (!(target instanceof Service)) {
// wrap the target so it becomes a service and we can manage its lifecycle
target = new WrapProcessor(target, childProcessor);
}
return target;
}
use of org.apache.camel.spi.Policy in project camel by apache.
the class QueueToProcessorTransactionTest method testRollbackUsingXmlQueueToProcessor.
@Test
public void testRollbackUsingXmlQueueToProcessor() throws Exception {
// configure routes and add to camel context
context.addRoutes(new SpringRouteBuilder() {
@Override
public void configure() throws Exception {
Policy required = lookup("PROPAGATION_REQUIRED_POLICY", SpringTransactionPolicy.class);
from("activemq:queue:foo").policy(required).process(new ConditionalExceptionProcessor());
}
});
assertResult();
}
use of org.apache.camel.spi.Policy in project camel by apache.
the class QueueToQueueRequestReplyTransactionTest method testRollbackUsingXmlQueueToQueueRequestReplyUsingDynamicMessageSelector.
@Test
public void testRollbackUsingXmlQueueToQueueRequestReplyUsingDynamicMessageSelector() throws Exception {
final ConditionalExceptionProcessor cp = new ConditionalExceptionProcessor(5);
context.addRoutes(new SpringRouteBuilder() {
@Override
public void configure() throws Exception {
Policy required = lookup("PROPAGATION_REQUIRED_POLICY", SpringTransactionPolicy.class);
from("activemq:queue:foo").policy(required).process(cp).to("activemq-1:queue:bar?replyTo=queue:bar.reply");
from("activemq-1:queue:bar").process(new Processor() {
public void process(Exchange e) {
String request = e.getIn().getBody(String.class);
Message out = e.getOut();
String selectorValue = e.getIn().getHeader("camelProvider", String.class);
if (selectorValue != null) {
out.setHeader("camelProvider", selectorValue);
}
out.setBody("Re: " + request);
}
});
}
});
for (int i = 0; i < 5; ++i) {
Object reply = template.requestBody("activemq:queue:foo", "blah" + i);
assertTrue("Received unexpeced reply", reply.equals("Re: blah" + i));
assertTrue(cp.getErrorMessage(), cp.getErrorMessage() == null);
}
}
use of org.apache.camel.spi.Policy in project camel by apache.
the class QueueToQueueTransactionTest method testRollbackUsingXmlQueueToQueue.
@Test
public void testRollbackUsingXmlQueueToQueue() throws Exception {
// configure routes and add to camel context
context.addRoutes(new SpringRouteBuilder() {
@Override
public void configure() throws Exception {
Policy required = lookup("PROPAGATION_REQUIRED_POLICY", SpringTransactionPolicy.class);
from("activemq:queue:foo?transacted=true").policy(required).process(new ConditionalExceptionProcessor()).to("activemq:queue:bar?transacted=true");
}
});
assertResult();
}
use of org.apache.camel.spi.Policy in project camel by apache.
the class PolicyDefinition method createProcessor.
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
Policy policy = resolvePolicy(routeContext);
ObjectHelper.notNull(policy, "policy", this);
// before wrap
policy.beforeWrap(routeContext, this);
// create processor after the before wrap
Processor childProcessor = this.createChildProcessor(routeContext, true);
// wrap
Processor target = policy.wrap(routeContext, childProcessor);
if (!(target instanceof Service)) {
// wrap the target so it becomes a service and we can manage its lifecycle
target = new WrapProcessor(target, childProcessor);
}
return target;
}
Aggregations