/** * Adapt the given interceptor object to the HandlerInterceptor interface. * <p>Supported interceptor types are HandlerInterceptor and WebRequestInterceptor. * Each given WebRequestInterceptor will be wrapped in a WebRequestHandlerInterceptorAdapter. * Can be overridden in subclasses. * @param interceptor the specified interceptor object * @return the interceptor wrapped as HandlerInterceptor * @see #setApplyWebRequestInterceptorsToRenderPhaseOnly * @see org.springframework.web.portlet.HandlerInterceptor * @see org.springframework.web.context.request.WebRequestInterceptor * @see WebRequestHandlerInterceptorAdapter */ protected HandlerInterceptor adaptInterceptor(Object interceptor) { if (interceptor instanceof HandlerInterceptor) { return (HandlerInterceptor) interceptor; } else if (interceptor instanceof WebRequestInterceptor) { return new WebRequestHandlerInterceptorAdapter( (WebRequestInterceptor) interceptor, this.applyWebRequestInterceptorsToRenderPhaseOnly); } else { throw new IllegalArgumentException("Interceptor type not supported: " + interceptor.getClass().getName()); } }
/** * Adds the provided {@link WebRequestInterceptor}. * @param interceptor the interceptor to add * @return An {@link InterceptorRegistration} that allows you optionally configure the * registered interceptor further for example adding URL patterns it should apply to. */ public InterceptorRegistration addWebRequestInterceptor(WebRequestInterceptor interceptor) { WebRequestHandlerInterceptorAdapter adapted = new WebRequestHandlerInterceptorAdapter(interceptor); InterceptorRegistration registration = new InterceptorRegistration(adapted); registrations.add(registration); return registration; }
/** * * * @return . */ @Bean public WebMvcConfigurerAdapter webMvcConfigurerAdapter( final WebRequestInterceptor conversationInterceptor) { return new WebMvcConfigurerAdapter() { @Override public void addInterceptors(InterceptorRegistry registry) { registry.addWebRequestInterceptor(conversationInterceptor); } }; }
/** * Create a new WebRequestHandlerInterceptorAdapter for the given WebRequestInterceptor. * @param requestInterceptor the WebRequestInterceptor to wrap */ public WebRequestHandlerInterceptorAdapter(WebRequestInterceptor requestInterceptor) { Assert.notNull(requestInterceptor, "WebRequestInterceptor must not be null"); this.requestInterceptor = requestInterceptor; }
/** * Adapt the given interceptor object to the {@link HandlerInterceptor} interface. * <p>By default, the supported interceptor types are {@link HandlerInterceptor} * and {@link WebRequestInterceptor}. Each given {@link WebRequestInterceptor} * will be wrapped in a {@link WebRequestHandlerInterceptorAdapter}. * Can be overridden in subclasses. * @param interceptor the specified interceptor object * @return the interceptor wrapped as HandlerInterceptor * @see org.springframework.web.servlet.HandlerInterceptor * @see org.springframework.web.context.request.WebRequestInterceptor * @see WebRequestHandlerInterceptorAdapter */ protected HandlerInterceptor adaptInterceptor(Object interceptor) { if (interceptor instanceof HandlerInterceptor) { return (HandlerInterceptor) interceptor; } else if (interceptor instanceof WebRequestInterceptor) { return new WebRequestHandlerInterceptorAdapter((WebRequestInterceptor) interceptor); } else { throw new IllegalArgumentException("Interceptor type not supported: " + interceptor.getClass().getName()); } }
/** * Create a new WebRequestHandlerInterceptorAdapter for the given WebRequestInterceptor, * applying to the render phase only. * @param requestInterceptor the WebRequestInterceptor to wrap */ public WebRequestHandlerInterceptorAdapter(WebRequestInterceptor requestInterceptor) { this(requestInterceptor, true); }
/** * Create a new WebRequestHandlerInterceptorAdapter for the given WebRequestInterceptor. * @param requestInterceptor the WebRequestInterceptor to wrap * @param renderPhaseOnly whether to apply to the render phase only ({@code true}) * or to the action phase as well ({@code false}) */ public WebRequestHandlerInterceptorAdapter(WebRequestInterceptor requestInterceptor, boolean renderPhaseOnly) { Assert.notNull(requestInterceptor, "WebRequestInterceptor must not be null"); this.requestInterceptor = requestInterceptor; this.renderPhaseOnly = renderPhaseOnly; }
/** * Create a new MappedInterceptor instance. * @param includePatterns the path patterns to map with a {@code null} value matching to all paths * @param interceptor the WebRequestInterceptor instance to map to the given patterns */ public MappedInterceptor(String[] includePatterns, WebRequestInterceptor interceptor) { this(includePatterns, null, interceptor); }
/** * Create a new MappedInterceptor instance. * @param includePatterns the path patterns to map with a {@code null} value matching to all paths * @param interceptor the WebRequestInterceptor instance to map to the given patterns */ public MappedInterceptor(String[] includePatterns, String[] excludePatterns, WebRequestInterceptor interceptor) { this(includePatterns, excludePatterns, new WebRequestHandlerInterceptorAdapter(interceptor)); }