Struts 2 - Interceptor restablece el objeto JSON de respuesta
Estoy usando Struts 2 en mi aplicación web. Escribo código para verificar la sesión del usuario en el interceptor, pero mientras estoy regresandonet.sf.json.JSONObject
como respuesta, se restablece el objeto de respuesta y se establece nulo en el objeto. Por favor revise mi código.
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;
}
}
¿Cómo puedo obtener el objeto JSON como respuesta del interceptor? Por favor, ayúdame a resolver este problema.