@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); }
public void addRegisterEndpointCallback(EndpointStrategy strategy) { if (!endpointStrategies.contains(strategy)) { // let it be invoked for already registered endpoints so it can catch-up. endpointStrategies.add(strategy); for (Endpoint endpoint : getEndpoints()) { Endpoint newEndpoint = strategy.registerEndpoint(endpoint.getEndpointUri(), endpoint); if (newEndpoint != null) { // put will replace existing endpoint with the new endpoint endpoints.put(getEndpointKey(endpoint.getEndpointUri()), newEndpoint); } } } }
/** * Strategy to add the given endpoint to the internal endpoint registry * * @param uri uri of the endpoint * @param endpoint the endpoint to add * @return the added endpoint */ protected Endpoint addEndpointToRegistry(String uri, Endpoint endpoint) { ObjectHelper.notEmpty(uri, "uri"); ObjectHelper.notNull(endpoint, "endpoint"); // if there is endpoint strategies, then use the endpoints they return // as this allows to intercept endpoints etc. for (EndpointStrategy strategy : endpointStrategies) { endpoint = strategy.registerEndpoint(uri, endpoint); } endpoints.put(getEndpointKey(uri, endpoint), endpoint); return endpoint; }
@Override public void addRegisterEndpointCallback(EndpointStrategy strategy) { context.addRegisterEndpointCallback(strategy); }
/** * Registers a {@link org.apache.camel.spi.EndpointStrategy callback} to allow you to do custom * logic when an {@link Endpoint} is about to be registered to the {@link org.apache.camel.spi.EndpointRegistry}. * <p/> * When a callback is added it will be executed on the already registered endpoints allowing you to catch-up * * @param strategy callback to be invoked */ void addRegisterEndpointCallback(EndpointStrategy strategy);