apache / apisix-java-plugin-runner

APISIX Plugin Runner in Java
https://apisix.apache.org/
Apache License 2.0
128 stars 95 forks source link

request help: request body charset - chinese error #220

Closed fitz-97 closed 1 year ago

fitz-97 commented 1 year ago

apisix-java-plugin-runner version:0.4.0 apsix version:3.0.0

Test post request contain chinese characters in OKHttp: { "name":"测试" } Custom filter in apisix-java-plugin-runner, get request body: { "name":"æµu008Bè¯u0095" }

fitz-97 commented 1 year ago

in request body , Not in response

fitz-97 commented 1 year ago

How can I modify the character set of a request before the PluginFilter.filter() ?

fitz-97 commented 1 year ago

like this {"name":"??????","nonce":"4317740522","timestamp":"1670570280","sign":"ff8eaa5caff13c78863c99d5b6b6264d"}

tzssangglass commented 1 year ago

same as #154

fitz-97 commented 1 year ago

same as #154

This method doesn't seem to solve the problem. You can try it

tzssangglass commented 1 year ago

This method doesn't seem to solve the problem. You can try it

It mainly depends on what encoding (maybe GBK?) your client is using for Chinese characters, and then use the same encoding to decode Chinese characters in java runner.

fitz-97 commented 1 year ago

This method doesn't seem to solve the problem. You can try it

It mainly depends on what encoding (maybe GBK?) your client is using for Chinese characters, and then use the same encoding to decode Chinese characters in java runner.

The client and code uses the same character set. However, I found the reason because my docker did not set the character set. when java plugin start System.getProperty("file.encoding") to be ANSI X3.4-1968 . The startup parameter plus -Dfile.encoding=utf-8 solves the problem. System.getProperty("file.encoding") will be utf-8 .