嵌入式Jetty NotUtf8Exception

时间:2013-12-09 17:32:19

标签: jetty url-encoding embedded-jetty

我们正在运行嵌入在码头容器中的Web应用程序。在jsp上有一个jsp:forward。 jsp:param的值为ISO-8859-1。我如何告诉Jetty,URL是ISO-8859-1?

系统属性org.eclipse.jetty.util.UrlEncoding.charset无效。 org.eclipse.jetty.util.Utf8Appendable$NotUtf8Exception: Not valid UTF8! incomplete UTF8 sequence...被抛出。

以下是jsp的一个示例:

<%@ page language="java" pageEncoding="ISO-8859-1" %>
...
<jsp:forward page="/forwardToAServlet">
<jsp:param name="param1" value="an+example+with+an+umlaut+gr%F6%DFere" />
</jsp:forward>

这里是stacktrace:

Caused by: org.eclipse.jetty.util.Utf8Appendable$NotUtf8Exception: Not valid UTF8! incomplete UTF8 sequence
    at org.eclipse.jetty.util.Utf8Appendable.checkState(Utf8Appendable.java:232) ~[jetty-util-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.util.Utf8StringBuffer.getStringBuffer(Utf8StringBuffer.java:65) ~[jetty-util-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.util.UrlEncoded.decodeString(UrlEncoded.java:843) ~[jetty-util-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.util.UrlEncoded.decodeTo(UrlEncoded.java:221) ~[jetty-util-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.server.Request.mergeQueryString(Request.java:2172) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:229) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:101) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:792) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
    at org.apache.jsp.WEB_002dINF.jsp.template.test_005jsp_jsp._jspService(test_005jsp_jsp.java:84) ~[na:na]
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0]
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:696) ~[jetty-servlet-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:526) [jetty-servlet-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:586) ~[jetty-security-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1110) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:453) [jetty-servlet-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1044) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:261) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:101) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
    at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:149) ~[javamelody-core-1.43.0.jar:1.43.0]
    at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:271) ~[javamelody-core-1.43.0.jar:1.43.0]
    at com.sun.proxy.$Proxy51.forward(Unknown Source) ~[na:na]
    at org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241) ~[tiles-servlet-2.2.2.jar:2.2.2]
    ... 94 common frames omitted

我在类org.eclipse.jetty.server.Request的方法mergeQueryString(String query)的源代码中找到了以下内容:

UrlEncoded.decodeTo(query,parameters, StandardCharsets.UTF_8,-1); //have to assume UTF-8 because we can't know otherwise

因此在方法URLEncoded.decodeTo()中使用UTF-8而不是使用System.setProperty(“org.eclipse.jetty.util.UrlEncoding.charset”,“ISO-8859-1”)的编码集

我能以某种方式解决这个问题吗?有任何想法吗? : - )

1 个答案:

答案 0 :(得分:1)

我怀疑这是Jetty 9.1.0中的一个错误。

所以我在https://bugs.eclipse.org/423692

提交了

缺点是Dispatcher.forward()需要执行Request.mergeQueryString(),但因为这将解码传入的查询字符串that decoding step is hardcoded at UTF8(HTTP的默认值),阻止您在org.eclipse.jetty.util.UrlEncoding.charset属性中指定的重写编码/字符集。

Jetty项目上的HTTP规范引导将评估这是Jetty中的有效错误还是HTTP规范的要求,并且必须保留原样。

遵循该错误,同时考虑在任何地方使用UTF-8,因为这是网络的事实上的编码。 (例如:HTTP / 2规范的早期指示也表明内容/文档编码将保持不变,但协议编码将严格按UTF-8强制执行)