Skip to content

Commit

Permalink
Fix clearing of request id
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheus-87 committed Jul 4, 2024
1 parent ced723f commit f0287bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.github.dbmdz.metadata.server.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.MDC;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.HandlerInterceptor;

public class MdcLoggingInterceptor implements HandlerInterceptor {
/** Clear MDC to avoid data leaking between two requests handled by the same thread. */
@Override
public void afterCompletion(
@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response,
@NonNull Object handler,
Exception ex)
throws Exception {
MDC.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@
import org.springframework.lang.NonNull;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class RequestIdLoggingInterceptor implements HandlerInterceptor {
/** Clear MDC to avoid data leaking between two requests handled by the same thread. */
@Override
public void postHandle(
@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response,
@NonNull Object handler,
ModelAndView modelAndView) {
MDC.clear();
}

/**
* Register the request identifier (if received from client/frontend server) in the logging
Expand Down

0 comments on commit f0287bb

Please sign in to comment.