392129 fixed merged of handling of timeouts after startAsync
This commit is contained in:
parent
ae7248b6d2
commit
b7aded6e55
|
@ -253,6 +253,15 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
|
|||
}
|
||||
else
|
||||
{
|
||||
if (_request.getHttpChannelState().isExpired())
|
||||
{
|
||||
_request.setDispatcherType(DispatcherType.ERROR);
|
||||
_request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE,new Integer(500));
|
||||
_request.setAttribute(RequestDispatcher.ERROR_MESSAGE,"Async Timeout");
|
||||
_request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI,_request.getRequestURI());
|
||||
_response.setStatusWithReason(500,"Async Timeout");
|
||||
}
|
||||
else
|
||||
_request.setDispatcherType(DispatcherType.ASYNC);
|
||||
getServer().handleAsync(this);
|
||||
}
|
||||
|
|
|
@ -413,12 +413,12 @@ public class HttpChannelState implements AsyncContext
|
|||
{
|
||||
case ASYNCSTARTED:
|
||||
case ASYNCWAIT:
|
||||
_expired=true;
|
||||
aListeners=_asyncListeners;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_expired=true;
|
||||
}
|
||||
|
||||
if (aListeners!=null)
|
||||
|
@ -436,22 +436,19 @@ public class HttpChannelState implements AsyncContext
|
|||
}
|
||||
}
|
||||
|
||||
boolean complete;
|
||||
synchronized (this)
|
||||
{
|
||||
switch(_state)
|
||||
{
|
||||
case ASYNCSTARTED:
|
||||
case ASYNCWAIT:
|
||||
complete = true;
|
||||
_state=State.REDISPATCH;
|
||||
break;
|
||||
default:
|
||||
complete = false;
|
||||
_expired=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (complete)
|
||||
complete();
|
||||
|
||||
scheduleDispatch();
|
||||
}
|
||||
|
@ -597,6 +594,14 @@ public class HttpChannelState implements AsyncContext
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isExpired()
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
return _expired;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInitial()
|
||||
{
|
||||
synchronized(this)
|
||||
|
|
|
@ -625,12 +625,20 @@ public class Response implements HttpServletResponse
|
|||
if (sc <= 0)
|
||||
throw new IllegalArgumentException();
|
||||
if (!isIncluding())
|
||||
{
|
||||
_status = sc;
|
||||
_reason = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setStatus(int sc, String sm)
|
||||
{
|
||||
setStatusWithReason(sc,sm);
|
||||
}
|
||||
|
||||
public void setStatusWithReason(int sc, String sm)
|
||||
{
|
||||
if (sc <= 0)
|
||||
throw new IllegalArgumentException();
|
||||
|
|
|
@ -437,7 +437,7 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
final Response response=connection.getResponse();
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("REQUEST "+target+" on "+connection);
|
||||
LOG.debug(request.getDispatcherType()+" "+target+" on "+connection);
|
||||
|
||||
if ("*".equals(target))
|
||||
{
|
||||
|
@ -498,7 +498,7 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("REQUEST "+target+" on "+connection);
|
||||
LOG.debug(request.getDispatcherType()+" "+target+" on "+connection);
|
||||
handle(target, baseRequest, request, response);
|
||||
LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus());
|
||||
}
|
||||
|
|
|
@ -941,7 +941,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
if (old_context != _scontext)
|
||||
{
|
||||
// check the target.
|
||||
if (DispatcherType.REQUEST.equals(dispatch) || DispatcherType.ASYNC.equals(dispatch) || (DispatcherType.ERROR.equals(dispatch) && baseRequest.getAsyncContinuation().isExpired()))
|
||||
if (DispatcherType.REQUEST.equals(dispatch) || DispatcherType.ASYNC.equals(dispatch) || (DispatcherType.ERROR.equals(dispatch) && baseRequest.getHttpChannelState().isExpired()))
|
||||
{
|
||||
if (_compactPath)
|
||||
target = URIUtil.compactPath(target);
|
||||
|
|
|
@ -421,6 +421,7 @@ public class StatisticsHandlerTest
|
|||
@Override
|
||||
public void onTimeout(AsyncEvent event) throws IOException
|
||||
{
|
||||
event.getAsyncContext().complete();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,7 +38,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
|
@ -49,18 +49,17 @@ import org.junit.Test;
|
|||
|
||||
public class AsyncServletTest
|
||||
{
|
||||
|
||||
protected AsyncServlet _servlet=new AsyncServlet();
|
||||
protected int _port;
|
||||
|
||||
protected Server _server = new Server();
|
||||
protected ServletHandler _servletHandler;
|
||||
protected SelectChannelConnector _connector;
|
||||
protected ServerConnector _connector;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
_connector = new SelectChannelConnector();
|
||||
_connector = new ServerConnector(_server);
|
||||
_server.setConnectors(new Connector[]{ _connector });
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY|ServletContextHandler.NO_SESSIONS);
|
||||
context.setContextPath("/ctx");
|
||||
|
@ -379,6 +378,9 @@ public class AsyncServletTest
|
|||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
|
||||
// System.err.println(response);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -396,6 +398,7 @@ public class AsyncServletTest
|
|||
@Override
|
||||
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
// System.err.println(request.getDispatcherType()+" "+request.getRequestURI());
|
||||
response.addHeader("history",request.getDispatcherType().toString());
|
||||
|
||||
int read_before=0;
|
||||
|
|
Loading…
Reference in New Issue