This is an automated email from the ASF dual-hosted git repository.
chenjunxu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/apisix-java-plugin-runner.git
The following commit(s) were added to refs/heads/main by this push:
new 8afa49e bug: `ExtraInfoResponse` class `getResult` method bug (#244)
8afa49e is described below
commit 8afa49e541b774c8e53917aa6d1d83eea6492eef
Author: Junyeong Jang <[email protected]>
AuthorDate: Fri Jun 2 09:37:31 2023 +0900
bug: `ExtraInfoResponse` class `getResult` method bug (#244)
---
.../apisix/plugin/runner/handler/RpcCallHandler.java | 4 ++--
.../apache/apisix/plugin/runner/ExtraInfoResponse.java | 8 ++++----
.../org/apache/apisix/plugin/runner/HttpRequest.java | 13 +++++++++++--
.../org/apache/apisix/plugin/runner/PostRequest.java | 13 +++++++++++--
.../apache/apisix/plugin/runner/PostResponseTest.java | 17 +++++++++++++++++
5 files changed, 45 insertions(+), 10 deletions(-)
diff --git
a/runner-core/src/main/java/org/apache/apisix/plugin/runner/handler/RpcCallHandler.java
b/runner-core/src/main/java/org/apache/apisix/plugin/runner/handler/RpcCallHandler.java
index ed5ff04..f054ccf 100644
---
a/runner-core/src/main/java/org/apache/apisix/plugin/runner/handler/RpcCallHandler.java
+++
b/runner-core/src/main/java/org/apache/apisix/plugin/runner/handler/RpcCallHandler.java
@@ -215,7 +215,7 @@ public class RpcCallHandler extends
SimpleChannelInboundHandler<A6Request> {
}
private void handleExtraInfo(ChannelHandlerContext ctx, ExtraInfoResponse
request) {
- String result = request.getResult();
+ byte[] result = request.getResult();
String varsKey = queue.poll();
if (Objects.isNull(varsKey)) {
logger.error("queue is empty");
@@ -233,7 +233,7 @@ public class RpcCallHandler extends
SimpleChannelInboundHandler<A6Request> {
}
}
else {
- nginxVars.put(varsKey, result);
+ nginxVars.put(varsKey, new String(result));
}
if (queue.isEmpty()) {
diff --git
a/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/ExtraInfoResponse.java
b/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/ExtraInfoResponse.java
index eb10f97..7839afb 100644
---
a/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/ExtraInfoResponse.java
+++
b/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/ExtraInfoResponse.java
@@ -35,12 +35,12 @@ public class ExtraInfoResponse implements A6Request {
return new ExtraInfoResponse(req);
}
- public String getResult() {
- StringBuilder builder = new StringBuilder();
+ public byte[] getResult() {
+ byte[] byteArray = new byte[this.resp.resultLength()];
for (int i = 0; i < this.resp.resultLength(); i++) {
- builder.append((char) this.resp.result(i));
+ byteArray[i] = (byte) this.resp.result(i);
}
- return builder.toString();
+ return byteArray;
}
@Override
diff --git
a/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/HttpRequest.java
b/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/HttpRequest.java
index 896a911..2efede0 100644
---
a/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/HttpRequest.java
+++
b/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/HttpRequest.java
@@ -24,6 +24,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -50,7 +51,7 @@ public class HttpRequest implements A6Request {
private Map<String, String> vars;
- private String body;
+ private byte[] body;
public HttpRequest(Req req) {
this.req = req;
@@ -300,10 +301,18 @@ public class HttpRequest implements A6Request {
}
public String getBody() {
- return body;
+ return new String(body);
+ }
+
+ public String getBody(Charset charset) {
+ return new String(body, charset);
}
public void setBody(String body) {
+ this.body = body.getBytes();
+ }
+
+ public void setBody(byte[] body) {
this.body = body;
}
diff --git
a/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/PostRequest.java
b/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/PostRequest.java
index ba4179a..88315f5 100644
---
a/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/PostRequest.java
+++
b/runner-plugin-sdk/src/main/java/org/apache/apisix/plugin/runner/PostRequest.java
@@ -23,6 +23,7 @@ import org.apache.apisix.plugin.runner.filter.PluginFilter;
import org.springframework.util.CollectionUtils;
import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -38,7 +39,7 @@ public class PostRequest implements A6Request {
private Integer status;
- private String body;
+ private byte[] body;
private Map<String, String> vars;
@@ -94,11 +95,19 @@ public class PostRequest implements A6Request {
}
public void setBody(String body) {
+ this.body = body.getBytes();
+ }
+
+ public void setBody(byte[] body) {
this.body = body;
}
public String getBody() {
- return body;
+ return new String(body);
+ }
+
+ public String getBody(Charset charset) {
+ return new String(body, charset);
}
public String getVars(String key) {
diff --git
a/runner-plugin-sdk/src/test/java/org/apache/apisix/plugin/runner/PostResponseTest.java
b/runner-plugin-sdk/src/test/java/org/apache/apisix/plugin/runner/PostResponseTest.java
index 512aca9..1c8a4de 100644
---
a/runner-plugin-sdk/src/test/java/org/apache/apisix/plugin/runner/PostResponseTest.java
+++
b/runner-plugin-sdk/src/test/java/org/apache/apisix/plugin/runner/PostResponseTest.java
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.apache.apisix.plugin.runner;
import org.junit.jupiter.api.DisplayName;