GithubHelp home page GithubHelp logo

Comments (4)

WangJi92 avatar WangJi92 commented on June 1, 2024

你这个可以试一下 打印header 头

你这个操作不对 , headers不是核心参数

watch org.springframework.web.servlet.DispatcherServlet doService '#httpRequest=params[0],#allHeaders={},#forEnumeration = :[#this.hasMoreElements()? (#headerName=#this.nextElement(),#allHeaders.add(#headerName+"="+#httpRequest.getHeader(#headerName)),#forEnumeration(#this)):null],#forEnumeration(#httpRequest.getHeaderNames()),#allHeaders'  -n 5  -x 3

from arthas.

smallchips avatar smallchips commented on June 1, 2024

你好,感谢回复,有个疑问,这样写法是打印出所有方法的headers参数,但是我需要过滤指定方法的,有解决办法吗

from arthas.

WangJi92 avatar WangJi92 commented on June 1, 2024

也是可以解决的哈

第一步获取到request 对象

org.springframework.web.context.request.RequestContextHolder#getRequestAttributes

    public static HttpServletRequest getRequest() {
        ServletRequestAttributes servletRequestAttributes = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes());
        return servletRequestAttributes.getRequest();
    }

第二步 ognl 语法获取 request 对象

@org.springframework.web.context.request.RequestContextHolder@getRequestAttributes().getRequest()

第三步 整合之前的请求

这里只是做了一点点修改,request 不是从参数里面获取,从静态字段里面获取request对象
#httpRequest=@org.springframework.web.context.request.RequestContextHolder@getRequestAttributes().getRequest()

watch com.wangji92.arthas.plugin.demo.controller.CommonController userFastJson '#httpRequest=@org.springframework.web.context.request.RequestContextHolder@getRequestAttributes().getRequest(),#allHeaders={},#forEnumeration = :[#this.hasMoreElements()? (#headerName=#this.nextElement(),#allHeaders.add(#headerName+"="+#httpRequest.getHeader(#headerName)),#forEnumeration(#this)):null],#forEnumeration(#httpRequest.getHeaderNames()),{params,returnObj,throwExp,#allHeaders}' -v -n 5  -x 3 '1==1'

结果

[arthas@23956]$ watch com.wangji92.arthas.plugin.demo.controller.CommonController userFastJson '#[email protected] ntextHolder@getRequestAttributes().getRequest(),#allHeaders={},#forEnumeration = :[#this.hasMoreElements()? (#headerName=#this.nextElement(),#allHeaders.add(#h eaderName+"="+#httpRequest.getHeader(#headerName)),#forEnumeration(#this)):null],#forEnumeration(#httpRequest.getHeaderNames()),{params,returnObj,throwExp,#all Headers}' -v -n 5  -x 3 '1==1'
Press Q or Ctrl+C to abort.
Affect(class count: 2 , method count: 2) cost in 367 ms, listenerId: 4
Condition express: 1==1 , result: true
method=com.wangji92.arthas.plugin.demo.controller.CommonController.userFastJson location=AtExit
ts=2023-12-27 17:21:18; [cost=0.020101ms] result=@ArrayList[
    @Object[][
        @User[
            name=@String[33],
            age=@Long[0],
        ],
    ],
    @User[
        name=@String[33],
        age=@Long[0],
    ],
    null,
    @ArrayList[
        @String[content-type=application/json],
        @String[content-length=30],
        @String[host=localhost:8080],
        @String[connection=Keep-Alive],
        @String[user-agent=Apache-HttpClient/4.5.13 (Java/11.0.11)],
        @String[accept-encoding=gzip,deflate],
    ],
]

from arthas.

WangJi92 avatar WangJi92 commented on June 1, 2024

#729 可以参考一下729 也可以过滤哦~ 这个过滤类信息

你也可以直接通过request 里面的uri 进行过滤 这样简单点 ,
org.springframework.web.servlet.DispatcherServlet doService 里面第一个参数 params[0] 获取路径 包含 xxx 作为条件表达式即可。
https://arthas.aliyun.com/doc/watch.html#%E6%9D%A1%E4%BB%B6%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84%E4%BE%8B%E5%AD%90

from arthas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.