Wicket CaptchaImageResource 在 Linux 服务器上创建零长度图像
我正在使用 Wicket 的 CaptchaImageResource< /a> 保护提交表单免受机器人攻击。它在我的测试环境(Mac)中使用 Jetty 服务器以及部署到本地 Tomcat 实例时运行良好。
但是,当应用程序部署到远程 Linux 服务器上的 Tomcat 7 时,验证码图像无法呈现。相反,我得到了零字节响应。以下是 curl -v
返回的图像 URL:
HTTP/1.1 200 OK
Date: Thu, 28 Jul 2011 14:28:22 GMT
Set-Cookie: JSESSIONID=6D37183A1FF2C3F43C35B49433A0FC1B; Path=/; HttpOnly
Cache-Control: no-cache, must-revalidate
Content-Type: image/png
Content-Length: 0
Connection: close
* Closing connection #0
我的第一直觉是 Tomcat 需要使用 -Djava.awt.headless=true
运行。我进行了设置,并使用 ps
验证它实际上正在使用该选项运行,但验证码仍然无法呈现。
我在 Tomcat 日志中没有看到任何错误消息或警告。我甚至启用了远程调试,并在 CaptchaImageResource.render()
深处设置了断点。它正在进入该方法,但我从未看到它返回;在第 291 行附近的某个地方,它神秘地停止了我的断点。
服务器 JVM 是 java-1.6.0-openjdk.x86_64
。 JVM 无法在无头模式下渲染 AWT 图形有什么原因吗?
I'm using Wicket's CaptchaImageResource to protect a submission form against bots. It works fine in my test environment (a Mac) using the Jetty server, as well as when deployed to a local Tomcat instance.
But the Captcha image fails to render when the app is deployed to Tomcat 7 on a remote Linux server. Instead I get a zero-byte response. Here's what curl -v
returns for the image URL:
HTTP/1.1 200 OK
Date: Thu, 28 Jul 2011 14:28:22 GMT
Set-Cookie: JSESSIONID=6D37183A1FF2C3F43C35B49433A0FC1B; Path=/; HttpOnly
Cache-Control: no-cache, must-revalidate
Content-Type: image/png
Content-Length: 0
Connection: close
* Closing connection #0
My first instinct was that Tomcat needed to be run with -Djava.awt.headless=true
. I set that up, and verified with ps
that it is in fact running with that option, but the captcha still fails to render.
I don't see any error messages or warnings in Tomcat's logs. I went so far as to enable remote debugging, and set breakpoints deep in CaptchaImageResource.render()
. It's entering that method, but I never see it return; somewhere around line 291 it just mysteriously stops hitting my breakpoints.
The server JVM is java-1.6.0-openjdk.x86_64
. Is there any reason why that JVM wouldn't be able to render AWT graphics in headless mode?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊,biziclop引导我走向正确的方向。我编写了这个快速独立(即无 Tomcat)测试:
这导致了以下错误:
对该字符串的一些谷歌搜索导致我安装了以下软件包:
现在它可以工作了。
Ah, biziclop led me in the right direction. I wrote this quick standalone (i.e. no-Tomcat) test:
Which resulted in the following error:
Some Googling on that string led me to install the following packages:
And now it works.