"IllegalArgumentException: !utf8" 大多数请求出现 Jetty 错误

"IllegalArgumentException: !utf8" Jetty error on most requests

我今天对我的应用做了一个小改动,突然间我们 90% 的请求都在这一行抛出错误:

private void serve(HttpServletRequest req, HttpServletResponse resp) {
    String bundle = req.getParameter("bundle");

我不知道该怎么办 – 异常深藏在 Jetty 的查询请求解析器中。这些请求没有什么异常,我认为没有任何非 UTF8 字符,除非它们是不可打印的或其他东西。

/sync
java.lang.IllegalArgumentException: !utf8
    at org.mortbay.util.Utf8StringBuffer.append(Utf8StringBuffer.java:121)
    at org.mortbay.util.UrlEncoded.decodeUtf8To(UrlEncoded.java:458)
    at org.mortbay.util.UrlEncoded.decodeTo(UrlEncoded.java:503)
    at org.mortbay.jetty.Request.extractParameters(Request.java:1565)
    at org.mortbay.jetty.Request.getParameter(Request.java:858)
    at javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:158)
    at javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:158)
    at com.keithlea.whamserver.sync.ServerSyncServlet.serve(ServerSyncServlet.java:169)
    at com.keithlea.whamserver.sync.ServerSyncServlet.doGet(ServerSyncServlet.java:77)
    at com.keithlea.whamserver.sync.ServerSyncServlet.doPost(ServerSyncServlet.java:67)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:278)
    at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:268)
    at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:180)
    at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:93)
    at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:120)
    at com.google.inject.servlet.GuiceFilter.call(GuiceFilter.java:134)
    at com.google.inject.servlet.GuiceFilter.call(GuiceFilter.java:131)
    at com.google.inject.servlet.GuiceFilter$Context.call(GuiceFilter.java:208)
    at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:131)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.googlecode.objectify.cache.AsyncCacheFilter.doFilter(AsyncCacheFilter.java:59)
    at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:49)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.keithlea.whamserver.EditorDomainFilter.doFilter(EditorDomainFilter.java:90)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:254)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:527)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:745)

感谢 JoakimErdfelt,我解决了这个问题。问题是这是一个 POST 请求,并且 HttpServletRequest 试图将输入数据解析为查询字符串。我可以通过先将查询字符串读入缓冲区来防止这种情况发生。这是新代码:

private void serve(HttpServletRequest req, HttpServletResponse resp) {
    UserInput input = readUserInput(req.getInputStream());
    String bundle = req.getParameter("bundle");

这似乎已经完全解决了这个问题。