stack overflow - ServletException java.lang.StackOverflowError thrown sometimes with multiple doGet() calls - Weblogic 10 -
we have application running on weblogic 10 server. while navigating application, randomly users getting following exception trace. code based on servlet/jsp framework. codes going controler.java, basisservlet.java , corresponding servlet. have not been able identify particular flow causing error. random. in local system never able replicate same. in other posts saw "/*" can cause stack overflow issues, confusing me why occurring sometimes. input regarding issue appreciated.
<[weblogic.servle t.internal.webappservletcontext@375e95f - appname: 'ebasis', name: '/', context- path: ''] root cause of servletexception. java.lang.stackoverflowerror @ weblogic.utils.stringutils.getstring(stringutils.java:556) @ weblogic.utils.http.bytestostring.newstring(bytestostring.java:14) @ weblogic.utils.http.bytestostring.newstring(bytestostring.java:10) @ weblogic.servlet.internal.requestheaders.getheadervalue(requestheader s.java:82) @ weblogic.servlet.internal.requestheaders.getheader(requestheaders.java:41) @ weblogic.servlet.internal.servletrequestimpl.getheader(unknown source) @ com.ba.basis.servlet.basisservlet.isloggedonuservalid(basisservlet.java:1749) @ com.ba.basis.servlet.controller.dopost(controller.java:293) @ com.ba.basis.servlet.controller.doget(controller.java:72) @ javax.servlet.http.httpservlet.service(httpservlet.java:707) @ javax.servlet.http.httpservlet.service(httpservlet.java:820) @ weblogic.servlet.internal.stubsecurityhelper$servletserviceaction.run(stubsecurityhelper.java:226) @ weblogic.servlet.internal.stubsecurityhelper.invokeservlet(stubsecurityhelper.java:124) @ weblogic.servlet.internal.servletstubimpl.execute(servletstubimpl.java:283) @ weblogic.servlet.internal.servletstubimpl.execute(servletstubimpl.java:175) @ weblogic.servlet.internal.requestdispatcherimpl.invokeservlet(requestdispatcherimpl.java:525) @ weblogic.servlet.internal.requestdispatcherimpl.forward(requestdispatcherimpl.java:261) @ com.ba.basis.servlet.controller.dopost(controller.java:658) @ com.ba.basis.servlet.controller.doget(controller.java:72) @ javax.servlet.http.httpservlet.service(httpservlet.java:707) @ javax.servlet.http.httpservlet.service(httpservlet.java:820) @ weblogic.servlet.internal.stubsecurityhelper$servletserviceaction.run(stubsecurityhelper.java:226) @ weblogic.servlet.internal.stubsecurityhelper.invokeservlet(stubsecurityhelper.java:124) @ weblogic.servlet.internal.servletstubimpl.execute(servletstubimpl.java:283) @ weblogic.servlet.internal.servletstubimpl.execute(servletstubimpl.java:175) @ weblogic.servlet.internal.requestdispatcherimpl.invokeservlet(requestdispatcherimpl.java:525) @ weblogic.servlet.internal.requestdispatcherimpl.forward(requestdispatcherimpl.java:261) @ com.ba.basis.servlet.controller.dopost(controller.java:658) @ com.ba.basis.servlet.controller.doget(controller.java:72)
as can see above, forward method being called recursively.
the web.xml :
<servlet-mapping> <servlet-name>controller</servlet-name> <url-pattern>/ebasis/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>search</servlet-name> <url-pattern>/search/*</url-pattern> </servlet-mapping>
basisservlet.java
protected void processhttprequest(httpservletrequest request, httpservletresponse response ) throws servletexception, ioexception { // set no-cache part of response /*system.out.println("#####1 |" + request.getrequesturi()); system.out.println("#####2 |" + request.getpathinfo()); system.out.println("#####3 |" + request.getpathtranslated()); system.out.println("#####4 |" + request.getservletpath()); system.out.println("#####5 |" + request.getrequesturl());*/ response.setheader("cache-control", "no-cache"); response.setheader("pragma", "no-cache"); response.setintheader("expires", 0); displayvaluebean displayvaluebean = (displayvaluebean)request.getattribute(servletdefines.displayvaluebean); // httpsession session; string methodidentifier = "dopost"; string methodtoexecute = new string(); com.ba.basis.util.navstate nav; //find method required called user's navstate //object held in session try { //session = request.getsession(true); // session = request.getsession(false); //nav = (com.ba.basis.util.navstate) session.getattribute(servletdefines.navigation_state); nav = (com.ba.basis.util.navstate) displayvaluebean.getnavstate(); methodtoexecute = nav.getservletmethodname(); } catch (nullpointerexception npe) { log(classidentifier, methodidentifier, "ebasis-2-100004", null, npe, request, response); } /* call required method introspection */ try { class c = this.getclass(); //create class of correct type inspect method names //create array of parameter types consistent method signature. //all methods called in way have 'request' , 'response' // passed in. class paramtypes[]; java.lang.reflect.method m; object arglist[]; if( (methodtoexecute != null) && methodtoexecute.equalsignorecase("removesystemfilter")){ paramtypes = new class[3]; paramtypes[0] = class .forname("javax.servlet.http.httpservletrequest"); paramtypes[1] = class .forname("javax.servlet.http.httpservletresponse"); paramtypes[2] = class .forname("com.ba.basis.servlet.displayvaluebean"); m = c.getdeclaredmethod(methodtoexecute, paramtypes); //create array of arguments passed method arglist = new object[3]; arglist[0] = request; arglist[1] = response; arglist[2] = displayvaluebean; request.setattribute(servletdefines.displayvaluebean, displayvaluebean); }else{ paramtypes = new class[2]; paramtypes[0] = class .forname("javax.servlet.http.httpservletrequest"); paramtypes[1] = class .forname("javax.servlet.http.httpservletresponse"); //find named method defined signature m = c.getdeclaredmethod(methodtoexecute, paramtypes); //create array of arguments passed method arglist = new object[2]; // system.out.println("before entering line 1167 in basis servlet tm :: "+runtime.getruntime().totalmemory()+" fm:: "+runtime.getruntime().freememory()); arglist[0] = request; // system.out.println("after entering line 1167 in basis servlet tm :: "+runtime.getruntime().totalmemory()+" fm:: "+runtime.getruntime().freememory()); arglist[1] = response; // system.out.println("after entering line 1168 in basis servlet tm :: "+runtime.getruntime().totalmemory()+" fm:: "+runtime.getruntime().freememory()); request.setattribute(servletdefines.displayvaluebean, displayvaluebean); } //long beforemethodcall = system.currenttimemillis(); //invoke method on instance of class, passing in desired // arguments m.invoke(this, arglist); //long aftermethodcall = system.currenttimemillis(); // log.write("time execute method :: "+m+" of class :: "+c+" within basisservlet's processhttprequest :: "+(aftermethodcall - beforemethodcall)+" ms"); } catch (java.lang.reflect.invocationtargetexception ite) { log(classidentifier, methodidentifier, "ebasis-3-100005", null, ite, request, response); } catch (nosuchmethodexception nsme) { log(classidentifier, methodidentifier, "ebasis-2-100006", "method called= " + methodtoexecute, nsme, request, response); } catch (exception e) { log(classidentifier, methodidentifier, "ebasis-2-100007", null, e, request, response); } }
controller.java
protected void processhttprequest(httpservletrequest request, httpservletresponse response ) throws servletexception, ioexception { // set no-cache part of response response.setheader("cache-control", "no-cache"); response.setheader("pragma", "no-cache"); response.setintheader("expires", 0); displayvaluebean displayvaluebean = (displayvaluebean)request.getattribute(servletdefines.displayvaluebean); // httpsession session; string methodidentifier = "dopost"; string methodtoexecute = new string(); com.ba.basis.util.navstate nav; //find method required called user's navstate //object held in session try { session.getattribute(servletdefines.navigation_state); nav = (com.ba.basis.util.navstate) displayvaluebean.getnavstate(); methodtoexecute = nav.getservletmethodname(); } catch (nullpointerexception npe) { log(classidentifier, methodidentifier, "ebasis-2-100004", null, npe, request, response); } /* call required method introspection */ try { class c = this.getclass(); //create class of correct type inspect method names //create array of parameter types consistent method signature. //all methods called in way have 'request' , 'response' // passed in. class paramtypes[]; java.lang.reflect.method m; object arglist[]; if( (methodtoexecute != null) && methodtoexecute.equalsignorecase("removesystemfilter")){ paramtypes = new class[3]; paramtypes[0] = class .forname("javax.servlet.http.httpservletrequest"); paramtypes[1] = class .forname("javax.servlet.http.httpservletresponse"); paramtypes[2] = class .forname("com.ba.basis.servlet.displayvaluebean"); m = c.getdeclaredmethod(methodtoexecute, paramtypes); //create array of arguments passed method arglist = new object[3]; arglist[0] = request; arglist[1] = response; arglist[2] = displayvaluebean; request.setattribute(servletdefines.displayvaluebean, displayvaluebean); }else{ paramtypes = new class[2]; paramtypes[0] = class .forname("javax.servlet.http.httpservletrequest"); paramtypes[1] = class .forname("javax.servlet.http.httpservletresponse"); //find named method defined signature m = c.getdeclaredmethod(methodtoexecute, paramtypes); //create array of arguments passed method arglist = new object[2]; // system.out.println("before entering line 1167 in basis servlet tm :: "+runtime.getruntime().totalmemory()+" fm:: "+runtime.getruntime().freememory()); arglist[0] = request; // system.out.println("after entering line 1167 in basis servlet tm :: "+runtime.getruntime().totalmemory()+" fm:: "+runtime.getruntime().freememory()); arglist[1] = response; // system.out.println("after entering line 1168 in basis servlet tm :: "+runtime.getruntime().totalmemory()+" fm:: "+runtime.getruntime().freememory()); request.setattribute(servletdefines.displayvaluebean, displayvaluebean); } //long beforemethodcall = system.currenttimemillis(); //invoke method on instance of class, passing in desired // arguments m.invoke(this, arglist); //long aftermethodcall = system.currenttimemillis(); // log.write("time execute method :: "+m+" of class :: "+c+" within basisservlet's processhttprequest :: "+(aftermethodcall - beforemethodcall)+" ms"); } catch (java.lang.reflect.invocationtargetexception ite) { log(classidentifier, methodidentifier, "ebasis-3-100005", null, ite, request, response); } catch (nosuchmethodexception nsme) { log(classidentifier, methodidentifier, "ebasis-2-100006", "method called= " + methodtoexecute, nsme, request, response); } catch (exception e) { log(classidentifier, methodidentifier, "ebasis-2-100007", null, e, request, response); } }
finding causes such runtime exceptions stackoverflowexception hard investigate without access code , knowing of user input. if error randomly appears. , in case of dynamic nature of methods calling posted.
i don't believe, specifying "/*"-pattern in deployment decriptor can cause such kind of random issues.
i can advice check (what stack trace says) business logic (reason of calling dopost() doget() , reason , point of redirection) in:
at com.ba.basis.servlet.controller.dopost(controller.java:658) @ com.ba.basis.servlet.controller.doget(controller.java:72)
and maybe method candidate check too:
at com.ba.basis.servlet.basisservlet.isloggedonuservalid(basisservlet.java:1749)
btw, cleaner change reflection-relevant code to:
paramtypes = new class[] {httpservletrequest.class, httpservletresponse.class, displayvaluebean.class}; m = c.getdeclaredmethod(methodtoexecute, paramtypes); //create array of arguments passed method arglist = new object[] {request, response, displayvaluebean};
Comments
Post a Comment