3

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>
            ...
Jama A.
  • 15,680
  • 10
  • 55
  • 88
WalterP
  • 41
  • 5

2 Answers2

1

After almost 2 days of searching, I have found the solution: Tomcat needs the following JVM argument in order to solve the issue:

-Dfile.encoding=UTF-8 

BR Walter

WalterP
  • 41
  • 5
  • Thanks! just a clarification for other Java newbies like me: on my ubuntu machine it was done by adding "-Dfile.encoding=UTF-8" to JAVA_OPTS on /etc/default/tomcat7 – Shoham Jan 13 '15 at 13:11
0

Have you considered checking out Errai 2.0? http://errai-blog.blogspot.com/2012/02/quick-tour-of-errai-20.html

Mike Brock
  • 296
  • 1
  • 3
  • Hi, I tried to move to Errai 2.0 but it didn't work without making some changes to the application. Since we are almost done with implementation, I didn't want to make that changes. But anyway, I solved the problem with errai 1.3.2 – WalterP Feb 21 '12 at 08:32