【问题标题】:Logging REST/SOAP services using HandlerInterceptorAdapter使用 HandlerInterceptorAdapter 记录 REST/SOAP 服务
【发布时间】:2017-01-12 16:18:54
【问题描述】:

我正在尝试实现HandlerInterceptorAdapter 以便能够将请求/响应捕获为前/后处理器。由于某种原因,呼叫没有通过我的拦截器。有多个示例,但我在我的案例中找不到问题。现在我想在请求进入实际服务之前捕获请求并记录一些数据。

注意:我没有要渲染的视图。

拦截器类:

public class ESignLoggingInterceptor extends HandlerInterceptorAdapter {

  private static final String CLASS_NAME = ESignLoggingInterceptor.class.getSimpleName();

  @SuppressWarnings("unused")
  @Override
  public boolean preHandle( HttpServletRequest request, HttpServletResponse response, Object handler ) throws Exception {
      String url = null;
      if( request != null ) {
          url = request.getRequestURL().toString();
      }
      return true;
  }

}

spring.xml

<mvc:interceptors>
    <mvc:interceptor>
        <mvc:mapping path="/rest"/>
        <bean class="com.mercuryinsurance.esignature.common.logging.ESignLoggingInterceptor" />
    </mvc:interceptor>
</mvc:interceptors>

<mvc:interceptors>
    <mvc:interceptor>
        <mvc:mapping path="/soap"/>
        <bean class="com.mercuryinsurance.esignature.common.logging.ESignLoggingInterceptor" />
    </mvc:interceptor>
</mvc:interceptors>

【问题讨论】:

    标签: java spring logging


    【解决方案1】:

    我知道解决这个问题的两种方法,我也遇到过。

    第一个就像你在尝试。请检查:

    1. 改变

    &lt;mvc:mapping path="/soap"/&gt;&lt;mvc:mapping path="/soap/**"/&gt;
    &lt;mvc:mapping path="/rest"/&gt;&lt;mvc:mapping path="/rest/**"/&gt;

    1. 还要检查您是否声明了所有模式。如果您实际上没有声明它,您应该会收到错误。

    xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"

    第二个

    1. 如下声明你的拦截器

      @Bean public MappedInterceptor myInterceptor() { return new MappedInterceptor(null, new MyLoggingInterceptor()); }

    编辑:将@Component 添加到您的类中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多