Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #5851] Sandbox API debugging, the target API method is not POST, and the response format is JSON. The API returns an exception. #5852

Merged
merged 7 commits into from
Dec 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -220,15 +221,16 @@ public String request(final String url, final Map<String, ?> form, final Map<Str
* @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, HTTPMethod method) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is call this funcation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpUtils#requestJson,This method is currently invoked in only one place.
The call stack of this method is as follows and the source code location..
org.apache.shenyu.admin.controller.SandboxController#proxyGateway. Line 52 - 55
org.apache.shenyu.admin.service.impl.SandboxServiceImpl#requestProxyGateway. Line 79 - 110
org.apache.shenyu.admin.utils.HttpUtils#requestCall. Line 303 - 308
org.apache.shenyu.admin.utils.HttpUtils#requestJson. Line 226 - 231

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,pls check ci,it not passed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied Checkstyle to HttpUtils file

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();
Expand Down Expand Up @@ -305,7 +307,7 @@ public Response requestCall(final String url, final Map<String, ?> form, final M
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);
}
Expand Down
Loading