DispatcherServlet logs request URI in encoded form only
Issue: SPR-11591
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -57,7 +57,6 @@ import org.springframework.web.multipart.MultipartException;
|
|||||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||||
import org.springframework.web.multipart.MultipartResolver;
|
import org.springframework.web.multipart.MultipartResolver;
|
||||||
import org.springframework.web.util.NestedServletException;
|
import org.springframework.web.util.NestedServletException;
|
||||||
import org.springframework.web.util.UrlPathHelper;
|
|
||||||
import org.springframework.web.util.WebUtils;
|
import org.springframework.web.util.WebUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,8 +245,6 @@ public class DispatcherServlet extends FrameworkServlet {
|
|||||||
/** Additional logger to use when no mapped handler is found for a request. */
|
/** Additional logger to use when no mapped handler is found for a request. */
|
||||||
protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY);
|
protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY);
|
||||||
|
|
||||||
private static final UrlPathHelper urlPathHelper = new UrlPathHelper();
|
|
||||||
|
|
||||||
private static final Properties defaultStrategies;
|
private static final Properties defaultStrategies;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -838,17 +835,15 @@ public class DispatcherServlet extends FrameworkServlet {
|
|||||||
@Override
|
@Override
|
||||||
protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
String requestUri = urlPathHelper.getRequestUri(request);
|
|
||||||
String resumed = WebAsyncUtils.getAsyncManager(request).hasConcurrentResult() ? " resumed" : "";
|
String resumed = WebAsyncUtils.getAsyncManager(request).hasConcurrentResult() ? " resumed" : "";
|
||||||
logger.debug("DispatcherServlet with name '" + getServletName() + "'" + resumed +
|
logger.debug("DispatcherServlet with name '" + getServletName() + "'" + resumed +
|
||||||
" processing " + request.getMethod() + " request for [" + requestUri + "]");
|
" processing " + request.getMethod() + " request for [" + getRequestUri(request) + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep a snapshot of the request attributes in case of an include,
|
// Keep a snapshot of the request attributes in case of an include,
|
||||||
// to be able to restore the original attributes after the include.
|
// to be able to restore the original attributes after the include.
|
||||||
Map<String, Object> attributesSnapshot = null;
|
Map<String, Object> attributesSnapshot = null;
|
||||||
if (WebUtils.isIncludeRequest(request)) {
|
if (WebUtils.isIncludeRequest(request)) {
|
||||||
logger.debug("Taking snapshot of request attributes before include");
|
|
||||||
attributesSnapshot = new HashMap<String, Object>();
|
attributesSnapshot = new HashMap<String, Object>();
|
||||||
Enumeration<?> attrNames = request.getAttributeNames();
|
Enumeration<?> attrNames = request.getAttributeNames();
|
||||||
while (attrNames.hasMoreElements()) {
|
while (attrNames.hasMoreElements()) {
|
||||||
@@ -928,8 +923,7 @@ public class DispatcherServlet extends FrameworkServlet {
|
|||||||
if (isGet || "HEAD".equals(method)) {
|
if (isGet || "HEAD".equals(method)) {
|
||||||
long lastModified = ha.getLastModified(request, mappedHandler.getHandler());
|
long lastModified = ha.getLastModified(request, mappedHandler.getHandler());
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
String requestUri = urlPathHelper.getRequestUri(request);
|
logger.debug("Last-Modified value for [" + getRequestUri(request) + "] is: " + lastModified);
|
||||||
logger.debug("Last-Modified value for [" + requestUri + "] is: " + lastModified);
|
|
||||||
}
|
}
|
||||||
if (new ServletWebRequest(request, response).checkNotModified(lastModified) && isGet) {
|
if (new ServletWebRequest(request, response).checkNotModified(lastModified) && isGet) {
|
||||||
return;
|
return;
|
||||||
@@ -1114,15 +1108,15 @@ public class DispatcherServlet extends FrameworkServlet {
|
|||||||
*/
|
*/
|
||||||
protected void noHandlerFound(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
protected void noHandlerFound(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
if (pageNotFoundLogger.isWarnEnabled()) {
|
if (pageNotFoundLogger.isWarnEnabled()) {
|
||||||
String requestUri = urlPathHelper.getRequestUri(request);
|
pageNotFoundLogger.warn("No mapping found for HTTP request with URI [" + getRequestUri(request) +
|
||||||
pageNotFoundLogger.warn("No mapping found for HTTP request with URI [" + requestUri +
|
|
||||||
"] in DispatcherServlet with name '" + getServletName() + "'");
|
"] in DispatcherServlet with name '" + getServletName() + "'");
|
||||||
}
|
}
|
||||||
if(throwExceptionIfNoHandlerFound) {
|
if (throwExceptionIfNoHandlerFound) {
|
||||||
ServletServerHttpRequest req = new ServletServerHttpRequest(request);
|
ServletServerHttpRequest req = new ServletServerHttpRequest(request);
|
||||||
throw new NoHandlerFoundException(req.getMethod().name(),
|
throw new NoHandlerFoundException(req.getMethod().name(),
|
||||||
req.getServletRequest().getRequestURI(),req.getHeaders());
|
req.getServletRequest().getRequestURI(),req.getHeaders());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1203,9 +1197,8 @@ public class DispatcherServlet extends FrameworkServlet {
|
|||||||
// We need to resolve the view name.
|
// We need to resolve the view name.
|
||||||
view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);
|
view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
throw new ServletException(
|
throw new ServletException("Could not resolve view with name '" + mv.getViewName() +
|
||||||
"Could not resolve view with name '" + mv.getViewName() + "' in servlet with name '" +
|
"' in servlet with name '" + getServletName() + "'");
|
||||||
getServletName() + "'");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1226,8 +1219,8 @@ public class DispatcherServlet extends FrameworkServlet {
|
|||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Error rendering view [" + view + "] in DispatcherServlet with name '"
|
logger.debug("Error rendering view [" + view + "] in DispatcherServlet with name '" +
|
||||||
+ getServletName() + "'", ex);
|
getServletName() + "'", ex);
|
||||||
}
|
}
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
@@ -1295,8 +1288,6 @@ public class DispatcherServlet extends FrameworkServlet {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void restoreAttributesAfterInclude(HttpServletRequest request, Map<?,?> attributesSnapshot) {
|
private void restoreAttributesAfterInclude(HttpServletRequest request, Map<?,?> attributesSnapshot) {
|
||||||
logger.debug("Restoring snapshot of request attributes after include");
|
|
||||||
|
|
||||||
// Need to copy into separate Collection here, to avoid side effects
|
// Need to copy into separate Collection here, to avoid side effects
|
||||||
// on the Enumeration when removing attributes.
|
// on the Enumeration when removing attributes.
|
||||||
Set<String> attrsToCheck = new HashSet<String>();
|
Set<String> attrsToCheck = new HashSet<String>();
|
||||||
@@ -1316,18 +1307,20 @@ public class DispatcherServlet extends FrameworkServlet {
|
|||||||
for (String attrName : attrsToCheck) {
|
for (String attrName : attrsToCheck) {
|
||||||
Object attrValue = attributesSnapshot.get(attrName);
|
Object attrValue = attributesSnapshot.get(attrName);
|
||||||
if (attrValue == null){
|
if (attrValue == null){
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("Removing attribute [" + attrName + "] after include");
|
|
||||||
}
|
|
||||||
request.removeAttribute(attrName);
|
request.removeAttribute(attrName);
|
||||||
}
|
}
|
||||||
else if (attrValue != request.getAttribute(attrName)) {
|
else if (attrValue != request.getAttribute(attrName)) {
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("Restoring original value of attribute [" + attrName + "] after include");
|
|
||||||
}
|
|
||||||
request.setAttribute(attrName, attrValue);
|
request.setAttribute(attrName, attrValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getRequestUri(HttpServletRequest request) {
|
||||||
|
String uri = (String) request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE);
|
||||||
|
if (uri == null) {
|
||||||
|
uri = request.getRequestURI();
|
||||||
|
}
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user