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