use of org.apache.camel.processor.InterceptEndpointProcessor in project camel by apache.
the class InterceptSendToEndpointDefinition method createProcessor.
@Override
public Processor createProcessor(final RouteContext routeContext) throws Exception {
// create the detour
final Processor detour = this.createChildProcessor(routeContext, true);
final String matchURI = getUri();
// register endpoint callback so we can proxy the endpoint
routeContext.getCamelContext().addRegisterEndpointCallback(new EndpointStrategy() {
public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
if (endpoint instanceof InterceptSendToEndpoint) {
// endpoint already decorated
return endpoint;
} else if (matchURI == null || matchPattern(routeContext.getCamelContext(), uri, matchURI)) {
// only proxy if the uri is matched decorate endpoint with our proxy
// should be false by default
boolean skip = getSkipSendToOriginalEndpoint() != null && getSkipSendToOriginalEndpoint();
InterceptSendToEndpoint proxy = new InterceptSendToEndpoint(endpoint, skip);
proxy.setDetour(detour);
return proxy;
} else {
// no proxy so return regular endpoint
return endpoint;
}
}
});
// remove the original intercepted route from the outputs as we do not intercept as the regular interceptor
// instead we use the proxy endpoints producer do the triggering. That is we trigger when someone sends
// an exchange to the endpoint, see InterceptSendToEndpoint for details.
RouteDefinition route = routeContext.getRoute();
List<ProcessorDefinition<?>> outputs = route.getOutputs();
outputs.remove(this);
return new InterceptEndpointProcessor(matchURI, detour);
}
use of org.apache.camel.processor.InterceptEndpointProcessor in project camel by apache.
the class ProcessorDefinition method addRoutes.
public void addRoutes(RouteContext routeContext, Collection<Route> routes) throws Exception {
Processor processor = makeProcessor(routeContext);
if (processor == null) {
// no processor to add
return;
}
if (!routeContext.isRouteAdded()) {
boolean endpointInterceptor = false;
// processor as we use the producer to trigger the interceptor
if (processor instanceof Channel) {
Channel channel = (Channel) processor;
Processor next = channel.getNextProcessor();
if (next instanceof InterceptEndpointProcessor) {
endpointInterceptor = true;
}
}
// only add regular processors as event driven
if (endpointInterceptor) {
log.debug("Endpoint interceptor should not be added as an event driven consumer route: {}", processor);
} else {
log.trace("Adding event driven processor: {}", processor);
routeContext.addEventDrivenProcessor(processor);
}
}
}
Aggregations