Search in sources :

Example 36 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class InlinedProcessorIdTest method testInlinedProcessorId.

public void testInlinedProcessorId() throws Exception {
    getMockEndpoint("mock:result").expectedHeaderReceived("foo", 123);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    // check ids
    RouteDefinition route = context.getRouteDefinition("foo");
    assertEquals("foo", route.getId());
    assertEquals(3, route.getOutputs().size());
    assertEquals("log", route.getOutputs().get(0).getId());
    assertEquals("inlined", route.getOutputs().get(1).getId());
    assertEquals("result", route.getOutputs().get(2).getId());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition)

Example 37 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class HttpInterceptSendToEndpointTest method testHttpInterceptSendToEndpoint.

@Test
public void testHttpInterceptSendToEndpoint() throws Exception {
    RouteDefinition route = context.getRouteDefinitions().get(0);
    route.adviceWith(context, new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("http*").to("mock:http").skipSendToOriginalEndpoint();
        }
    });
    getMockEndpoint("mock:http").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test)

Example 38 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class SpringScheduledRoutePolicyTest method startRouteWithPolicy.

@SuppressWarnings("unchecked")
private CamelContext startRouteWithPolicy(String policyBeanName) throws Exception {
    CamelContext context = new DefaultCamelContext();
    List<RouteDefinition> routes = (List<RouteDefinition>) applicationContext.getBean("testRouteContext");
    RoutePolicy policy = applicationContext.getBean(policyBeanName, RoutePolicy.class);
    assertTrue(getTestType() == TestType.SIMPLE ? policy instanceof SimpleScheduledRoutePolicy : policy instanceof CronScheduledRoutePolicy);
    routes.get(0).routePolicy(policy);
    ((ModelCamelContext) context).addRouteDefinitions(routes);
    context.start();
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) ModelCamelContext(org.apache.camel.model.ModelCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteDefinition(org.apache.camel.model.RouteDefinition) List(java.util.List) RoutePolicy(org.apache.camel.spi.RoutePolicy) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ModelCamelContext(org.apache.camel.model.ModelCamelContext)

Example 39 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class RoutesCollector method loadXmlRests.

private void loadXmlRests(ApplicationContext applicationContext, CamelContext camelContext, String directory) {
    LOG.info("Loading additional Camel XML rests from: {}", directory);
    try {
        final Resource[] xmlRests = applicationContext.getResources(directory);
        for (final Resource xmlRest : xmlRests) {
            final RestsDefinition xmlDefinitions = camelContext.loadRestsDefinition(xmlRest.getInputStream());
            camelContext.addRestDefinitions(xmlDefinitions.getRests());
            for (final RestDefinition xmlDefinition : xmlDefinitions.getRests()) {
                final List<RouteDefinition> routeDefinitions = xmlDefinition.asRouteDefinition(camelContext);
                camelContext.addRouteDefinitions(routeDefinitions);
            }
        }
    } catch (FileNotFoundException e) {
        LOG.debug("No XML rests found in {}. Skipping XML rests detection.", directory);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : RestDefinition(org.apache.camel.model.rest.RestDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) Resource(org.springframework.core.io.Resource) RestsDefinition(org.apache.camel.model.rest.RestsDefinition) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException)

Example 40 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class CustomIdIssuesTest method testCustomId.

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());
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) ChoiceDefinition(org.apache.camel.model.ChoiceDefinition) LogDefinition(org.apache.camel.model.LogDefinition) WhenDefinition(org.apache.camel.model.WhenDefinition)

Aggregations

RouteDefinition (org.apache.camel.model.RouteDefinition)102 AdviceWithRouteBuilder (org.apache.camel.builder.AdviceWithRouteBuilder)17 RouteBuilder (org.apache.camel.builder.RouteBuilder)17 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 FromDefinition (org.apache.camel.model.FromDefinition)9 HashMap (java.util.HashMap)6 Processor (org.apache.camel.Processor)6 ConnectException (java.net.ConnectException)5 Exchange (org.apache.camel.Exchange)5 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)5 IOException (java.io.IOException)4 Map (java.util.Map)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 ChoiceDefinition (org.apache.camel.model.ChoiceDefinition)4 HystrixConfigurationDefinition (org.apache.camel.model.HystrixConfigurationDefinition)4 HystrixDefinition (org.apache.camel.model.HystrixDefinition)4 LogDefinition (org.apache.camel.model.LogDefinition)4 ModelCamelContext (org.apache.camel.model.ModelCamelContext)4