运行我的webportal一段时间后,我得到以下异常。我需要重新登录才能消除此错误。因此,我无法在eclipse上顺利运行我的开发环境。
这是我的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 {
}
}
我得到的例外
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)
修改 我已经确定了根源线。
response = new Gson()。toJson(invException);
的类型
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;
}
}
我在这里做错了什么?为什么Gason无法解析异常?
答案 0 :(得分:2)
我认为这不是正确的例外来源。 net.codejava.spring.AuthenticationFilter.doFilter(AuthenticationFilter.java:52)
。由于内存不足,它在这个位置失败了。
应该有另一个转换response(maybe)/object to json string
的流程/请求。查看response
对象,它应该有一个嵌套的无限对象引用。
答案 1 :(得分:2)
Object exceptionCausingObject
它有循环引用,因此Gson解析器无法正确解析它并抛出StackOverflowError
您可以将exceptionCausingObject
类的某些字段标记为transient
private transient String name;
这会将他们排除在Gson序列化之外。
另一种选择是使用GraphAdapterBuilder
。见here