1 Reply Latest reply: Feb 20, 2012 7:48 AM by walterp RSS

Errai and Tomcat have an UTF-8 Problem?

walterp Newbie

Hello,

 

we are developing an web application using GWT 2.4, Errai 1.3.2. It is running on Tomcat 6 (6.0.35) and built by Maven (3.0.4).

 

When running this application on Tomcat, the transfer of special cases is not working. More specific, the request works fine but the response of special characters converts them to ?. When using the errai maven archetype, it has the same behaviour. When using GWT-RPC instead of errai RPC, everything works fine. Running the same application in Dev-Mode, the problem doesn't occur.

 

When looking at the request/response in chrome, both have character encoding UTF-8.

 

I think this might be an errai bug because there is some String encoding in errai before sending the response.

 

It would be great, if someone could help me!! It's really a tricky problem...

 

 

Thanks, Walter

 

----------

   

PS: I have already tried the following potential solutions, which all do not work:

 

 

Setting index.html head:

 

 

   <meta http-equiv="content-type" content="text/html; charset=UTF-8">

 

 

Define a custom Servlet Filter

 

 

WEB.xml

 

 

<filter>

                    <filter-name>SessionFilter</filter-name>

                    <filter-class>at.apa.excelsa.web.server.SessionFilter</filter-class>

        <init-param>

            <param-name>requestEncoding</param-name>

            <param-value>UTF-8</param-value>

        </init-param>

          </filter>

          <filter-mapping>

                    <filter-name>SessionFilter</filter-name>

                    <url-pattern>*</url-pattern>

          </filter-mapping>

 

 

Filter.java

 

 

public class SessionFilter implements Filter {

 

 

          String encoding;

 

 

          @Override

          public void init(FilterConfig filterConfig) throws ServletException {

                    encoding = filterConfig.getInitParameter("requestEncoding");

        if (encoding == null) {

            encoding = "UTF-8";

        }

          }

 

          @Override

          public void doFilter(ServletRequest request, ServletResponse response,

                              FilterChain chain) throws IOException, ServletException {

 

                    if(request.getCharacterEncoding()==null) {

                              request.setCharacterEncoding(encoding);

                    }

 

 

                    response.setContentType("text/html; charset=UTF-8");

                    response.setCharacterEncoding("UTF-8");

 

                    chain.doFilter(request, response);

          }

 

 

On Tomcat Server.xml setting URIEncoding

 

     <Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" useBodyEncodingForURI="true" URIEncoding="UTF-8" />

 

 

Maven in pom.xml

 

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    ...

    <build>

              <outputDirectory>war/WEB-INF/classes</outputDirectory>

                          <plugins>

                             <plugin>

                                            <groupId>org.codehaus.mojo</groupId>

                                            <artifactId>gwt-maven-plugin</artifactId>

                                            <version>${gwt.maven}</version>

                                            <configuration>

                        ...

                                                      <extraJvmArgs>-Xmx512m **-Dfile.encoding=UTF-8**</extraJvmArgs>

                        ...

                                            </configuration>

                                            <executions>

                                                      <execution>

                                                                <goals>

                                                                          <goal>resources</goal>

                                                                          <goal>compile</goal>

                                                                </goals>

                                                      </execution>

                                            </executions>

                                  </plugin>

                ...