Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复servlet过滤器bug #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ public void init(FilterConfig filterConfig) throws ServletException {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (request instanceof HttpServletRequest && response instanceof HttpServletResponse){
try{
TLogWebCommon.loadInstance().preHandle((HttpServletRequest)request);
//把traceId放入response的header,为了方便有些人有这样的需求,从前端拿整条链路的traceId
((HttpServletResponse)response).addHeader(TLogConstants.TLOG_TRACE_KEY, TLogContext.getTraceId());
}finally {
TLogWebCommon.loadInstance().afterCompletion();
}
TLogWebCommon.loadInstance().preHandle((HttpServletRequest)request);
//把traceId放入response的header,为了方便有些人有这样的需求,从前端拿整条链路的traceId
((HttpServletResponse)response).addHeader(TLogConstants.TLOG_TRACE_KEY, TLogContext.getTraceId());
}
chain.doFilter(request, response);

if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
// 放置在doFilter后面, 否则未进入方法就清空了
TLogWebCommon.loadInstance().afterCompletion();
}
}

@Override
Expand Down