Search code examples
javaspringjavassist

javassist, get second param of doGet method


i inject my code into doGet method

val replace = "" +
  "  System.out.println(\"[before] " + className + "\");" +
  "  $proceed($$);" +
  "  try{System.out.println(\"$args[2] = \" + $args[1].toString());}catch(Exception ex){System.out.println(\"ERROR\");}"
  "  System.out.println(\"[after] " + className  + "\");".stripMargin

Here i am getting second param and i expect that param will be instance of HttpServletResponse class, but i see following class

org.springframework.security.web.context
.HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper@398ce9f7 

Behind action is in DefaultServlet, FrameworkServlet

What is wrong with my reality?


Solution

  • HttpServletResponse is an interface, so there can be anything there that correctly inmplements the given interface. As you are in Spring, the framework is using its own implementation, as you can see from .toString mehotd, it is a SaveToSessionResponseWrapper class.

    On second link you can find a exactly place there is the substitution goes:

    SaveToSessionResponseWrapper wrappedResponse =
      new SaveToSessionResponseWrapper(response, request, httpSession != null, context);
    requestResponseHolder.setResponse(wrappedResponse);
    

    You can find more information about this class here:

    HttpSessionSecurityContextRepository implementation