http入站网关可以做类似拦截器的preHandle和postHandle吗?

时间:2019-11-26 09:35:17

标签: spring-integration spring-dsl

当服务接受http请求时,我想在MDC中放入“ UUID”。 因为它方便了日志搜索。

我继承了HttpRequestHandlingMessagingGateway并发现handleRequest()是最终的,因此我无法覆盖它。

那么当接受请求(MDC.put())并编写响应(MDC.remove())时,有什么办法做吗?

1 个答案:

答案 0 :(得分:0)

好吧,以这种方式处理请求不是HttpRequestHandlingMessagingGateway的责任。

我认为您需要查看 Web过滤器注册:https://www.mkyong.com/spring-mvc/how-to-register-a-servlet-filter-in-spring-mvc/

从概念上讲,您可以借用现有的AbstractRequestLoggingFilter

 * Base class for {@code Filter}s that perform logging operations before and after a request
 * is processed.
 *
 * <p>Subclasses should override the {@code beforeRequest(HttpServletRequest, String)} and
 * {@code afterRequest(HttpServletRequest, String)} methods to perform the actual logging
 * around the request.