Skip to content

Commit

Permalink
[type:improve] Optimize code for shenyu-alert (#5865)
Browse files Browse the repository at this point in the history
* [type:improve] Optimize code for shenyu-alert(#5865)

---------

Co-authored-by: aias00 <liuhongyu@apache.org>
Co-authored-by: xiaoyu <xiaoyu@apache.org>
  • Loading branch information
3 people authored Dec 26, 2024
1 parent 02bdaba commit 3b5f075
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
* AlertReceiver.
*/
public class AlertReceiverDTO implements Serializable {


private static final long serialVersionUID = 1790514185328089645L;

/**
* primary key id.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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)", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import jakarta.mail.internet.MimeMessage;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/**
* email alert notice.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3b5f075

Please sign in to comment.