Question

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.)
Was it helpful?

Solution

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?

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top