6 Replies Latest reply on Jul 22, 2013 9:04 AM by vinni298

    Weld 2.0 problems with special character encoding.

    vinni298

      Hi Community,

       

      I hope someone of you is able to help me. Actual we are using "weld-servlet-1.1.10.Final.jar" in a Tomcat 7. With this one everything works fine.

      Now we tried to upgrade to weld 2.0. The Application is working fine as well but now we have problem with the encoding of special characters

      like the German "äöü". Every time I enter such a letter in an input field the bean value will be something like this: äüöäÃ.

       

      Do someone know this behavior?

       

      Kind Regards,

      Vinni

        • 1. Re: Weld 2.0 problems with special character encoding.
          luksa

          I noticed this once, but with weld 1.1.

           

          Something is screwing up the servlet request's characterEncoding. This may be caused by weld's ConversationFilter.

           

          You can fix it by adding your own filter that sets the characterEncoding to UTF-8 or whatever you're using.

          • 2. Re: Weld 2.0 problems with special character encoding.
            luksa

            Of course, the filter needs to be first in line, as you must call servletRequest.setCharacterEncoding("UTF-8") before anyone invokes servletRequest.getParameter().

            • 3. Re: Weld 2.0 problems with special character encoding.
              vinni298

              Thank you very much for your answer. But unfortunately the parameters are already parsed when I hit the first Filter.

              It seems that the problem is a ServletListener implemented by Weld. here is the call stack:

               

              Request.parseParameters:2853
              Request.getParameter:1131
              ConversationContextActivator.getConversationId:115
              ConversationContextActivator.activateConversationContext:82
              HttpContextLifecycle.requestInitialized:132
              WeldListener.requestInitialized:107
              ForwardingServletListener.requestInitialized:42
              StandardContext.fireRequestInitEvent:5974
              StandardContextValve.invoke:181
              AuthenticatorBase.invoke:472
              StandardHostValve.invoke:151
              ErrorReportValve.invoke:100
              AccessLogValve.invoke:929
              StandardEngineValve.invoke:118
              CoyoteAdapter.service:405
              Http11Processor.process:269
              AbstractProtocol$AbstractConnectionHandler.process:515
              JIoEndpoint$SocketProcessor.run:302
              ThreadPoolExecutor$Worker.runTask:895
              ThreadPoolExecutor$Worker.run:918
              Thread.run:662

               

              This is called before the first Filter is invoked. In this case it seems that I have no chance to set the encoding before the first Parameter is read.

              • 4. Re: Weld 2.0 problems with special character encoding.
                luksa

                OK, you also need to manually register Weld's ConversationFilter (org.jboss.weld.servlet.ConversationFilter). WeldListener will not parse parameters if the ConversationFillter is registered in web.xml.

                 

                I know this is a real pain. I'll see if we can fix this.

                • 5. Re: Weld 2.0 problems with special character encoding.
                  luksa

                  I have created a jira issue: https://issues.jboss.org/browse/WELD-1467

                  • 6. Re: Weld 2.0 problems with special character encoding.
                    vinni298

                    Thank you very much. I'll try this the next days. Hope this will get fixed.