如何诊断Tomcat中的空指针异常

发布于 2024-12-09 20:01:33 字数 1463 浏览 0 评论 0原文

我正在开发一个在 Tomcat 中运行的 Java Servlet。我目前正在 Windows XP 计算机上使用 XAMPP 包(包括 Tomcat 7)对其进行测试(不用担心,我不打算在生产中使用它)。我这样做是因为我需要保持连接打开,以便我可以使用 Comet 服务器推送通信(服务器推送这是必须具备的要求)。

servlet 正在运行,并且我编写了一个测试客户端,它表明客户端和服务器正在完美通信。客户端使用 HTTP 标头通过 Internet 访问服务器,该标头在 servlet 中生成 BEGIN 事件,然后进行通信以响应 READ 事件。

然后,我尝试使用“真正的”客户端,这对我们来说是一个我无法完全控制的专有设备。很难获得有关它正在做什么的大量信息,更糟糕的是,其他程序员将来可能会对它进行更改。充其量,我所能做的就是对未来的变化提出建议。

设备发出带有标头的 HTTP 请求,服务器处理 BEGIN 事件,但是,当设备尝试继续对话时,连接断开,我在 Catalina 日志文件中收到以下内容:

2011 年 10 月 12 日 5:59 :00 PM org.apache.coyote.http11.Http11NioProcessor 进程 严重:处理请求时出错 java.lang.NullPointerException 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436) 在 org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:317) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515) 在 org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1544) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 在 java.lang.Thread.run(Thread.java:722)

我知道很难用这些有限的信息进行诊断,而这正是我的问题。如何获得有关 Tomcat 发生情况的更多信息?此外,我能做些什么来保护/通知/帮助设备的未来程序员避免犯同样的错误(无论发生什么)?显然,问题很严重,那么我是否面临黑客故意犯错误而导致我的服务器瘫痪的危险?

任何及时的回复和任何建议都将赢得我永远的感激。


只是更新 - 我不知道为什么,但是当我们从初始标头之后的通信中删除所有回车符和换行符时,问题就消失了。

感谢您的帮助。 StackOverflow 规则!

I am developing a Java Servlet to run in Tomcat. I am currently testing it with an XAMPP package, including Tomcat 7, on a Windows XP machine (don't worry, I am not planning on using this in production). I am doing this because I need to keep a connection open so I can use Comet server-push communications (server-push this is a must-have requirement).

The servlet is running, and I have written a test client which shows that client and server are communicating perfectly. The client hits the server from across the Internet with an HTTP header which generates a BEGIN event in the servlet, and it then communicates in response to READ events.

Then, I try a "real" client, which for us is a proprietary device which I do not have complete control over. It is difficult to get much information about what it is doing, and even worse, other programmers may make changes to it in the future. At best, all I will be able to do is make recommendations about future changes.

The device makes the HTTP request with header, the server handles the BEGIN event, but then, when the device tries to continue the conversation, the connection is dropped and I get the following in my catalina log file:

Oct 12, 2011 5:59:00 PM org.apache.coyote.http11.Http11NioProcessor process
SEVERE: Error processing request
java.lang.NullPointerException
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:317)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1544)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

I know it is difficult to diagnose with this limited information, and that is exactly my question. How can get more information about what is going on with Tomcat? Furthermore, is there anything I can do to protect/inform/aid future programmers of the device from making the same mistake (whatever that happens to be)? Apparently, the problem is SEVERE, so am I in danger of a hacker taking down my server by making the mistake on purpose?

Any prompt responses with any suggestions at all will earn my eternal gratitude.


Just to update - I have no idea why, but the problem went away when we removed all carriage returns and line feeds from the communications after the initial header.

Thanks for your help. StackOverflow rules!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼藏柔 2024-12-16 20:01:33

放入调试日志。然后你就会知道哪里失败了。了解请求有何不同以及为什么导致连接断开等事情很重要,可以通过记录服务器正在执行的所有操作来找到。 Log4j 很棒,因为它可以让您记录想要的任何内容,然后在不再需要时立即将其关闭。

“SEVERE”意味着您的服务器不能只是掩盖错误并继续执行程序,它并不表明安全问题有多严重,这可能不存在。

Put in debugging logs. Then you'll know where it failed. Things like knowing how the request is different, and why that causes the dropped connection are important and can be found by logging everything the server is doing. Log4j is great because it lets you log anything you want, then turn it off instantly when you don't need it any more.

"SEVERE" means that your server can't just gloss over the error and continue with the program, it doesn't indicate how severe the security issue is, which may not exist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文