11 Replies Latest reply on Sep 28, 2005 11:24 PM by leyang80

    UTF-8 FORM character encoding support?

    kevs3d

      sorry i forgot to login when posting that...

      Kev
      --
      http://www.alfresco.org

        • 1. Re: UTF-8 FORM character encoding support?
          kevs3d

          I have tried making these changes as suggested by Julian:

          org.jboss.portal.core.invocation.ContentTypeInterceptor
          line 113

           // Set content type
           response.setContentType(mimeType);
           response.setCharacterEncoding("UTF-8");
          


          So the pages are showing UTF-8 encoding in both IE and FireFox. This is fine and UTF-8 multi-byte characters are displaying ok.

          This image shows that working:
          http://www.kevs3d.co.uk/dev/jboss_utf8.png

          So now I attempt to enter UTF-8 characters in my FORM, the HTML FORM has the following attribute: acceptCharset="UTF-8" this image shows the input form:

          http://www.kevs3d.co.uk/dev/jboss_forminput.png

          As you can see it's working fine allowing you to input the characters.

          Now we submit the form. At this point if I check the value of the fields submitted to my bean in the debugger the values are a mess of characters and incorrect :( As can be seen on the next screen shot where we output the submitted characters back to the browser:

          http://www.kevs3d.co.uk/dev/jboss_formoutput.png

          Exactly the same web-application, running out of the Jboss Portal (still inside JBoss - but running as a TomCat web-app) works fine and the characters are submitted correctly back to the web-server.

          Does anyone have any idea what I need to do in JBoss Portal to fix this?

          Thanks,

          Kevin

          • 2. Re: UTF-8 FORM character encoding support?
            kevs3d

            Anyone help with this issue?

            Currently this means we cannot support UTF-8 multi-byte language clients with the JBoss Portal version of our application...

            Cheers,

            Kevin
            --
            http://www.alfresco.org

            • 3. Re: UTF-8 FORM character encoding support?

              could you try to setup the request.setCharacterEncoding("UTF-8") before JBoss Portal retrieves any parameter ?

              Do you have a portlet test case to send us that would use a form to submit itself data and then compare it ? that would be helpfull

              • 4. Re: UTF-8 FORM character encoding support?
                kevs3d

                 

                "julien@jboss.com" wrote:
                could you try to setup the request.setCharacterEncoding("UTF-8") before JBoss Portal retrieves any parameter ?


                I would, but in what class can I do that?

                Cheers,

                Kevin

                • 5. Re: UTF-8 FORM character encoding support?

                  try to place a servlet filter ahead of any processing on the portal servlet

                  • 6. Re: UTF-8 FORM character encoding support?
                    kevs3d

                    In the TomCat version of our app we are doing exactly that! But in the Portal world the web-app context is "/portal" at the point where Portlet processing takes place. Therefore our web-app filters at "/alfresco" never fire, so we have instead extended the Faces/GenericPortlet class to perform work that happens on every request. The problem here is when doView() etc. is executed it's already too late to set the encoding (and the PortletRequest/Response object does not have the appropriate methods anyway).

                    I guess I could add a filter to the portal source tree and web.xml, but i wouldn't see that as a perminant solution as it would require a special version of Jboss portal to run our app. I will try this though today to see if it fixes the problem so at least I'll know! :)

                    Cheers,

                    Kevin

                    • 7. Re: UTF-8 FORM character encoding support?

                      try it and tell us.

                      • 8. Re: UTF-8 FORM character encoding support?
                        kevs3d

                         

                        "julien@jboss.com" wrote:
                        try it and tell us.


                        I have and it fixed the issue. I modified the file:
                        org.jboss.portal.server.servlet.AbstractMainServlet

                        and changed this method thus:
                         protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
                         {
                         log.info("Setting character encoding to UTF-8...");
                         req.setCharacterEncoding("UTF-8");
                         PortalServer container = getContainer();
                         ServerManager manager = container.getManager();
                         InvocationFactory ctx = manager.getInvocationContext();
                         Invocation invocation = ctx.decode(req, resp);
                         invoke(invocation);
                         }
                        


                        This fixed the issue and Form characters are now correctly handled as UTF-8 in the portal pages.

                        For now, we will be patching the JBoss Portal bundle we ship with our app. Is this a change you can make configurable/permanent?

                        Thanks,

                        Kevin
                        --
                        http://www.alfresco.org

                        • 9. Re: UTF-8 FORM character encoding support?

                          I think it is already fixed in 2.2 but could you check to be sure ?

                          the place where it is done is in ContentTypeInterceptor, of course now the code take care of not using any request parameter before this interceptor is reached.

                          I will commit this modification in the branch 2.0 in order to have it in 2.0.1RC2

                          • 10. Re: UTF-8 FORM character encoding support?
                            smartx

                            It is much easier to write a filter that will set characterEncoding on the request if it isn't set already.

                            Attached one is configured very easily:

                            web.xml:
                            -------------------CUT HERE------------------

                            <filter-name>EncodingFixFilter</filter-name>
                            <filter-class>EncodingFixFilter</filter-class>

                            <filter-mapping>
                            <filter-name>EncodingFixFilter</filter-name>
                            <servlet-name>dispatcher</servlet-name>
                            REQUEST
                            </filter-mapping>
                            ------------------------------------------------

                            EncodingFixFilter.java
                            -------------------CUT HERE------------------

                            import java.io.IOException;
                            import javax.servlet.Filter;
                            import javax.servlet.FilterChain;
                            import javax.servlet.FilterConfig;
                            import javax.servlet.ServletException;
                            import javax.servlet.ServletRequest;
                            import javax.servlet.ServletResponse;

                            public class EncodingFixFilter implements Filter {
                            private FilterConfig filterConfig = null;
                            public EncodingFixFilter() {
                            }

                            public void doFilter(ServletRequest request, ServletResponse response,
                            FilterChain chain)
                            throws IOException, ServletException {
                            if (request.getCharacterEncoding() == null) {
                            String encoding = "UTF-8";
                            if (filterConfig != null) {
                            String encodingOverride = filterConfig.getInitParameter("defaultEncoding");
                            if (encodingOverride != null)
                            encoding = encodingOverride;
                            }
                            request.setCharacterEncoding(encoding);
                            }
                            chain.doFilter(request, response);
                            }

                            public FilterConfig getFilterConfig() {
                            return (this.filterConfig);
                            }

                            public void setFilterConfig(FilterConfig filterConfig) {
                            this.filterConfig = filterConfig;
                            }

                            public void destroy() {
                            }

                            public void init(FilterConfig filterConfig) {
                            this.filterConfig = filterConfig;
                            }

                            public String toString() {
                            if (filterConfig == null) return ("EncodingFixFilter()");
                            StringBuffer sb = new StringBuffer("EncodingFixFilter(");
                            sb.append(filterConfig);
                            sb.append(")");
                            return (sb.toString());
                            }
                            }

                            • 11. Re: UTF-8 FORM character encoding support?
                              leyang80

                              smartx,

                              Can you tell me the dedailed deployment of web.xml and EncodingFixFilter.java? I am new to JBoss portal. Thanks!