I am using Struts 2 in my web application. I write code to check user session into interceptor but while I am returning net.sf.json.JSONObject
as response, its reset the response object and set null to the object.
Please check my code.
import net.sf.json.JSONObject;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class AuthorizationInterceptor implements Interceptor {
JSONObject response = new JSONObject();
public String intercept(ActionInvocation invocation) {
try {
Map session = invocation.getInvocationContext().getSession();
if (session.get("userId") == null) {
response.put("errorCode", "SESSION_OUT");
return ActionSupport.ERROR;
} else {
System.out.println("Session found");
Object action = invocation.getAction();
return invocation.invoke();
}
} catch (Exception e) {
return ActionSupport.ERROR;
}
}
public JSONObject getResponse() {
return response;
}
public void setResponse(JSONObject response) {
this.response = response;
}
}
How can I get the JSON Object as response from interceptor. Please help me to resolve this issue.