use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class JdbcMessageIdRepositoryTest method testFailedExchangesNotAdded.
@Test
public void testFailedExchangesNotAdded() throws Exception {
RouteBuilder interceptor = new RouteBuilder(context) {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:result").process(new Processor() {
public void process(Exchange exchange) throws Exception {
String id = exchange.getIn().getHeader("messageId", String.class);
if (id.equals("2")) {
throw new IllegalArgumentException("Damn I cannot handle id 2");
}
}
});
}
};
RouteDefinition routeDefinition = context.getRouteDefinition("JdbcMessageIdRepositoryTest");
routeDefinition.adviceWith(context, interceptor);
// we send in 2 messages with id 2 that fails
errorEndpoint.expectedMessageCount(2);
resultEndpoint.expectedBodiesReceived("one", "three");
template.sendBodyAndHeader("direct:start", "one", "messageId", "1");
template.sendBodyAndHeader("direct:start", "two", "messageId", "2");
template.sendBodyAndHeader("direct:start", "one", "messageId", "1");
template.sendBodyAndHeader("direct:start", "two", "messageId", "2");
template.sendBodyAndHeader("direct:start", "one", "messageId", "1");
template.sendBodyAndHeader("direct:start", "three", "messageId", "3");
assertMockEndpointsSatisfied();
jdbcTemplate.update(CLEAR_STRING, PROCESSOR_NAME);
// only message 1 and 3 should be in jdbc repo
List<String> receivedMessageIds = jdbcTemplate.queryForList(SELECT_ALL_STRING, String.class, PROCESSOR_NAME);
assertEquals(0, receivedMessageIds.size());
assertFalse("Should not contain message 1", receivedMessageIds.contains("1"));
assertFalse("Should not contain message 3", receivedMessageIds.contains("3"));
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class OnExceptionRouteIdTest method testOnExceptionRouteId.
@Test
public void testOnExceptionRouteId() throws Exception {
getMockEndpoint("mock:error").expectedMessageCount(0);
getMockEndpoint("mock:foo").expectedMessageCount(1);
template.sendBody("direct:foo", "Hello World");
assertMockEndpointsSatisfied();
RouteDefinition route = context.getRouteDefinition("foo");
assertNotNull(route);
assertEquals("foo", route.getId());
}
use of org.apache.camel.model.RouteDefinition in project ddf by codice.
the class ContentDirectoryMonitor method destroy.
/**
* Invoked when a configuration is destroyed from the container.
* <p>
* Only remove routes that this Content Directory Monitor created since the same CamelContext
* is shared across all Content Directory Monitors.
*/
public void destroy(int code) {
List<RouteDefinition> routeDefinitions = new ArrayList<>(camelContext.getRouteDefinitions());
for (RouteDefinition routeDef : routeDefinitions) {
try {
String routeId = routeDef.getId();
if (isMyRoute(routeId)) {
LOGGER.trace("Stopping route with ID = {} and path {}", routeId, monitoredDirectory);
camelContext.stopRoute(routeId);
boolean status = camelContext.removeRoute(routeId);
LOGGER.trace("Status of removing route {} is {}", routeId, status);
camelContext.removeRouteDefinition(routeDef);
}
} catch (Exception e) {
LOGGER.debug("Unable to stop Camel route with route ID = {}", routeDef.getId(), e);
}
}
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class AbstractLocalCamelController method getRouteModelAsXml.
public String getRouteModelAsXml(String routeId, String camelContextName) throws Exception {
CamelContext context = this.getLocalCamelContext(camelContextName);
if (context == null) {
return null;
}
RouteDefinition route = context.getRouteDefinition(routeId);
if (route == null) {
return null;
}
return ModelHelper.dumpModelAsXml(null, route);
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class CustomIdIssuesTest method testCustomId.
@Test
public void testCustomId() {
RouteDefinition route = context.getRouteDefinition("myRoute");
assertNotNull(route);
assertTrue(route.hasCustomIdAssigned());
FromDefinition from = route.getInputs().get(0);
assertEquals("fromFile", from.getId());
assertTrue(from.hasCustomIdAssigned());
ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
assertEquals("myChoice", choice.getId());
assertTrue(choice.hasCustomIdAssigned());
WhenDefinition when = choice.getWhenClauses().get(0);
assertTrue(when.hasCustomIdAssigned());
assertEquals("UK", when.getId());
LogDefinition log = (LogDefinition) choice.getOtherwise().getOutputs().get(0);
assertFalse(log.hasCustomIdAssigned());
}
Aggregations