org.springframework.web.servlet.HandlerInterceptor.afterCompletion()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(207)

本文整理了Java中org.springframework.web.servlet.HandlerInterceptor.afterCompletion()方法的一些代码示例,展示了HandlerInterceptor.afterCompletion()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HandlerInterceptor.afterCompletion()方法的具体详情如下:
包路径:org.springframework.web.servlet.HandlerInterceptor
类名称:HandlerInterceptor
方法名:afterCompletion

HandlerInterceptor.afterCompletion介绍

[英]Callback after completion of request processing, that is, after rendering the view. Will be called on any outcome of handler execution, thus allows for proper resource cleanup.

Note: Will only be called if this interceptor's preHandlemethod has successfully completed and returned true!

As with the postHandle method, the method will be invoked on each interceptor in the chain in reverse order, so the first interceptor will be the last to be invoked.

Note: special considerations apply for asynchronous request processing. For more details see org.springframework.web.servlet.AsyncHandlerInterceptor.

The default implementation is empty.
[中]请求处理完成后(即呈现视图后)回调。将在处理程序执行的任何结果上调用,从而允许适当的资源清理。
注意:仅当此拦截器的preHandlemethod已成功完成并返回true时才会调用!
与postHandle方法一样,该方法将以相反的顺序在链中的每个拦截器上调用,因此第一个拦截器将是最后一个被调用的拦截器。
注意:特殊注意事项适用于异步请求处理。有关更多详细信息,请参阅org。springframework。网状物servlet。AsyncHandlerInterceptor。
默认实现为空。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
    @Nullable Exception ex) throws Exception {
  this.interceptor.afterCompletion(request, response, handler, ex);
}

代码示例来源:origin: org.springframework/spring-webmvc

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
    @Nullable Exception ex) throws Exception {
  this.interceptor.afterCompletion(request, response, handler, ex);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Trigger afterCompletion callbacks on the mapped HandlerInterceptors.
 * Will just invoke afterCompletion for all interceptors whose preHandle invocation
 * has successfully completed and returned true.
 */
void triggerAfterCompletion(HttpServletRequest request, HttpServletResponse response, @Nullable Exception ex)
    throws Exception {
  HandlerInterceptor[] interceptors = getInterceptors();
  if (!ObjectUtils.isEmpty(interceptors)) {
    for (int i = this.interceptorIndex; i >= 0; i--) {
      HandlerInterceptor interceptor = interceptors[i];
      try {
        interceptor.afterCompletion(request, response, this.handler, ex);
      }
      catch (Throwable ex2) {
        logger.error("HandlerInterceptor.afterCompletion threw exception", ex2);
      }
    }
  }
}

代码示例来源:origin: org.springframework/spring-webmvc

/**
 * Trigger afterCompletion callbacks on the mapped HandlerInterceptors.
 * Will just invoke afterCompletion for all interceptors whose preHandle invocation
 * has successfully completed and returned true.
 */
void triggerAfterCompletion(HttpServletRequest request, HttpServletResponse response, @Nullable Exception ex)
    throws Exception {
  HandlerInterceptor[] interceptors = getInterceptors();
  if (!ObjectUtils.isEmpty(interceptors)) {
    for (int i = this.interceptorIndex; i >= 0; i--) {
      HandlerInterceptor interceptor = interceptors[i];
      try {
        interceptor.afterCompletion(request, response, this.handler, ex);
      }
      catch (Throwable ex2) {
        logger.error("HandlerInterceptor.afterCompletion threw exception", ex2);
      }
    }
  }
}

代码示例来源:origin: apache/geode

@Test
public void afterCompletion_logsOut() throws Exception {
 HttpServletRequest request = request().build();
 interceptor.afterCompletion(request, null, null, null);
 verify(securityService, times(1)).logout();
}

代码示例来源:origin: apache/geode

@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();
}

代码示例来源:origin: apache/geode

interceptor.afterCompletion(request, null, null, null);

代码示例来源:origin: spring-projects/spring-framework

@Test
public void afterCompletion() throws Exception {
  HandlerInterceptor interceptor = mock(HandlerInterceptor.class);
  MappedInterceptor mappedInterceptor = new MappedInterceptor(new String[] { "/**" }, interceptor);
  mappedInterceptor.afterCompletion(mock(HttpServletRequest.class), mock(HttpServletResponse.class),
      null, mock(Exception.class));
  then(interceptor).should().afterCompletion(any(), any(), any(), any());
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
    Exception ex) throws Exception {
  this.interceptor.afterCompletion(request, response, handler, ex);
}

代码示例来源:origin: pl.edu.icm.synat/synat-portal-core

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
  processVoidDelegates(i -> i.afterCompletion(request, response, handler, ex));
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Trigger afterCompletion callbacks on the mapped HandlerInterceptors.
 * Will just invoke afterCompletion for all interceptors whose preHandle invocation
 * has successfully completed and returned true.
 */
void triggerAfterCompletion(HttpServletRequest request, HttpServletResponse response, Exception ex)
    throws Exception {
  HandlerInterceptor[] interceptors = getInterceptors();
  if (!ObjectUtils.isEmpty(interceptors)) {
    for (int i = this.interceptorIndex; i >= 0; i--) {
      HandlerInterceptor interceptor = interceptors[i];
      try {
        interceptor.afterCompletion(request, response, this.handler, ex);
      }
      catch (Throwable ex2) {
        logger.error("HandlerInterceptor.afterCompletion threw exception", ex2);
      }
    }
  }
}

代码示例来源:origin: org.rythmengine/spring-rythm

public static void applyCompleteHandlers(HttpServletRequest req, HttpServletResponse res) {
  for (HandlerInterceptor in : getInterceptors().reverse()) {
    try {
      in.afterCompletion(req, res, null, null);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: org.parancoe/parancoe-web

public void invokeAfterCompletion(HttpServletRequest request, HttpServletResponse response,
    Object handler, Exception exception) {
  for (WebPlugin plugin : getWebPlugins()) {
    for (HandlerInterceptor interceptor : plugin.getInterceptors()) {
      try {
        interceptor.afterCompletion(request, response, handler, exception);
      } catch (Exception e) {
        log.error("error in afterCompletion for plugin '" + plugin.getName() + "'", e);
      }
    }
  }
}

代码示例来源:origin: org.tinygroup/org.tinygroup.springmvc

HandlerInterceptor interceptor = interceptors[i];
try {
  interceptor.afterCompletion(request, response,
      mappedHandler.getHandler(), ex);
} catch (Exception ex2) {

相关文章