WAR file works in tomcat but gives UTF-8 errors in Jetty, why?
I have Java webapp that I developed locally with m2eclipse + Jetty + eclipse, and deploy nightly to Tomcat. With Jetty, I get UTF-8 error
, when I send AJAX posts to the server. The same code works fine in tomcat.
On the Jetty side, I can see all the post parameters, and everything gets logged to the log files, but then a run time exception is thrown saying that the encoding is unrecognized.
My pages are all encoded as UTF-8, and the headers in the Post are UTF-8. It appears that something in Jetty or Eclipse doesn't like the utf-8 encoding and I can't figure out what it might be.
any thoughts?
update:
here is a stacktrace.[Click] [error] java.io.UnsupportedEncodingException: UTF-8;org.eclipse.jetty.io.RuntimeIOException: java.io.UnsupportedEncodingException: UTF-8;
at org.eclipse.jetty.io.UncheckedPrintWriter.setError(UncheckedPrintWriter.java:107)
at org.eclipse.jetty.io.UncheckedPrintWriter.write(UncheckedPrintWriter.java:280)
at org.eclipse.jetty.io.UncheckedPrintWriter.write(UncheckedPrintWriter.java:295)
at org.apache.click.ClickServlet.handleAjaxException(ClickServlet.java:1972)
at org.apache.click.ClickServlet.handleException(ClickServlet.java:458)
at org.apache.click.ClickServlet.handleRequest(ClickServlet.java:390)
at org.apache.click.ClickServlet.doPost(ClickServlet.java:294)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:533)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:475)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.se开发者_JAVA百科curity.SecurityHandler.handle(SecurityHandler.java:514)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:920)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:403)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:184)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:856)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:247)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:151)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:114)
at org.eclipse.jetty.server.Server.handle(Server.java:352)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:596)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1066)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:805)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:218)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:426)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:510)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.access$000(SelectChannelEndPoint.java:34)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:450)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.UnsupportedEncodingException: UTF-8;
at sun.nio.cs.StreamEncoder.forOutputStreamWriter(StreamEncoder.java:42)
at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:83)
at org.eclipse.jetty.server.HttpWriter.getConverter(HttpWriter.java:268)
at org.eclipse.jetty.server.HttpWriter.write(HttpWriter.java:125)
at org.eclipse.jetty.server.HttpWriter.write(HttpWriter.java:107)
at org.eclipse.jetty.io.UncheckedPrintWriter.write(UncheckedPrintWriter.java:271)
... 31 more
java.io.UnsupportedEncodingException: UTF-8;
That semicolon is suspicious. It isn't part of the normal error message/trace.
Sure that you or Ajax didn't set Content-Type
to text/html;charset=UTF-8;
or something? Use a HTTP request tracker like Firebug to be sure. I would consider it as another ugly bug in Jetty though. It is apparently not expecting more than two attributes in the header. If you like Jetty, report it to the Jetty guys.
i found the answer to my question. I am using the apache click framework and had recently upgraded from version 2.2.0 to 2.3.0-RC1. A bug was introduced in version 2.3.0-RC1 that caused duplicate contentType headers to be sent on AJAX requests. Tomcat was able to gracefully handle the mis-constructed header, Jetty was not.
i ended up applying a temp patch by overriding the problem function.
精彩评论