protected URI selectDispatchUri(RouteboxEndpoint endpoint, Exchange exchange) throws Exception {
URI dispatchUri;
List<URI> consumerUris = getInnerContextConsumerList(endpoint.getConfig().getInnerContext());
if (consumerUris.isEmpty()) {
throw new CamelExchangeException("No routes found to dispatch in Routebox at " + endpoint, exchange);
} else if (consumerUris.size() == 1) {
dispatchUri = consumerUris.get(0);
} else {
if (!endpoint.getConfig().getDispatchMap().isEmpty()) {
// apply URI string found in dispatch Map
String key = exchange.getIn().getHeader("ROUTE_DISPATCH_KEY", String.class);
if (endpoint.getConfig().getDispatchMap().containsKey(key)) {
dispatchUri = new URI(endpoint.getConfig().getDispatchMap().get(key));
} else {
throw new CamelExchangeException("No matching entry found in Dispatch Map for ROUTE_DISPATCH_KEY: " + key, exchange);
}
} else {
// apply dispatch strategy
dispatchUri = endpoint.getConfig().getDispatchStrategy().selectDestinationUri(consumerUris, exchange);
if (dispatchUri == null) {
throw new CamelExchangeException("No matching inner routes found for Operation", exchange);
}
}
}
if (LOG.isDebugEnabled()) {