This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 02bdabacb5 [ISSUE #5851] Sandbox API debugging, the target API method
is not POST, and the response format is JSON. The API returns an exception.
(#5852)
02bdabacb5 is described below
commit 02bdabacb594113e7889394e49e3bbd77f6b217e
Author: SKonst <[email protected]>
AuthorDate: Thu Dec 26 14:12:41 2024 +0800
[ISSUE #5851] Sandbox API debugging, the target API method is not POST, and
the response format is JSON. The API returns an exception. (#5852)
* fix admin: The error occurs when testing the sandbox API, and the target
method is not a POST request.
* fix admin: Applied Checkstyle to HttpUtils file
---------
Co-authored-by: aias00 <[email protected]>
Co-authored-by: xiaoyu <[email protected]>
---
.../src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java
index e814fefc57..d825328975 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java
@@ -28,6 +28,7 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
+import okhttp3.internal.http.HttpMethod;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import org.apache.commons.codec.digest.DigestUtils;
@@ -220,15 +221,16 @@ public class HttpUtils {
* @param url url
* @param json json
* @param header header
+ * @param method method
* @return Response
* @throws IOException IOException
*/
public Response requestJson(final String url, final String json,
- final Map<String, String> header) throws IOException {
+ final Map<String, String> header, final HTTPMethod method) throws
IOException {
RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, json);
Request.Builder requestBuilder = new Request.Builder()
.url(url)
- .post(body);
+ .method(method.value(),
HttpMethod.requiresRequestBody(method.value()) ? body : null);
addHeader(requestBuilder, header);
Request request = requestBuilder.build();
@@ -305,7 +307,7 @@ public class HttpUtils {
if (Objects.nonNull(files) && !files.isEmpty()) {
return requestFile(url, form, header, files);
} else if (isJsonRequest(header)) {
- return requestJson(url, JsonUtils.toJson(form), header);
+ return requestJson(url, JsonUtils.toJson(form), header, method);
} else {
return requestForResponse(url, form, header, method);
}