Search in sources :

Example 1 with FromDefinition

use of org.apache.camel.model.FromDefinition 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)

Example 2 with FromDefinition

use of org.apache.camel.model.FromDefinition 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 3 with FromDefinition

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

the class AdviceWithTasks method replaceFromWith.

public static AdviceWithTask replaceFromWith(final RouteDefinition route, final String uri) {
    return new AdviceWithTask() {

        public void task() throws Exception {
            FromDefinition from = route.getInputs().get(0);
            LOG.info("AdviceWith replace input from [{}] --> [{}]", from.getUriOrRef(), uri);
            from.setEndpoint(null);
            from.setRef(null);
            from.setUri(uri);
        }
    };
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition)

Example 4 with FromDefinition

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

the class AdviceWithTasks method replaceFrom.

public static AdviceWithTask replaceFrom(final RouteDefinition route, final Endpoint endpoint) {
    return new AdviceWithTask() {

        public void task() throws Exception {
            FromDefinition from = route.getInputs().get(0);
            LOG.info("AdviceWith replace input from [{}] --> [{}]", from.getUriOrRef(), endpoint.getEndpointUri());
            from.setRef(null);
            from.setUri(null);
            from.setEndpoint(endpoint);
        }
    };
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition)

Example 5 with FromDefinition

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

the class RouteIdFactory method extractIdFromInput.

/**
     * Extract id from rest input uri.
     */
private Optional<String> extractIdFromInput(RouteDefinition route) {
    List<FromDefinition> inputs = route.getInputs();
    if (inputs == null || inputs.isEmpty()) {
        return Optional.empty();
    }
    FromDefinition from = inputs.get(0);
    String uri = from.getUri();
    String[] uriSplitted = uri.split(":");
    // needs to have at least 3 fields
    if (uriSplitted.length < 3) {
        return Optional.empty();
    }
    String verb = uriSplitted[1];
    String contextPath = uriSplitted[2];
    String additionalUri = "";
    if (uriSplitted.length > 3 && uriSplitted[3].startsWith("/")) {
        additionalUri = uriSplitted[3];
    }
    StringBuilder routeId = new StringBuilder(verb.length() + contextPath.length() + additionalUri.length());
    routeId.append(verb);
    appendWithSeparator(routeId, prepareUri(contextPath));
    if (additionalUri.length() > 0) {
        appendWithSeparator(routeId, prepareUri(additionalUri));
    }
    return Optional.of(routeId.toString());
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition)

Aggregations

FromDefinition (org.apache.camel.model.FromDefinition)16 RouteDefinition (org.apache.camel.model.RouteDefinition)10 ModelCamelContext (org.apache.camel.model.ModelCamelContext)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ChoiceDefinition (org.apache.camel.model.ChoiceDefinition)2 InterceptFromDefinition (org.apache.camel.model.InterceptFromDefinition)2 LogDefinition (org.apache.camel.model.LogDefinition)2 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)2 WhenDefinition (org.apache.camel.model.WhenDefinition)2 RestDefinition (org.apache.camel.model.rest.RestDefinition)2 RestConfiguration (org.apache.camel.spi.RestConfiguration)2 FabricService (io.fabric8.api.FabricService)1 Profile (io.fabric8.api.Profile)1 IOException (java.io.IOException)1 URI (java.net.URI)1 LinkedHashMap (java.util.LinkedHashMap)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1