我正在基于请求uri实现api网关。我需要在chain.doFilter(request,response)
中添加其他标题。
我的过滤器是jwt过滤器,如下所示
public class JwtAuthenticationFilter extends OncePerRequestFilter{
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
CustomHttpServletRequest cRequest = new CustomHttpServletRequest(request);
/* authenticate user for valid token if valid then add the following header*/
if(request.getRequestURI().equals("/testService/updateHeader")) {
cRequest.putHeader("test","Test-header");
}
filterChain.doFilter(cRequest, response);
}
}
基于reference实现:
在我的testservice中,尝试在标题中获取标题,我无法获取标题名称
答案 0 :(得分:0)
我想问题是在filterChain.doFilter(request,response)中,您使用的是原始请求,而不是使用自定义侦听器的新请求。更改
filterChain.doFilter(request, response);
到
filterChain.doFilter(cRequest, response);