0

Till now we have used the jquery AJAX and if we want to catch any parameters in interceptor used to do like below

   public String intercept(ActionInvocation actionInvocation) throws Exception {

        Map<String, Object> sessionAttributes =
            actionInvocation.getInvocationContext().getSession();

        Map<String, Object> parameters =
            actionInvocation.getInvocationContext().getParameters();


        String[] sid = (String[]) parameters.get("sessionId");
    }

Now we are making Rest request and all parameters are passing as request body in postman. If we use above code not able to get any parameters which are passed as body in JSON.

struts.xml

<interceptor-ref name="json"></interceptor-ref>
<interceptor-ref name="customSessionInterceptor"></interceptor-ref>

Even if i place json interceptor as first and after my custom interceptor, it is not picking up.

Interceptor class

 public class SessionInitInterceptor implements Interceptor {
       privtae String sessionId;
       //getter and setters

       @Override
       public String intercept(ActionInvocation actionInvocation) throws 
       Exception {
          //Want to catch sessionid here which is passed from request body
       }
  }
  • 1
    The same way the JSON interceptor does it--by getting the request reader and deserializing it. But if you have your interceptor *after* the JSON interceptor you shouldn't need to as it'll already have been decoded... with the caveat that I haven't tried it. – Dave Newton Jun 26 '19 at 15:20
  • Edited post and suggested one also not working but my requirement is like for every request i should check session is active or not and to achieve this requirement every request should go through custom interceptor. – Kona Laxman Deepak Jun 27 '19 at 06:53
  • Looks like this https://stackoverflow.com/a/16752302/573032 – Roman C Jul 14 '19 at 21:38

0 Answers0