How to put breakpoint in class without having it's source?

后端 未结 3 1821
-上瘾入骨i
-上瘾入骨i 2021-02-14 02:30

I have a web application where I need to find all classes that accesses the http request object (because one of them is causing a hard to find bug). Therefore I would like to pu

3条回答
  •  感情败类
    2021-02-14 03:15

    Depending on your luck, you can do this with a decompiler. You'll have to place the breakpoint in the appropriate line (which, alas, might not contain "breakpointable" code)

    The better way to do this is to create a ServletResponse wrapper. Incidentally, yesterday I created such a thing (with a slightly different purpose), so here it is:

    public class DebugFilter implements Filter {
    
        public void init(FilterConfig filterConfig) {}
    
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 
              throws IOException, ServletException {
    
            chain.doFilter(request, 
                  new ResponseWrapper((HttpServletResponse) response));
        }
    
        public void destroy() {}
    }
    
    class ResponseWrapper extends HttpServletResponseWrapper {
    
        public ResponseWrapper(HttpServletResponse response) {
            super(response);
        }
    
        @Override
        public PrintWriter getWriter() throws IOException {
            return super.getWriter(); // breakpoint here
        }
    
        // Override whichever methods you like
    }
    

提交回复
热议问题