使用 Resin 和 Grails 时抛出 UnsupportedEncodingException

发布于 2024-08-31 15:15:14 字数 1783 浏览 11 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失而复得 2024-09-07 15:15:14

我对 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?

苯莒 2024-09-07 15:15:14

您还可以在应用程序上下文中设置 localeResolver bean。 DispatcherServlet 将使用它来解析区域设置。我自己没有尝试过,但我的建议是使用 org.springframework.web.servlet.i18n.FixedLocaleResolver。如果您没有进行任何设置,它将委托给 Locale.getDefault()

You can also set up a localeResolver bean in your application context. The DispatcherServlet will use that to resolve the locale. I haven't tried it myself, but my suggestion is to use the org.springframework.web.servlet.i18n.FixedLocaleResolver. It will delegate to Locale.getDefault() if you don't have any set up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文