I got a form in my application. I input there russian and chineese symbols. Http request from browser to application looks like this:
POST /payout/process HTTP/1.0
Host: my_host
X-Real-IP: 10.3.4.6
X-Forwarded-For: 10.3.4.6
X-Forwarded-Proto: https
Connection: close
Content-Length: 286
Accept: */*
Origin: https://my_host
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/43.0.2357.130 Chrome/43.0.2357.130 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: https://my_host
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,ru;q=0.6
Cookie: piwikExternalId=; COOKIEPOO="d14ef459332e84ab12f8187181e01e50df3abd61-5d635c8478334352d2865b11dd747d6d3fe84704=1&d6e2c1ad27a45b7d9b8ed7b039ab96c7d3ef8051=1&7cf1199693fa6d40bf3654db17ec4773e0d61f38=1"
group=27&qwipi.customer_name=%D1%84%D1%8B%D0%B2&qwipi.bank_code=%E6%8B%9B%E5%95%86%E9%93%B6%E8%A1%8C&qwipi.bank_branch=%D1%84%D0%B2%D0%B0&customer_purse=%D1%84%D1%8B%D0%B2%D0%B0&qwipi.bank_city=%D1%84%D0%B2%D1%8B%D0%B0&qwipi.bank_province=%E6%8B%9B%E5%95%86%E9%93%B6%E8%A1%8C&amount=546
Check out request body, parameter customer_name. Decoded it will give фыв. Chec out paramter bank_branch. Decoded it will give 招商银行.
I log the request to console and graylog like this:
def logRequest(request: Request[AnyContent]) {
request.body match {
case AnyContentAsFormUrlEncoded(data) => Logger.info(data.toString())
case AnyContentAsText(text) => Logger.info(text + ", ")
case other => Logger.info(other.toString())
}
}
and I get something like
body: 'qwipi.bank_code' => '??????', 'qwipi.bank_province' => '??????', 'qwipi.customer_name' => '??????', 'amount' => '654', 'qwipi.bank_branch' => '??????', 'qwipi.bank_city' => '??????'
i.e., all non-latin symbols turn to question signs.
echo $LANG outputs en_US.UTF-8, so I guess my application's encoding (whatever that means -- application's itself or java's or playframework's or smth else) is different.
This is what I tried:
def logRequest(request: Request[AnyContent]) {
Logger.info(new String(appendRequestData(request).getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8))
}
i.e., got the byte array in UTF-8 and turn it into the String which is in UTF-8 as well. But nothing changed.
What I also tried was starting an application passing -Dfile.encoding=UTF8 key -- the result still the same.
So how can I make my stuff logged properly? What things I might have missed?
It didn't help converting my string from one encoding to another on the fly. It didn't help passing UTF-8 to scalac option in Build.scala like that
So I just passed -Dfile.encoding=UTF-8 when starting my java service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With