apisix-java-plugin-runner
apisix-java-plugin-runner copied to clipboard
bug: POST request with body contain chinese characters exist encoding problem
Issue description
Environment
apisix-java-plugin-runner versionï¼0.2.0 apsix versionï¼2.13.1
Minimal test code / Steps to reproduce the issue
- Test post request contain chinese characters in OKHttpï¼
{"source":"é«å¾·å°å¾","content":"https://surl.amap.com/1PoSAsa1l4Ud","deviceId":"123456"} - inner OKHttpï¼body will be translated to utf-8 format bytes:
Charset charset = Util.UTF_8; byte[] bytes = content.getBytes(charset); - Custom filter in apisix-java-plugin-runner, get request body:
{"source":"é«Âå¾·å°å¾","content":"https://surl.amap.com/1PoSAsa1l4Ud","deviceId":"123456"}
apisix-java-plugin-runner also use UTF_8 , see: https://github.com/apache/apisix-java-plugin-runner/pull/53/files
@tzssangglass
I mean body in request, fixed by modifing ExtraInfoResponse.getResult:
from:
public String getResult() {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < this.resp.resultLength(); i++) {
builder.append((char) this.resp.result(i));
}
return builder.toString();
}
to
public String getResult() {
byte[] bytes = new byte[this.resp.resultLength()];
for (int i = 0; i < this.resp.resultLength(); i++) {
bytes[i] = (byte) this.resp.result(i);
}
return new String(bytes, StandardCharsets.UTF_8);
}
would you like to submit a PR to fix it?
@tzssangglass
I mean body in request, fixed by modifing ExtraInfoResponse.getResult:
from:
public String getResult() { StringBuilder builder = new StringBuilder(); for (int i = 0; i < this.resp.resultLength(); i++) { builder.append((char) this.resp.result(i)); } return builder.toString(); }to
public String getResult() { byte[] bytes = new byte[this.resp.resultLength()]; for (int i = 0; i < this.resp.resultLength(); i++) { bytes[i] = (byte) this.resp.result(i); } return new String(bytes, StandardCharsets.UTF_8); }
确实有个问题
0.4.0 Cannot be modified manually
We can make it configurable by reading configuration from the configuration file.