From 02bdabacb594113e7889394e49e3bbd77f6b217e Mon Sep 17 00:00:00 2001 From: SKonst <346403746@qq.com> Date: Thu, 26 Dec 2024 14:12:41 +0800 Subject: [PATCH 1/3] [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 Co-authored-by: xiaoyu --- .../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 e814fefc57f1..d82532897539 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.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 String request(final String url, final Map form, final Map header) throws IOException { + final Map 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 Response requestCall(final String url, final Map 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); } From 3b5f075449035de41a54315ec586f4d9ae54d6f2 Mon Sep 17 00:00:00 2001 From: po-168 Date: Thu, 26 Dec 2024 14:43:51 +0800 Subject: [PATCH 2/3] [type:improve] Optimize code for shenyu-alert (#5865) * [type:improve] Optimize code for shenyu-alert(#5865) --------- Co-authored-by: aias00 Co-authored-by: xiaoyu --- .../shenyu/alert/config/HeaderRequestInterceptor.java | 8 +++++--- .../shenyu/alert/exception/AlertNoticeException.java | 3 +++ .../org/apache/shenyu/alert/model/AlertReceiverDTO.java | 4 +++- .../shenyu/alert/strategy/AbstractAlertNotifyHandler.java | 3 ++- .../shenyu/alert/strategy/EmailAlertNotifyStrategy.java | 3 ++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/shenyu-alert/src/main/java/org/apache/shenyu/alert/config/HeaderRequestInterceptor.java b/shenyu-alert/src/main/java/org/apache/shenyu/alert/config/HeaderRequestInterceptor.java index e291495bc695..2a025039f20f 100644 --- a/shenyu-alert/src/main/java/org/apache/shenyu/alert/config/HeaderRequestInterceptor.java +++ b/shenyu-alert/src/main/java/org/apache/shenyu/alert/config/HeaderRequestInterceptor.java @@ -25,6 +25,7 @@ import org.springframework.http.client.ClientHttpResponse; import java.io.IOException; +import java.util.Objects; /** * Rest Template interceptor adds request header information. @@ -35,11 +36,12 @@ public class HeaderRequestInterceptor implements ClientHttpRequestInterceptor { public ClientHttpResponse intercept(final HttpRequest request, final byte[] body, final ClientHttpRequestExecution execution) throws IOException { // Send json by default - if (request.getHeaders().getContentType() == null) { - request.getHeaders().setContentType(MediaType.APPLICATION_JSON); + HttpHeaders headers = request.getHeaders(); + if (Objects.isNull(headers.getContentType())) { + headers.setContentType(MediaType.APPLICATION_JSON); } // Use short links - request.getHeaders().add(HttpHeaders.CONNECTION, "close"); + headers.add(HttpHeaders.CONNECTION, "close"); return execution.execute(request, body); } } diff --git a/shenyu-alert/src/main/java/org/apache/shenyu/alert/exception/AlertNoticeException.java b/shenyu-alert/src/main/java/org/apache/shenyu/alert/exception/AlertNoticeException.java index a0ff3f56f611..6c73106b45f2 100644 --- a/shenyu-alert/src/main/java/org/apache/shenyu/alert/exception/AlertNoticeException.java +++ b/shenyu-alert/src/main/java/org/apache/shenyu/alert/exception/AlertNoticeException.java @@ -21,6 +21,9 @@ * alert notice send failed. */ public class AlertNoticeException extends RuntimeException { + + private static final long serialVersionUID = 1904557336581968426L; + public AlertNoticeException(final String message) { super(message); } diff --git a/shenyu-alert/src/main/java/org/apache/shenyu/alert/model/AlertReceiverDTO.java b/shenyu-alert/src/main/java/org/apache/shenyu/alert/model/AlertReceiverDTO.java index 4400ef6154ba..1a483832bc5a 100644 --- a/shenyu-alert/src/main/java/org/apache/shenyu/alert/model/AlertReceiverDTO.java +++ b/shenyu-alert/src/main/java/org/apache/shenyu/alert/model/AlertReceiverDTO.java @@ -26,7 +26,9 @@ * AlertReceiver. */ public class AlertReceiverDTO implements Serializable { - + + private static final long serialVersionUID = 1790514185328089645L; + /** * primary key id. */ diff --git a/shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/AbstractAlertNotifyHandler.java b/shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/AbstractAlertNotifyHandler.java index e22079bc3365..a2a30163409a 100644 --- a/shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/AbstractAlertNotifyHandler.java +++ b/shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/AbstractAlertNotifyHandler.java @@ -27,6 +27,7 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Objects; import java.util.TimeZone; /** @@ -67,7 +68,7 @@ protected String renderContent(final AlarmContent alert) { protected abstract String templateName(); private static String removeBlankLine(final String value) { - if (value == null) { + if (Objects.isNull(value)) { return null; } return value.replaceAll("(?m)^\\s*$(\\n|\\r\\n)", ""); diff --git a/shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/EmailAlertNotifyStrategy.java b/shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/EmailAlertNotifyStrategy.java index e1c810963b4e..658e847f510d 100644 --- a/shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/EmailAlertNotifyStrategy.java +++ b/shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/EmailAlertNotifyStrategy.java @@ -31,6 +31,7 @@ import jakarta.mail.internet.MimeMessage; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Objects; /** * email alert notice. @@ -80,7 +81,7 @@ private String buildAlertHtmlTemplate(final AlarmContent alert) { context.setVariable("content", alert.getContent()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date alertTime = alert.getDateCreated(); - if (alertTime == null) { + if (Objects.isNull(alert)) { alertTime = new Date(); } String alarmTime = simpleDateFormat.format(alertTime); From f5733b3f92779e8e1505ef83e1a875f1b4cdb39c Mon Sep 17 00:00:00 2001 From: aias00 Date: Thu, 26 Dec 2024 17:17:21 +0800 Subject: [PATCH 3/3] [bugfix] fix mysql vulnerability (#5861) * [type:fix] fix vulnerability * [type:fix] fix vulnerability --------- Co-authored-by: xiaoyu --- pom.xml | 6 +++--- shenyu-admin/pom.xml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 5b29e20f8568..c3118eadb37f 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ 1.9.2 3.0.3 - 8.0.29 + 8.3.0 3.12.0 32.0.0-jre 4.4 @@ -315,8 +315,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j ${mysql.version} provided diff --git a/shenyu-admin/pom.xml b/shenyu-admin/pom.xml index 293b75287a6c..967bd6dde601 100644 --- a/shenyu-admin/pom.xml +++ b/shenyu-admin/pom.xml @@ -173,8 +173,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j