Issue #4861 - AsyncAttributes should wrap ServletAttributes inner AttributesMap

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-05-14 08:26:44 +10:00
parent 4aece5e9cf
commit 7111f5f161
3 changed files with 46 additions and 36 deletions

View File

@ -118,17 +118,17 @@ class AsyncAttributes extends Attributes.Wrapper
super.clearAttributes();
}
public void applyToAttributes(Attributes attributes)
public static void applyAsyncAttributes(Attributes attributes, String requestURI, String contextPath, String servletPath, String pathInfo, String queryString)
{
if (_requestURI != null)
attributes.setAttribute(AsyncContext.ASYNC_REQUEST_URI, _requestURI);
if (_contextPath != null)
attributes.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH, _contextPath);
if (_servletPath != null)
attributes.setAttribute(AsyncContext.ASYNC_SERVLET_PATH, _servletPath);
if (_pathInfo != null)
attributes.setAttribute(AsyncContext.ASYNC_PATH_INFO, _pathInfo);
if (_queryString != null)
attributes.setAttribute(AsyncContext.ASYNC_QUERY_STRING, _queryString);
if (requestURI != null)
attributes.setAttribute(AsyncContext.ASYNC_REQUEST_URI, requestURI);
if (contextPath != null)
attributes.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH, contextPath);
if (servletPath != null)
attributes.setAttribute(AsyncContext.ASYNC_SERVLET_PATH, servletPath);
if (pathInfo != null)
attributes.setAttribute(AsyncContext.ASYNC_PATH_INFO, pathInfo);
if (queryString != null)
attributes.setAttribute(AsyncContext.ASYNC_QUERY_STRING, queryString);
}
}

View File

@ -1982,6 +1982,30 @@ public class Request implements HttpServletRequest
if (getAttribute(AsyncContext.ASYNC_REQUEST_URI) != null)
return;
String requestURI;
String contextPath;
String servletPath;
String pathInfo;
String queryString;
// Have we been forwarded before?
requestURI = (String)getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
if (requestURI != null)
{
contextPath = (String)getAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH);
servletPath = (String)getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH);
pathInfo = (String)getAttribute(RequestDispatcher.FORWARD_PATH_INFO);
queryString = (String)getAttribute(RequestDispatcher.FORWARD_QUERY_STRING);
}
else
{
requestURI = getRequestURI();
contextPath = getContextPath();
servletPath = getServletPath();
pathInfo = getPathInfo();
queryString = getQueryString();
}
// Unwrap the _attributes to get the base attributes instance.
Attributes baseAttributes;
if (_attributes == null)
@ -1989,31 +2013,17 @@ public class Request implements HttpServletRequest
else
baseAttributes = Attributes.unwrap(_attributes);
AsyncAttributes asyncAttributes;
// Have we been forwarded before?
String uri = (String)getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
if (uri != null)
{
String contextPath = (String)getAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH);
String servletPath = (String)getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH);
String pathInfo = (String)getAttribute(RequestDispatcher.FORWARD_PATH_INFO);
String queryString = (String)getAttribute(RequestDispatcher.FORWARD_QUERY_STRING);
asyncAttributes = new AsyncAttributes(baseAttributes, uri, contextPath, servletPath, pathInfo, queryString);
}
else
{
String requestURI = getRequestURI();
String contextPath = getContextPath();
String servletPath = getServletPath();
String pathInfo = getPathInfo();
String queryString = getQueryString();
asyncAttributes = new AsyncAttributes(baseAttributes, requestURI, contextPath, servletPath, pathInfo, queryString);
}
if (baseAttributes instanceof ServletAttributes)
((ServletAttributes)_attributes).setAsyncAttributes(asyncAttributes);
{
// Set the AsyncAttributes on the ServletAttributes.
ServletAttributes servletAttributes = (ServletAttributes)baseAttributes;
servletAttributes.setAsyncAttributes(requestURI, contextPath, servletPath, pathInfo, queryString);
}
else
asyncAttributes.applyToAttributes(_attributes);
{
// If ServletAttributes has been replaced just set them on the top level Attributes.
AsyncAttributes.applyAsyncAttributes(_attributes, requestURI, contextPath, servletPath, pathInfo, queryString);
}
}
/**

View File

@ -28,9 +28,9 @@ public class ServletAttributes implements Attributes
private final Attributes _attributes = new AttributesMap();
private AsyncAttributes _asyncAttributes;
public void setAsyncAttributes(AsyncAttributes attributes)
public void setAsyncAttributes(String requestURI, String contextPath, String servletPath, String pathInfo, String queryString)
{
_asyncAttributes = attributes;
_asyncAttributes = new AsyncAttributes(_attributes, requestURI, contextPath, servletPath, pathInfo, queryString);
}
private Attributes getAttributes()