Reputation: 272
I am trying post the following string "`.4.13 - 30613 £ ₤ © ™" to a Grails Server once Deployed as a WAR and I'm having no luck when communicating between two instances of Tomcat7
Our server works as an API, and the web layer entirely seperately. Data is saved to the DB by POST request to Web App, then the Web App sends a POST (or PUT for updates) request to the server to save the data.
This works fine locally when I start the Web App and Server with "Run-App" but not when we move to non-local enviroments with Tomcat7 and deployed WAR files.
Initally I thought this may be related to a reported bug http://jira.grails.org/browse/GRAILS-8873 but upon closer inspection, it appears that UTF-8 is the default anyway, and is currently in use
The non-local enviroments use the following structure (Deployed WAR in Tomcat7)
Entry Point -> Apache 2.2 < - > Web App < - > Server
The local environments use the following structure (Run App)
Entry Point -> Web Abb < - > Server
I have output the value at the time of marshalling to string to ensure that before it is sent to the server, it is of the correct encoding
DEBUG MarshallService - Marshalling Property : name of value [ `.4.13 - 30613 £ ? © ™]
This is directly from the log for the outgoing request from the Web App to the Server Ignore the fact that the content length is wrong, i've truncated the body for the purposes of readability.
DEBUG org.apache.http.headers - >> PUT /baseline-server/baseline/pwqi9tzyTRWX5oZogfKjJw HTTP/1.1
DEBUG org.apache.http.headers - >> Accept: application/json; charset=utf-8
DEBUG org.apache.http.headers - >> Content-Length: 349
DEBUG org.apache.http.headers - >> Content-Type: application/json
DEBUG org.apache.http.headers - >> Host: localhost:9001
DEBUG org.apache.http.headers - >> Connection: Keep-Alive
DEBUG org.apache.http.headers - >> Accept-Encoding: gzip,deflate
DEBUG org.apache.http.wire - >> "{"name":"`.4.13 - 30613 [0xa3] ? [0xa9] [0x99]"}
I have read several answers across several other locations and done the following
In Apache 2.2 HTTPD.conf before ANY VirtualHost
AddDefaultCharset utf-8
In both Tomcat Instances (Web.xml)
<filter>
<filter-name>setCharacterEncodingFilter</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<async-supported>true</async-supported>
</filter>
Additionally, as per other answers, I ahve ensured we are using webxml 1.4.1
And yet, when the value reaches the Server side, the values are all ???
What I find particularly strange is the outgoing JSON doesn't appear to show UTF-8 characters at all
Any assistance would be greatly appreciated
Upvotes: 4
Views: 3738
Reputation: 5540
I can suggest some configs to try.... Let me know if any can resolve your problem :)
Are you on ubuntu or other linux? Try to set
LANG="en_US.UTF-8"
LANGUAGE="en_US:en"
LC_ALL="en_US.UTF-8"
in /etc/default/locale and run
sudo locale-gen
( and reboot )
Are you using a db connection? Check if the connection in config/dasource.groovy is utf8
url = "jdbc:mysql://localhost/?useUnicode=true&characterEncoding=UTF-8"
Put this settings in your /etc/Config.groovy
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8"
Check that your tomcat connector is configured utf8
<Connector ... URIEncoding="UTF-8">
Upvotes: 2