Search in sources :

Example 6 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 7 with FromDefinition

use of org.apache.camel.model.FromDefinition 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());
}
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) Test(org.junit.Test)

Example 8 with FromDefinition

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

the class XmlConfigTestSupport method assertValidContext.

protected void assertValidContext(CamelContext context) {
    assertNotNull("No context found!", context);
    List<RouteDefinition> routes = ((ModelCamelContext) context).getRouteDefinitions();
    LOG.debug("Found routes: " + routes);
    assertEquals("One Route should be found", 1, routes.size());
    for (RouteDefinition route : routes) {
        List<FromDefinition> inputs = route.getInputs();
        assertEquals("Number of inputs", 1, inputs.size());
        FromDefinition fromType = inputs.get(0);
        assertEquals("from URI", "seda:test.a", fromType.getUri());
        List<?> outputs = route.getOutputs();
        assertEquals("Number of outputs", 1, outputs.size());
    }
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) ModelCamelContext(org.apache.camel.model.ModelCamelContext)

Example 9 with FromDefinition

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

the class RouteboxDispatcher method getInnerContextConsumerList.

protected List<URI> getInnerContextConsumerList(CamelContext context) throws URISyntaxException {
    List<URI> consumerList = new ArrayList<URI>();
    List<RouteDefinition> routeDefinitions = context.getRouteDefinitions();
    for (RouteDefinition routeDefinition : routeDefinitions) {
        List<FromDefinition> inputs = routeDefinition.getInputs();
        for (FromDefinition input : inputs) {
            consumerList.add(new URI(input.getUri()));
        }
    }
    return consumerList;
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 10 with FromDefinition

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

the class DefaultCamelContext method explainEipJson.

public String explainEipJson(String nameOrId, boolean includeAllOptions) {
    try {
        // try to find the id within all known routes and their eips
        String eipName = nameOrId;
        NamedNode target = null;
        for (RouteDefinition route : getRouteDefinitions()) {
            if (route.getId().equals(nameOrId)) {
                target = route;
                break;
            }
            for (FromDefinition from : route.getInputs()) {
                if (nameOrId.equals(from.getId())) {
                    target = route;
                    break;
                }
            }
            Iterator<ProcessorDefinition> it = ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), ProcessorDefinition.class);
            while (it.hasNext()) {
                ProcessorDefinition def = it.next();
                if (nameOrId.equals(def.getId())) {
                    target = def;
                    break;
                }
            }
            if (target != null) {
                break;
            }
        }
        if (target != null) {
            eipName = target.getShortName();
        }
        String json = getEipParameterJsonSchema(eipName);
        if (json == null) {
            return null;
        }
        // overlay with runtime parameters that id uses at runtime
        if (target != null) {
            List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("properties", json, true);
            // selected rows to use for answer
            Map<String, String[]> selected = new LinkedHashMap<String, String[]>();
            // extract options from the node
            Map<String, Object> options = new LinkedHashMap<String, Object>();
            IntrospectionSupport.getProperties(target, options, "", false);
            // remove outputs which we do not want to include
            options.remove("outputs");
            // include other rows
            for (Map<String, String> row : rows) {
                String name = row.get("name");
                String kind = row.get("kind");
                String label = row.get("label");
                String required = row.get("required");
                String value = row.get("value");
                String defaultValue = row.get("defaultValue");
                String type = row.get("type");
                String javaType = row.get("javaType");
                String deprecated = row.get("deprecated");
                String description = row.get("description");
                // find the configured option
                Object o = options.get(name);
                if (o != null) {
                    value = o.toString();
                }
                value = URISupport.sanitizePath(value);
                if (includeAllOptions || o != null) {
                    // add as selected row
                    if (!selected.containsKey(name)) {
                        selected.put(name, new String[] { name, kind, label, required, type, javaType, deprecated, value, defaultValue, description });
                    }
                }
            }
            json = ObjectHelper.before(json, "  \"properties\": {");
            StringBuilder buffer = new StringBuilder("  \"properties\": {");
            boolean first = true;
            for (String[] row : selected.values()) {
                if (first) {
                    first = false;
                } else {
                    buffer.append(",");
                }
                buffer.append("\n    ");
                String name = row[0];
                String kind = row[1];
                String label = row[2];
                String required = row[3];
                String type = row[4];
                String javaType = row[5];
                String deprecated = row[6];
                String value = row[7];
                String defaultValue = row[8];
                String description = row[9];
                // add json of the option
                buffer.append(StringQuoteHelper.doubleQuote(name)).append(": { ");
                CollectionStringBuffer csb = new CollectionStringBuffer();
                if (kind != null) {
                    csb.append("\"kind\": \"" + kind + "\"");
                }
                if (label != null) {
                    csb.append("\"label\": \"" + label + "\"");
                }
                if (required != null) {
                    csb.append("\"required\": \"" + required + "\"");
                }
                if (type != null) {
                    csb.append("\"type\": \"" + type + "\"");
                }
                if (javaType != null) {
                    csb.append("\"javaType\": \"" + javaType + "\"");
                }
                if (deprecated != null) {
                    csb.append("\"deprecated\": \"" + deprecated + "\"");
                }
                if (value != null) {
                    csb.append("\"value\": \"" + value + "\"");
                }
                if (defaultValue != null) {
                    csb.append("\"defaultValue\": \"" + defaultValue + "\"");
                }
                if (description != null) {
                    csb.append("\"description\": \"" + description + "\"");
                }
                if (!csb.isEmpty()) {
                    buffer.append(csb.toString());
                }
                buffer.append(" }");
            }
            buffer.append("\n  }\n}\n");
            // insert the original first part of the json into the start of the buffer
            buffer.insert(0, json);
            return buffer.toString();
        }
        return json;
    } catch (Exception e) {
        // ignore and return empty response
        return null;
    }
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition) CollectionStringBuffer(org.apache.camel.util.CollectionStringBuffer) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) NamedNode(org.apache.camel.NamedNode) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MalformedObjectNameException(javax.management.MalformedObjectNameException) VetoCamelContextStartException(org.apache.camel.VetoCamelContextStartException) IOException(java.io.IOException) LoadPropertiesException(org.apache.camel.util.LoadPropertiesException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException) LinkedHashMap(java.util.LinkedHashMap) RouteDefinition(org.apache.camel.model.RouteDefinition) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

FromDefinition (org.apache.camel.model.FromDefinition)15 RouteDefinition (org.apache.camel.model.RouteDefinition)9 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 ModelCamelContext (org.apache.camel.model.ModelCamelContext)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 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 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 FailedToStartRouteException (org.apache.camel.FailedToStartRouteException)1