@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { return this.interceptor.preHandle(request, response, handler); }
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { return this.interceptor.preHandle(request, response, handler); }
/** * Apply preHandle methods of registered interceptors. * @return {@code true} if the execution chain should proceed with the * next interceptor or the handler itself. Else, DispatcherServlet assumes * that this interceptor has already dealt with the response itself. */ boolean applyPreHandle(HttpServletRequest request, HttpServletResponse response) throws Exception { HandlerInterceptor[] interceptors = getInterceptors(); if (!ObjectUtils.isEmpty(interceptors)) { for (int i = 0; i < interceptors.length; i++) { HandlerInterceptor interceptor = interceptors[i]; if (!interceptor.preHandle(request, response, this.handler)) { triggerAfterCompletion(request, response, null); return false; } this.interceptorIndex = i; } } return true; }
/** * Apply preHandle methods of registered interceptors. * @return {@code true} if the execution chain should proceed with the * next interceptor or the handler itself. Else, DispatcherServlet assumes * that this interceptor has already dealt with the response itself. */ boolean applyPreHandle(HttpServletRequest request, HttpServletResponse response) throws Exception { HandlerInterceptor[] interceptors = getInterceptors(); if (!ObjectUtils.isEmpty(interceptors)) { for (int i = 0; i < interceptors.length; i++) { HandlerInterceptor interceptor = interceptors[i]; if (!interceptor.preHandle(request, response, this.handler)) { triggerAfterCompletion(request, response, null); return false; } this.interceptorIndex = i; } } return true; }
private void verifyWebInterceptor(HandlerInterceptor interceptor, TestWebRequestInterceptor webInterceptor) throws Exception { assertTrue(interceptor instanceof WebRequestHandlerInterceptorAdapter); interceptor.preHandle(this.request, this.response, null); assertTrue(webInterceptor.preHandleInvoked); }
private HandlerExecutionChain getHandler(HandlerMapping hm, MockHttpServletRequest req) throws Exception { HandlerExecutionChain hec = hm.getHandler(req); HandlerInterceptor[] interceptors = hec.getInterceptors(); if (interceptors != null) { for (HandlerInterceptor interceptor : interceptors) { interceptor.preHandle(req, null, hec.getHandler()); } } return hec; }
private HandlerExecutionChain getHandler(MockHttpServletRequest req) throws Exception { HandlerExecutionChain hec = hm.getHandler(req); HandlerInterceptor[] interceptors = hec.getInterceptors(); if (interceptors != null) { for (HandlerInterceptor interceptor : interceptors) { interceptor.preHandle(req, null, hec.getHandler()); } } return hec; }
@Test public void preHandle_returnsTrue() throws Exception { HttpServletRequest request = request().build(); assertThat(interceptor.preHandle(request, null, null)) .isTrue(); }
@Test public void preHandle_logsInWithUserNameAndPasswordFromRequestHeaders() throws Exception { HttpServletRequest request = request() .withHeader(USER_NAME, "expected user-name") .withHeader(PASSWORD, "expected password") .build(); interceptor.preHandle(request, null, null); Properties expectedLoginProperties = new Properties(); expectedLoginProperties.setProperty(USER_NAME, "expected user-name"); expectedLoginProperties.setProperty(PASSWORD, "expected password"); verify(securityService, times(1)).login(expectedLoginProperties); }
for (Iterator i = interceptors.iterator(); i.hasNext(); ) { HandlerInterceptor interceptor = (HandlerInterceptor) i.next(); interceptor.preHandle(request, response, dispatcher);
for (Iterator i = interceptors.iterator(); i.hasNext(); ) { HandlerInterceptor interceptor = (HandlerInterceptor) i.next(); interceptor.preHandle(request, response, dispatcher);
@Test public void preHandle_createsNewEnvironmentInstance() throws Exception { HttpServletRequest request = request().build(); Map<String, String> environmentBeforePreHandle = LoginHandlerInterceptor.getEnvironment(); interceptor.preHandle(request, null, null); assertThat(LoginHandlerInterceptor.getEnvironment()) .isNotSameAs(environmentBeforePreHandle); }
@Test public void afterCompletion_clearsTheEnvironment() throws Exception { HttpServletRequest request = request() .withParameter(ENVIRONMENT_VARIABLE_REQUEST_PARAMETER_PREFIX + "variable", "value") .build(); // Call preHandle() to put values into the environment interceptor.preHandle(request, null, null); interceptor.afterCompletion(request, null, null, null); assertThat(LoginHandlerInterceptor.getEnvironment()) .isEmpty(); }
.isEmpty(); interceptor.preHandle(request, null, null);
@Test public void preHandle() throws Exception { HandlerInterceptor interceptor = mock(HandlerInterceptor.class); MappedInterceptor mappedInterceptor = new MappedInterceptor(new String[] { "/**" }, interceptor); mappedInterceptor.preHandle(mock(HttpServletRequest.class), mock(HttpServletResponse.class), null); then(interceptor).should().preHandle(any(HttpServletRequest.class), any(HttpServletResponse.class), any()); }
@Test public void preHandle_copiesPrefixedRequestParametersIntoEnvironment() throws Exception { HttpServletRequest request = request() .withParameter(ENVIRONMENT_VARIABLE_REQUEST_PARAMETER_PREFIX + "prefixed", "prefixed value") .withParameter("not-prefixed", "not-prefixed value") .build(); interceptor.preHandle(request, null, null); assertThat(LoginHandlerInterceptor.getEnvironment()) .containsOnly(entry("prefixed", "prefixed value")) .doesNotContain(entry("not-prefixed", "not-prefixed value")); }
interceptor.preHandle(request, response, chain.getHandler());
handlerMapping.getHandler(request).getInterceptors(); for (HandlerInterceptor interceptor : interceptors) { final boolean carryOn = interceptor.preHandle(request, response, controller); if (!carryOn) { return null;
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { return this.interceptor.preHandle(request, response, handler); }