Accessing objects of private class
bluegol Jul 21, 2016 4:37 AMHi all,
I am trying to trace how servlet handles requests. My rule is:
RULE servlet start in FilterChain
INTERFACE javax.servlet.FilterChain
METHOD void doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
AT ENTRY
IF TRUE
DO
startWithTarget(TT_SERVLET, $0, $1, $2);
ENDRULE
where startWithTarget is some function which handles tracing, TT_SERVLET some short constant value.
Now with Tomcat, the following exception occurs:
java.lang.IllegalAccessError: tried to access class org.apache.catalina.core.ApplicationFilterChain from class com.brainzsquare.apm.agent.RuleHelper_HelperAdapter_Compiled_81
com.brainzsquare.apm.agent.RuleHelper_HelperAdapter_Compiled_81.execute0(test_rules.btm:13)
com.brainzsquare.apm.agent.RuleHelper_HelperAdapter_Compiled_81.execute(test_rules.btm)
org.jboss.byteman.rule.Rule.execute(Rule.java:777)
org.jboss.byteman.rule.Rule.execute(Rule.java:746)
And googling org.apache.catalina.core.ApplicationFilterChain, reveals that $0 is an object of package private class. Seems fair.
Wait, this means that my rule body must be executed out of the method it targets. OK, I suspected that much.
NOW, I don't need all of the object $0. I just need to save it somewhere and compare it with other objects. In other words,
I need an "identity" of $0. But anyway, since byteman code is injected into the method, there must be a way to get my hands on $0.
So my next try is with the rule:
RULE servlet start in FilterChain
INTERFACE javax.servlet.FilterChain
METHOD void doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
AT ENTRY
BIND o:Object = $0
IF TRUE
DO
startWithTarget(TT_SERVLET, o, $1, $2);
ENDRULE
which unfortunately gives the same exception. Reflection doesn't help me either, because
calling a method with $0 results in the same exception.
Is there a way to get a grab of $0, e.g., as a plain java Object, or to extract some identity of $0 at least,
when $0 is an object of package private class?
Best,
Jahwan
P.S. Since the rule is on "INTERFACE javax.servlet.FilterChain", shouldn't $0 be just of type javax.servlet.FilterChain?