当隐式调用 request.getAttribute("atg.parent.session.id") 时,我会发生许多 NPE。堆栈跟踪如下(包裹在跟踪日志之间)。
[2012/02/03 12:53:26:953 SAST] 00000162 srt 1 com.ibm.ws.webcontainer.srt.SRTServletRequest getHeader this->com.ibm.ws.webcontainer.srt.SRTServletRequest@14f314f3: name --> SOAPAction header --> "http://acme.com/services/pick/SubmitOrder2"
[2012/02/03 12:53:26:953 SAST] 00000162 http 1 com.ibm.ws.webcontainer.srt.http.HttpInputStream fill fill
[2012/02/03 12:53:26:960 SAST] 00000162 channel 1 com.ibm.ws.webcontainer.channel.WCCByteBufferInputStream bufferIsGood buffer is good remaining --> 1635
[2012/02/03 12:53:26:960 SAST] 00000162 http 1 com.ibm.ws.webcontainer.srt.http.HttpInputStream read read length -->2048
[2012/02/03 12:53:26:960 SAST] 00000162 channel 1 com.ibm.ws.webcontainer.channel.WCCByteBufferInputStream bufferIsGood buffer is good remaining --> 1123
[2012/02/03 12:53:26:960 SAST] 00000162 channel 1 com.ibm.ws.webcontainer.channel.WCCByteBufferInputStream read Reset requested len --> 1574 to size remaining in current buffer --> 1123
[2012/02/03 12:53:26:960 SAST] 00000162 http 1 com.ibm.ws.webcontainer.srt.http.HttpInputStream read read returning -->1597, total=1635,limit=1635
[2012/02/03 12:53:26:961 SAST] 00000162 http 1 com.ibm.ws.webcontainer.srt.http.HttpInputStream read read length -->2048
[2012/02/03 12:53:26:962 SAST] 00000162 http 1 com.ibm.ws.webcontainer.srt.http.HttpInputStream read Over the limit: -1
[2012/02/03 12:53:26:962 SAST] 00000162 http > com.ibm.ws.webcontainer.srt.http.HttpInputStream close ENTRY total=1635,limit=1635
[2012/02/03 12:53:26:962 SAST] 00000162 http 1 com.ibm.ws.webcontainer.srt.http.HttpInputStream finish finish
[2012/02/03 12:53:26:962 SAST] 00000162 srt 1 com.ibm.ws.webcontainer.srt.SRTServletResponse isSkipInputStreamRead skipInputStreamRead = false
[2012/02/03 12:53:26:962 SAST] 00000162 http < com.ibm.ws.webcontainer.srt.http.HttpInputStream close RETURN total=1635,limit=1635
[2012/02/03 12:53:26:964 SAST] 00000162 PickingManage I com.acme.services.pick.PickingManagementHttpBindingImpl submitOrder2 Method: submitOrder2
[2012/02/03 12:53:26:967 SAST] 00000162 webapp 1 com.ibm.ws.webcontainer.webapp.WebAppDispatcherContextImpl isSecurityEnabledForApplication serverSecurityEnabled
[2012/02/03 12:53:26:967 SAST] 00000162 srt 1 com.ibm.ws.webcontainer.srt.SRTServletRequest getRemoteUser (security enabled)--> user XXXX
[2012/02/03 12:53:26:968 SAST] 00000162 PickingManage I com.acme.services.pick.PickingManagementHttpBindingImpl getUsername current user is: XXXX
[2012/02/03 12:53:26:971 SAST] 00000162 channel 1 com.ibm.ws.webcontainer.channel.WCCRequestImpl getHeader header --> Axis/1.4
[2012/02/03 12:53:26:971 SAST] 00000162 srt 1 com.ibm.ws.webcontainer.srt.SRTServletRequest getHeader this->com.ibm.ws.webcontainer.srt.SRTServletRequest@14f314f3: name --> user-agent
[2012/02/03 12:53:27:564 SAST] 00000162 srt 1 com.ibm.ws.webcontainer.srt.SRTServletRequest getAttribute this->com.ibm.ws.webcontainer.srt.SRTServletRequest@28e428e4: name --> atg.parent.session.id
[2012/02/03 12:53:27:565 SAST] 00000162 SystemOut O /com/acme/order/picking/PickingService An exception occurred: java.lang.NullPointerException java.lang.NullPointerException
at com.ibm.ws.webcontainer.srt.SRTServletRequest$SRTServletRequestHelper.access$200(SRTServletRequest.java:2629)
at com.ibm.ws.webcontainer.srt.SRTServletRequest.getAttribute(SRTServletRequest.java:276)
at atg.servlet.MutableHttpServletRequest.getAttribute(MutableHttpServletRequest.java:505)
at atg.servlet.MutableHttpServletRequest.getAttribute(MutableHttpServletRequest.java:470)
at atg.servlet.NameContextManager.getNameContextId(NameContextManager.java:320)
at atg.servlet.ServletUtil.getParentSessionId(ServletUtil.java:558)
at atg.commerce.messaging.CommerceMessageImpl.<init>(CommerceMessageImpl.java:230)
at com.acme.fulfillment.PickingMessage.<init>(PickingMessage.java:5)
at com.acme.order.picking.PickingService.submitOrder(PickingService.java:128)
at com.acme.services.pick.PickingManagementHttpBindingImpl.submitOrder2(PickingManagementHttpBindingImpl.java:177)
at com.acme.services.pick.PickingManagementHttpBindingSkeleton.submitOrder2(PickingManagementHttpBindingSkeleton.java:165)
at sun.reflect.GeneratedMethodAccessor1040.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:388)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:283)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
[2012/02/03 12:53:27:566 SAST] 00000162 SystemOut O
[2012/02/03 12:53:27:571 SAST] 00000162 PickingManage E com.acme.services.pick.PickingManagementHttpBindingImpl submitOrder2 An exception occurred: java.lang.NullPointerException
java.lang.NullPointerException
at com.ibm.ws.webcontainer.srt.SRTServletRequest$SRTServletRequestHelper.access$200(SRTServletRequest.java:2629)
at com.ibm.ws.webcontainer.srt.SRTServletRequest.getAttribute(SRTServletRequest.java:276)
at atg.servlet.MutableHttpServletRequest.getAttribute(MutableHttpServletRequest.java:505)
at atg.servlet.MutableHttpServletRequest.getAttribute(MutableHttpServletRequest.java:470)
at atg.servlet.NameContextManager.getNameContextId(NameContextManager.java:320)
at atg.servlet.ServletUtil.getParentSessionId(ServletUtil.java:558)
at atg.commerce.messaging.CommerceMessageImpl.<init>(CommerceMessageImpl.java:230)
at com.acme.fulfillment.PickingMessage.<init>(PickingMessage.java:5)
at com.acme.order.picking.PickingService.submitOrder(PickingService.java:128)
at com.acme.services.pick.PickingManagementHttpBindingImpl.submitOrder2(PickingManagementHttpBindingImpl.java:177)
at com.acme.services.pick.PickingManagementHttpBindingSkeleton.submitOrder2(PickingManagementHttpBindingSkeleton.java:165)
at sun.reflect.GeneratedMethodAccessor1040.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:388)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:283)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1655)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1595)
[2012/02/03 12:53:27:586 SAST] 00000162 srt > com.ibm.ws.webcontainer.srt.SRTServletResponse setStatus ENTRY status --> 500 [com.ibm.ws.webcontainer.srt.SRTServletResponse@15651565]
[2012/02/03 12:53:27:586 SAST] 00000162 srt 1 com.ibm.ws.webcontainer.srt.SRTServletResponse getRequest request=com.ibm.ws.webcontainer.srt.SRTServletRequest@14f314f3
[2012/02/03 12:53:27:587 SAST] 00000162 srt 1 com.ibm.ws.webcontainer.srt.SRTServletRequest getWebAppDispatcherContext
所以最初,线程很高兴地使用请求@14f314f3。然后,由于未知原因,它尝试从不同的请求(@28e428e4)中检索 atg.parent.session.id,并在一切都出错后返回到原始请求(@14f314f3)。
发生此异常时,它几乎总是会重复自身,直到重新启动部署 EAR 的实例。似乎请求中有一些陈旧的数据,并且以某种方式被保留,但我无法追踪到这一点。
PickingService 组件的范围是“全局的”,但它似乎是线程安全的。CommerceMessageImpl 的 PickingMessage 扩展覆盖了一个对请求没有影响的方法。
有什么方法可以让我弄清楚请求为什么/如何突然改变?此问题并非在所有实例上或所有请求上都始终如一地发生。但是,它在我们的生产环境中引起了问题。任何帮助表示赞赏。