Saturday, 28 September 2013

Scalatra charset error

Scalatra charset error

I'm facing a charset encoding issue I cannot figure out how to resolve.
Here's what I'm doing:
I have a Scalatra Action calling a Apache Solr instance. The action in
Scalatra just opens a Strem on the Url where Solr responds, it takes the
output and prints it in the response
The response has invalid UTF-8 bytes
What do I miss?
The data in Solr's indexes are UTF-8 encoded: calling Solr directly from
Advanced Rest Client for Google Chrome I see everything is OK (I get a
utf-8 contentType response)
When reading the stream from Solr, I force UTF-8 decoding
val urlCon = url.openConnection()
Some(fromInputStream( urlCon.getInputStream, "utf8" ).getLines.mkString)
The Java options variable is ok (as defined in my project's sbt file)
declare -r default_jvm_opts="-Dfile.encoding=UTF8"
All my Eclipse project files are UTF-8 encoded
I force contentType to UTF-8 in the HTTP response
response.setCharacterEncoding("utf-8")
Here's the configuration of the software stack I'm running on:
Mac OS X Snow Leopard
Java 1.6.0_51
Apache Solr 4.3.0 deployed on Tomcat 7.0.41
Scalatra 2.2.1 using Scala 2.10.2, SBT 0.12.3, running on Jetty
8.1.8.v20121106
I'm quite sure the issue is in one of the software related to Scalatra
(Scalatra, SBT, Jetty, Scala) because as I told earlier, calling Solr
directly I see everything is correctly encoded.
Any idea?

No comments:

Post a Comment