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