如何使用Java代理截获返回变量

如何使用Java代理截获返回变量,java,debugging,javassist,intercept,javaagents,Java,Debugging,Javassist,Intercept,Javaagents,我正在拦截一个方法,并在我的应用程序中使用Java代理。通过Javassist字节码操作框架,我可以 addLocalVariable(..); - add local variable. insertBefore(..); - insert method at the start of the body. insertAfter(..); - insert method at the end of the body. 我在使用这个机制时遇到了一个问题。假设这是我正在执行的代码 fun(req

我正在拦截一个方法,并在我的应用程序中使用Java代理。通过Javassist字节码操作框架,我可以

addLocalVariable(..); - add local variable.
insertBefore(..); - insert method at the start of the body.
insertAfter(..); - insert method at the end of the body.
我在使用这个机制时遇到了一个问题。假设这是我正在执行的代码

fun(req,res){
    interceptstart(req,res)
    .....
    ....
    logic
    ....
    ....
    ...
    ..
    if (..){
        res.add.....
        return res
        //then method in the below won't capture anything
    }
    else if(){
        res.add.....
        return res
        //then method in the below won't capture anything
    }

    ......

    interceptend(req,res)

}
在这里,我想捕获请求和响应。但我现在面临的问题是,我可以捕获请求,因为请求包含所有变量,但我无法捕获响应,因为添加了响应变量并返回了
,并且
截取
将无法执行

是否有任何方法可以通过使用JavaAgent和Javassist拦截来捕获返回变量