arthas/tutorials/katacoda/case-http-401-cn/case-http-401.md

2.1 KiB
Raw Blame History

在这个案例里展示排查HTTP 401问题的技巧。

访问: https://HOST_SUBDOMAIN-80-KATACODA_HOST.environments.katacoda.com/admin

结果是:

Something went wrong: 401 Unauthorized

我们知道401通常是被权限管理的Filter拦截了,那么到底是哪个Filter处理了这个请求返回了401

跟踪所有的Filter函数

开始trace

trace javax.servlet.Filter *{{execute T2}}

访问: https://HOST_SUBDOMAIN-80-KATACODA_HOST.environments.katacoda.com/admin

可以在调用树的最深层,找到AdminFilterConfig$AdminFilter返回了401

+---[3.806273ms] javax.servlet.FilterChain:doFilter()
|   `---[3.447472ms] com.example.demo.arthas.AdminFilterConfig$AdminFilter:doFilter()
|       `---[0.17259ms] javax.servlet.http.HttpServletResponse:sendError()

通过stack获取调用栈

上面是通过trace命令来获取信息,从结果里,我们可以知道通过stack跟踪HttpServletResponse:sendError(),同样可以知道是哪个Filter返回了401

执行:

stack javax.servlet.http.HttpServletResponse sendError 'params[0]==401'{{execute T2}}

访问: https://HOST_SUBDOMAIN-80-KATACODA_HOST.environments.katacoda.com/admin

$ stack javax.servlet.http.HttpServletResponse sendError 'params[0]==401'
Press Q or Ctrl+C to abort.
Affect(class-cnt:2 , method-cnt:4) cost in 87 ms.
ts=2019-02-15 16:44:06;thread_name=http-nio-8080-exec-6;id=16;is_daemon=true;priority=5;TCCL=org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader@8546cd5
    @org.apache.catalina.connector.ResponseFacade.sendError()
        at com.example.demo.arthas.AdminFilterConfig$AdminFilter.doFilter(AdminFilterConfig.java:38)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)