Search in sources :

Example 1 with SendDefinition

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

the class CamelNamespaceHandler method registerEndpointsWithIdsDefinedInFromOrToTypes.

/**
     * Used for auto registering endpoints from the <tt>from</tt> or <tt>to</tt> DSL if they have an id attribute set
     */
protected void registerEndpointsWithIdsDefinedInFromOrToTypes(Element element, ParserContext parserContext, String contextId, Binder<Node> binder) {
    NodeList list = element.getChildNodes();
    int size = list.getLength();
    for (int i = 0; i < size; i++) {
        Node child = list.item(i);
        if (child instanceof Element) {
            Element childElement = (Element) child;
            Object object = binder.getJAXBNode(child);
            // we only want from/to types to be registered as endpoints
            if (object instanceof FromDefinition || object instanceof SendDefinition) {
                registerEndpoint(childElement, parserContext, contextId);
            }
            // recursive
            registerEndpointsWithIdsDefinedInFromOrToTypes(childElement, parserContext, contextId, binder);
        }
    }
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition) SendDefinition(org.apache.camel.model.SendDefinition) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 2 with SendDefinition

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

the class SimpleProcessorIdAwareTest method testIdAware.

public void testIdAware() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    List<Processor> matches = context.getRoute("foo").filter("b*");
    assertEquals(2, matches.size());
    Processor bar = matches.get(0);
    Processor baz = matches.get(1);
    assertEquals("bar", ((IdAware) bar).getId());
    assertEquals("baz", ((IdAware) baz).getId());
    bar = context.getProcessor("bar");
    assertNotNull(bar);
    baz = context.getProcessor("baz");
    assertNotNull(baz);
    Processor unknown = context.getProcessor("unknown");
    assertNull(unknown);
    Processor result = context.getProcessor("result");
    assertNotNull(result);
    ProcessorDefinition def = context.getProcessorDefinition("result");
    assertNotNull(def);
    assertEquals("result", def.getId());
    SendDefinition send = assertIsInstanceOf(SendDefinition.class, def);
    assertNotNull(send);
    assertEquals("mock:result", send.getEndpointUri());
}
Also used : Processor(org.apache.camel.Processor) SendDefinition(org.apache.camel.model.SendDefinition) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition)

Example 3 with SendDefinition

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

the class RandomLoadBalanceJavaDSLBuilderTest method navigateDefinition.

private void navigateDefinition(ProcessorDefinition<?> def, StringBuilder sb) {
    // must do this ugly cast to avoid compiler error on HP-UX
    ProcessorDefinition<?> defn = (ProcessorDefinition<?>) def;
    if (defn instanceof LoadBalanceDefinition) {
        sb.append(".loadBalance()");
        LoadBalanceDefinition lbd = (LoadBalanceDefinition) defn;
        LoadBalancer balancer = lbd.getLoadBalancerType().getLoadBalancer(null);
        if (balancer instanceof RandomLoadBalancer) {
            sb.append(".random()");
        }
    }
    if (defn instanceof SendDefinition) {
        SendDefinition<?> send = (SendDefinition<?>) defn;
        sb.append(".to(\"" + send.getUri() + "\")");
    }
    List<ProcessorDefinition<?>> children = defn.getOutputs();
    if (children == null || children.isEmpty()) {
        return;
    }
    for (ProcessorDefinition<?> child : children) {
        navigateDefinition(child, sb);
    }
}
Also used : SendDefinition(org.apache.camel.model.SendDefinition) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) LoadBalanceDefinition(org.apache.camel.model.LoadBalanceDefinition) LoadBalancer(org.apache.camel.processor.loadbalancer.LoadBalancer) RandomLoadBalancer(org.apache.camel.processor.loadbalancer.RandomLoadBalancer) RandomLoadBalancer(org.apache.camel.processor.loadbalancer.RandomLoadBalancer)

Aggregations

SendDefinition (org.apache.camel.model.SendDefinition)3 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)2 Processor (org.apache.camel.Processor)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 FromDefinition (org.apache.camel.model.FromDefinition)1 LoadBalanceDefinition (org.apache.camel.model.LoadBalanceDefinition)1 LoadBalancer (org.apache.camel.processor.loadbalancer.LoadBalancer)1 RandomLoadBalancer (org.apache.camel.processor.loadbalancer.RandomLoadBalancer)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1