-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat : upgrade to springboot 3.4 #1480
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...ain/java/com/example/restclient/bootrestclient/config/ClientLoggerRequestInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.example.restclient.bootrestclient.config; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpRequest; | ||
import org.springframework.http.HttpStatusCode; | ||
import org.springframework.http.client.ClientHttpRequestExecution; | ||
import org.springframework.http.client.ClientHttpRequestInterceptor; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StreamUtils; | ||
|
||
@Component | ||
public class ClientLoggerRequestInterceptor implements ClientHttpRequestInterceptor { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(ClientLoggerRequestInterceptor.class); | ||
|
||
@Override | ||
public ClientHttpResponse intercept( | ||
HttpRequest request, byte[] body, ClientHttpRequestExecution execution) | ||
throws IOException { | ||
logRequest(request, body); | ||
ClientHttpResponse response = execution.execute(request, body); | ||
return logResponse(response); | ||
} | ||
|
||
private BufferingClientHttpResponseWrapper logResponse(ClientHttpResponse response) | ||
throws IOException { | ||
log.info( | ||
"============================response begin=========================================="); | ||
log.info("Status code : {}", response.getStatusCode()); | ||
log.info("Status text : {}", response.getStatusText()); | ||
logHeaders(response.getHeaders()); | ||
|
||
String responseBody = | ||
StreamUtils.copyToString(response.getBody(), Charset.defaultCharset()); | ||
log.info("Response body: {}", responseBody); | ||
log.info( | ||
"=======================response end================================================="); | ||
return new BufferingClientHttpResponseWrapper(response, responseBody); | ||
} | ||
|
||
private void logRequest(HttpRequest request, byte[] body) { | ||
|
||
log.info( | ||
"===========================request begin================================================"); | ||
log.info("URI : {}", request.getURI()); | ||
log.info("Method : {}", request.getMethod()); | ||
logHeaders(request.getHeaders()); | ||
if (body.length > 0) { | ||
log.info("Request body: {}", new String(body, StandardCharsets.UTF_8)); | ||
} | ||
log.info( | ||
"==========================request end================================================"); | ||
} | ||
|
||
private void logHeaders(HttpHeaders headers) { | ||
log.info("Headers : "); | ||
headers.forEach((name, values) -> values.forEach(value -> log.info("{}={}", name, value))); | ||
} | ||
|
||
private static class BufferingClientHttpResponseWrapper implements ClientHttpResponse { | ||
private final ClientHttpResponse response; | ||
private final String body; | ||
|
||
public BufferingClientHttpResponseWrapper(ClientHttpResponse response, String body) { | ||
this.response = response; | ||
this.body = body; | ||
} | ||
|
||
@Override | ||
public InputStream getBody() { | ||
return new ByteArrayInputStream(body.getBytes()); | ||
} | ||
|
||
@Override | ||
public HttpHeaders getHeaders() { | ||
return response.getHeaders(); | ||
} | ||
|
||
@Override | ||
public HttpStatusCode getStatusCode() throws IOException { | ||
return response.getStatusCode(); | ||
} | ||
|
||
@Override | ||
public int getRawStatusCode() throws IOException { | ||
return response.getRawStatusCode(); | ||
} | ||
|
||
@Override | ||
public String getStatusText() throws IOException { | ||
return response.getStatusText(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
response.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...boot-restclient/src/main/resources/META-INF/additional-spring-configuration-metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"properties": [ | ||
{ | ||
"name": "application.external-call-url", | ||
"type": "java.lang.String", | ||
"description": "URL to which call should be made." | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid logging sensitive information in request bodies
Logging the request body may expose sensitive data such as credentials or personal information. It's a security risk to log request bodies without sanitization.
Apply this diff to remove logging of the request body: