Skip to content

Commit

Permalink
Issue #4741 Async HttpServletMapping
Browse files Browse the repository at this point in the history
added javadoc about AsyncAttributes

Signed-off-by: Greg Wilkins <gregw@webtide.com>
  • Loading branch information
gregw committed May 18, 2020
1 parent 1aeacc8 commit cf0a795
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -1849,11 +1849,19 @@ public void setAsyncAttributes()
else
baseAttributes = Attributes.unwrap(_attributes);

// We cannot use a apply AsyncAttribute via #setAttributes as that
// will wrap over any dispatch specific attribute wrappers (eg.
// Dispatcher#ForwardAttributes). Async attributes must persist
// after the current dispatch, so they must be set under any other
// wrappers.

String fwdRequestURI = (String)getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
if (fwdRequestURI == null)
{
if (baseAttributes instanceof ServletAttributes)
{
// The baseAttributes map is our ServletAttributes, so we can set the async
// attributes there, under any other wrappers.
((ServletAttributes)baseAttributes).setAsyncAttributes(getRequestURI(),
getContextPath(),
getPathInfo(), // TODO change to pathInContext when cheaply available
Expand All @@ -1862,6 +1870,8 @@ public void setAsyncAttributes()
}
else
{
// We cannot find our ServletAttributes instance, so just set directly and hope
// whatever non jetty wrappers that have been applied will do the right thing.
_attributes.setAttribute(AsyncContext.ASYNC_REQUEST_URI, getRequestURI());
_attributes.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH, getContextPath());
_attributes.setAttribute(AsyncContext.ASYNC_SERVLET_PATH, getServletPath());
Expand All @@ -1874,6 +1884,8 @@ public void setAsyncAttributes()
{
if (baseAttributes instanceof ServletAttributes)
{
// The baseAttributes map is our ServletAttributes, so we can set the async
// attributes there, under any other wrappers.
((ServletAttributes)baseAttributes).setAsyncAttributes(fwdRequestURI,
(String)getAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH),
(String)getAttribute(RequestDispatcher.FORWARD_PATH_INFO),
Expand All @@ -1882,6 +1894,8 @@ public void setAsyncAttributes()
}
else
{
// We cannot find our ServletAttributes instance, so just set directly and hope
// whatever non jetty wrappers that have been applied will do the right thing.
_attributes.setAttribute(AsyncContext.ASYNC_REQUEST_URI, fwdRequestURI);
_attributes.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH, getAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH));
_attributes.setAttribute(AsyncContext.ASYNC_SERVLET_PATH, getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@

import java.util.Set;

import javax.servlet.http.HttpServletMapping;

import org.eclipse.jetty.util.Attributes;
import org.eclipse.jetty.util.AttributesMap;

/**
* An implementation of Attributes that supports the standard async attributes.
*
* This implementation delegates to an internal {@link AttributesMap} instance, which
* can optionally be wrapped with a {@link AsyncAttributes} instance. This allows async
* attributes to be applied underneath any other attribute wrappers.
*/
public class ServletAttributes implements Attributes
{
private final Attributes _attributes = new AttributesMap();
Expand Down

0 comments on commit cf0a795

Please sign in to comment.