22
33import dev .aikido .agent .wrappers .Wrapper ;
44import dev .aikido .agent_api .collectors .WebRequestCollector ;
5- import dev .aikido .agent_api .collectors .WebResponseCollector ;
65import dev .aikido .agent_api .context .Context ;
76import dev .aikido .agent_api .context .ContextObject ;
87import dev .aikido .agent_api .context .JavalinContextObject ;
98import io .javalin .http .servlet .JavalinServletContext ;
10- import jakarta .servlet .http .HttpServletResponse ;
119import net .bytebuddy .asm .Advice ;
1210import net .bytebuddy .description .method .MethodDescription ;
1311import net .bytebuddy .description .type .TypeDescription ;
1412import net .bytebuddy .matcher .*;
1513
16- import java .lang .reflect .Executable ;
17-
1814import static net .bytebuddy .implementation .bytecode .assign .Assigner .Typing .DYNAMIC ;
1915import static net .bytebuddy .matcher .ElementMatchers .*;
2016
@@ -35,13 +31,11 @@ public ElementMatcher<? super TypeDescription> getTypeMatcher() {
3531 }
3632 public class JavalinAdvice {
3733 @ Advice .OnMethodEnter (suppress = Throwable .class )
38- public static JavalinServletContext before (
39- @ Advice .This (typing = DYNAMIC , optional = true ) Object target ,
40- @ Advice .Origin Executable method ,
34+ public static void before (
4135 @ Advice .Argument (value = 0 , typing = DYNAMIC , optional = true ) JavalinServletContext ctx
42- ) {
36+ ) {
4337 if (Context .get () != null ) {
44- return ctx ; // Do not extract if context already exists.
38+ return ; // Do not extract if context already exists.
4539 }
4640 // Create a context object :
4741 ContextObject context = new JavalinContextObject (
@@ -56,14 +50,6 @@ public static JavalinServletContext before(
5650 ctx .status (response .status ());
5751 ctx .skipRemainingHandlers ();
5852 }
59-
60- return ctx ;
61- }
62- @ Advice .OnMethodExit (suppress = Throwable .class , onThrowable = Throwable .class )
63- public static void after (
64- @ Advice .Enter (typing = DYNAMIC ) JavalinServletContext ctx
65- ) {
66- WebResponseCollector .report (ctx .statusCode ());
6753 }
6854 }
6955
0 commit comments