Merge pull request #1609 from jeff/SPR-16245
This commit is contained in:
commit
537f79f680
|
|
@ -25,6 +25,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.ContentCachingRequestWrapper;
|
||||
|
|
@ -306,21 +307,9 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
|
|||
}
|
||||
|
||||
if (isIncludePayload()) {
|
||||
ContentCachingRequestWrapper wrapper =
|
||||
WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class);
|
||||
if (wrapper != null) {
|
||||
byte[] buf = wrapper.getContentAsByteArray();
|
||||
if (buf.length > 0) {
|
||||
int length = Math.min(buf.length, getMaxPayloadLength());
|
||||
String payload;
|
||||
try {
|
||||
payload = new String(buf, 0, length, wrapper.getCharacterEncoding());
|
||||
}
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
payload = "[unknown]";
|
||||
}
|
||||
msg.append(";payload=").append(payload);
|
||||
}
|
||||
String payload = getMessagePayload(request);
|
||||
if (payload != null) {
|
||||
msg.append(";payload=").append(payload);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -328,6 +317,32 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
|
|||
return msg.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the message payload portion of the message created by
|
||||
* {@link #createMessage(HttpServletRequest, String, String)} when
|
||||
* {@link #isIncludePayload()} returns true.
|
||||
* @since 5.0.3
|
||||
*/
|
||||
@Nullable
|
||||
protected String getMessagePayload(HttpServletRequest request) {
|
||||
ContentCachingRequestWrapper wrapper =
|
||||
WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class);
|
||||
String payload = null;
|
||||
if (wrapper != null) {
|
||||
byte[] buf = wrapper.getContentAsByteArray();
|
||||
if (buf.length > 0) {
|
||||
int length = Math.min(buf.length, getMaxPayloadLength());
|
||||
try {
|
||||
payload = new String(buf, 0, length, wrapper.getCharacterEncoding());
|
||||
}
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
payload = "[unknown]";
|
||||
}
|
||||
}
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether to call the {@link #beforeRequest}/{@link #afterRequest}
|
||||
|
|
|
|||
Loading…
Reference in New Issue