Search in sources :

Example 1 with InterceptEndpointProcessor

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);
}
Also used : InterceptSendToEndpoint(org.apache.camel.impl.InterceptSendToEndpoint) InterceptEndpointProcessor(org.apache.camel.processor.InterceptEndpointProcessor) Processor(org.apache.camel.Processor) InterceptSendToEndpoint(org.apache.camel.impl.InterceptSendToEndpoint) Endpoint(org.apache.camel.Endpoint) EndpointStrategy(org.apache.camel.spi.EndpointStrategy) InterceptEndpointProcessor(org.apache.camel.processor.InterceptEndpointProcessor)

Example 2 with InterceptEndpointProcessor

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);
        }
    }
}
Also used : InterceptEndpointProcessor(org.apache.camel.processor.InterceptEndpointProcessor) Processor(org.apache.camel.Processor) Channel(org.apache.camel.Channel) DefaultChannel(org.apache.camel.processor.interceptor.DefaultChannel) InterceptEndpointProcessor(org.apache.camel.processor.InterceptEndpointProcessor)

Aggregations

Processor (org.apache.camel.Processor)2 InterceptEndpointProcessor (org.apache.camel.processor.InterceptEndpointProcessor)2 Channel (org.apache.camel.Channel)1 Endpoint (org.apache.camel.Endpoint)1 InterceptSendToEndpoint (org.apache.camel.impl.InterceptSendToEndpoint)1 DefaultChannel (org.apache.camel.processor.interceptor.DefaultChannel)1 EndpointStrategy (org.apache.camel.spi.EndpointStrategy)1