I get the below exception after running my webportal for a while. I need to re login to eliminate this error. Because of this I am not able to run my development environment smoothly on eclipse.
This is my AuthenticationFilter.java
public class AuthenticationFilter implements Filter {
private static final Logger log = Logger.getLogger(AuthenticationFilter.class) ;
static Map<String, String> permissionsMapping = new HashMap<String, String>();
private static int domainOrGroupParentId = 0;
static {
}
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest servletRequest = (HttpServletRequest) request;
if (servletRequest.getRequestURI().contains("onLoadOfLoginPage")
|| servletRequest.getRequestURI().contains("Corporate")
|| servletRequest.getRequestURI().contains("mainDashboard")
// ||
// servletRequest.getRequestURI().contains("mainDashboardWithoutDomainOrGroupParent")
|| servletRequest.getRequestURI().contains("loginButtonPressedForSuperAdminView")
// ||
// servletRequest.getRequestURI().contains("loginButtonPressedForNonSuperAdmin")
|| servletRequest.getRequestURI().contains("resources")
|| servletRequest.getRequestURI().contains("session")
|| servletRequest.getRequestURI().contains("forgot_password")
|| servletRequest.getRequestURI().contains("resetPassword")) {
>>Line52>> chain.doFilter(request, response);
} else {
HttpSession session = servletRequest.getSession(false);
try {
if (null == session || SessionDataManager.getInstance().getLoggedInWebAdminUser().getWebAdminUserPojo()
.getUsername() == null) {
RequestDispatcher dispatcher = request.getRequestDispatcher("onLoadOfLoginPage");
dispatcher.forward(request, response);
return;
} else if (!servletRequest.getRequestURI().contains("get")) {
String username = (String) SessionDataManager.getInstance().getLoggedInWebAdminUser()
.getWebAdminUserPojo().getUsername();
String sessionID = session.getId();
domainOrGroupParentId = SessionDataManager.getInstance().getDomainIdFromRequest(servletRequest);
log.info("Attempting to maintain Session, with domainParent "+domainOrGroupParentId);
if (!WebAdminHelper.maintainSession(username, sessionID, domainOrGroupParentId)) {
RequestDispatcher dispatcher = request.getRequestDispatcher("onLoadOfLoginPage");
dispatcher.forward(request, response);
return;
}
}
} catch (Exception e) {
}
chain.doFilter(request, response);
}
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}
Exception I get
type Exception report
message Handler processing failed; nested exception is java.lang.StackOverflowError
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.StackOverflowError
org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1276)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:958)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
net.codejava.spring.AuthenticationFilter.doFilter(AuthenticationFilter.java:52)
root cause
java.lang.StackOverflowError
com.google.gson.stream.JsonWriter.beforeName(JsonWriter.java:586)
com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:401)
com.google.gson.stream.JsonWriter.value(JsonWriter.java:417)
com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:362)
com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:346)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
EDIT I have identified the root causing line.
response = new Gson().toJson(invException);
Type of
InvalidObjectStateException invException
public class InvalidObjectStateException extends Exception {
private static final long serialVersionUID = -9086960433236073019L;
private static final Logger log = Logger.getLogger(InvalidObjectStateException.class);
private String customErrorMessage = null;
private Object exceptionCausingObject = null;
public InvalidObjectStateException(String errorMessage, Object exceptionCausingObject) {
super(errorMessage);
this.customErrorMessage = errorMessage;
log.info("InvalidObjectStateException : exceptionCausingObject"
+ ((exceptionCausingObject != null) ? exceptionCausingObject.getClass().toString() : ""));
this.exceptionCausingObject = exceptionCausingObject;
}
public String getCustomErrorMessage() {
return customErrorMessage;
}
public void setCustomErrorMessage(String customErrorMessage) {
this.customErrorMessage = customErrorMessage;
}
public Object getExceptionCausingObject() {
return exceptionCausingObject;
}
public void setExceptionCausingObject(Object exceptionCausingObject) {
this.exceptionCausingObject = exceptionCausingObject;
}
}
What am I doing wrong here ? Why cant Gson parse the Exception ?