使用 Resin 和 Grails 时抛出 UnsupportedEncodingException
我在 Grails 下运行的 Grails Web 应用程序中遇到了一个奇怪的问题:
由于各种未知的编码字符串(例如 "ISO8859_10"
),经常抛出 java.io.UnsupportedEncodingException
,"ISO-8859-10"
),奇怪的是这完全是在 Resin 和 Grails 代码中完成的。也就是说,抛出异常时不涉及任何自定义代码。
我不确定是 Grails 还是 servlet 容器的代码应该处理该异常。但我认为应该在某个地方处理异常,而不是一直冒泡到 stderr。
这是完整的异常:
java.io.UnsupportedEncodingException: ISO-8859-10
at com.caucho.vfs.i18n.JDKWriter$OutputStreamEncodingWriter.<init>(JDKWriter.java:112)
at com.caucho.vfs.i18n.JDKWriter.create(JDKWriter.java:79)
at com.caucho.vfs.Encoding.getWriteEncoding(Encoding.java:231)
at com.caucho.server.connection.ToByteResponseStream.setEncoding(ToByteResponseStream.java:137)
at com.caucho.server.connection.AbstractHttpResponse.setLocale(AbstractHttpResponse.java:1683)
at com.caucho.server.connection.HttpServletResponseImpl.setLocale(HttpServletResponseImpl.java: 115)
at javax.servlet.ServletResponseWrapper.setLocale(ServletResponseWrapper.java:139)
at javax.servlet.ServletResponseWrapper.setLocale(ServletResponseWrapper.java:139)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1035)
at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:290)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:114)
我的问题:
- 应该处理异常吗?如果是这样,这是 servlet 容器 (Resin) 还是 Web 框架 (Grails) 的责任?
- 你会如何解决这个问题? (我不想让异常日志中充满我无能为力的异常。)
I've encountered a strange problem in a Grails webapp running under Grails:
java.io.UnsupportedEncodingException
is thrown quite frequently due to various unknown encoding strings (such as "ISO8859_10"
, "ISO-8859-10"
), and the strange thing is that this is done entirely within the Resin and Grails code. That is - no custom code is involved when the exception is thrown.
I'm not sure if it is Grails or the servlet container's code that should handle the exception. But I'd assume that the exception should be handled somewhere and not bubble up all the way to stderr.
This is the exception in full:
java.io.UnsupportedEncodingException: ISO-8859-10
at com.caucho.vfs.i18n.JDKWriter$OutputStreamEncodingWriter.<init>(JDKWriter.java:112)
at com.caucho.vfs.i18n.JDKWriter.create(JDKWriter.java:79)
at com.caucho.vfs.Encoding.getWriteEncoding(Encoding.java:231)
at com.caucho.server.connection.ToByteResponseStream.setEncoding(ToByteResponseStream.java:137)
at com.caucho.server.connection.AbstractHttpResponse.setLocale(AbstractHttpResponse.java:1683)
at com.caucho.server.connection.HttpServletResponseImpl.setLocale(HttpServletResponseImpl.java: 115)
at javax.servlet.ServletResponseWrapper.setLocale(ServletResponseWrapper.java:139)
at javax.servlet.ServletResponseWrapper.setLocale(ServletResponseWrapper.java:139)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1035)
at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:290)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:114)
My questions:
- Should the exception be handled? If so, is it the responsibility of the servlet container (Resin) or the web framework (Grails)?
- How would you go about solving this? (I'd rather not having the exception log cluttered with exceptions that I can do nothing about.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 Grails 不太了解,但也许你可以尝试找出这种奇怪的编码从何而来。
您的请求是否发送 Accept-Charset 标头?
如果您在resin.conf 中将“file.encoding”系统属性设置为有意义的值(例如UTF-8),效果是否会更好?
I don't know much about Grails, but maybe you could try to find out where this weird encoding comes from.
Do your requests send Accept-Charset headers?
Do things work better if you set the "file.encoding" system property to something meaningful like UTF-8 in your resin.conf?
您还可以在应用程序上下文中设置
localeResolver
bean。DispatcherServlet
将使用它来解析区域设置。我自己没有尝试过,但我的建议是使用 org.springframework.web.servlet.i18n.FixedLocaleResolver。如果您没有进行任何设置,它将委托给Locale.getDefault()
。You can also set up a
localeResolver
bean in your application context. TheDispatcherServlet
will use that to resolve the locale. I haven't tried it myself, but my suggestion is to use theorg.springframework.web.servlet.i18n.FixedLocaleResolver
. It will delegate toLocale.getDefault()
if you don't have any set up.