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