AbstractRequestLoggingFilter unwraps request to find ContentCachingRequestWrapper
Issue: SPR-13764
This commit is contained in:
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpSession;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.ContentCachingRequestWrapper;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
/**
|
||||
* Base class for {@code Filter}s that perform logging operations before and after a request
|
||||
@@ -270,21 +271,23 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
|
||||
msg.append(";user=").append(user);
|
||||
}
|
||||
}
|
||||
if (isIncludePayload() && request instanceof ContentCachingRequestWrapper) {
|
||||
ContentCachingRequestWrapper wrapper = (ContentCachingRequestWrapper) request;
|
||||
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());
|
||||
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);
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
payload = "[unknown]";
|
||||
}
|
||||
msg.append(";payload=").append(payload);
|
||||
}
|
||||
|
||||
}
|
||||
msg.append(suffix);
|
||||
return msg.toString();
|
||||
|
||||
Reference in New Issue
Block a user