continuations only support response wrapping
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@335 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
8ef8fab8b5
commit
c8f300bc52
|
@ -6,6 +6,7 @@ jetty-7.0.0.M3-SNAPSHOT
|
|||
+ 277403 Cleanup system property usage.
|
||||
+ 277798 Denial of Service Filter
|
||||
+ Portable continuations for jetty6 and servlet3
|
||||
+ Refactored continuations to only support response wrapping
|
||||
|
||||
jetty-7.0.0.M2 18 May 2009
|
||||
+ JETTY-937 Work around Sun JVM bugs
|
||||
|
|
|
@ -100,6 +100,8 @@ public interface Continuation
|
|||
* or if the request has been dispatched for error handling.
|
||||
*/
|
||||
void suspend();
|
||||
|
||||
void suspend(ServletResponse response);
|
||||
|
||||
/**
|
||||
* Resume a suspended request.
|
||||
|
@ -190,41 +192,20 @@ public interface Continuation
|
|||
*/
|
||||
boolean isInitial();
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Call to signal that the suspending filter/servlet has kept a
|
||||
* reference to any passed requests wrappers, and that these should
|
||||
* not be finalized until a onComplete event has been seen.
|
||||
*/
|
||||
void keepWrappers();
|
||||
|
||||
/**
|
||||
* @return True if {@link #keepWrappers()} has been called.
|
||||
*/
|
||||
boolean wrappersKept();
|
||||
boolean isResponseWrapped();
|
||||
|
||||
ServletResponse getServletResponse();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param listener
|
||||
*/
|
||||
void addContinuationListener(ContinuationListener listener);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the associated servlet request.
|
||||
* <p>
|
||||
* Not all request methods are valid to be called outside of the
|
||||
* scope of a filter/servlet. Specifically servletPath methods will
|
||||
* not return correct values. The request attribute methods are suitable
|
||||
* to be called from an asynchronous scope.
|
||||
* @return The associated servlet request
|
||||
*/
|
||||
ServletRequest getServletRequest();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return The associated servlet response.
|
||||
*/
|
||||
ServletResponse getServletResponse();
|
||||
public void removeAttribute(String name);
|
||||
public void setAttribute(String name, Object attribute);
|
||||
public Object getAttribute(String name);
|
||||
}
|
||||
|
|
|
@ -33,21 +33,27 @@ public class ContinuationFilter implements Filter
|
|||
|
||||
public void init(FilterConfig filterConfig) throws ServletException
|
||||
{
|
||||
boolean jetty="org.eclipse.jetty.servlet".equals(filterConfig.getClass().getPackage().getName());
|
||||
boolean jetty_7_or_greater="org.eclipse.jetty.servlet".equals(filterConfig.getClass().getPackage().getName());
|
||||
_context = filterConfig.getServletContext();
|
||||
|
||||
String param=filterConfig.getInitParameter("debug");
|
||||
_debug=param!=null&&Boolean.parseBoolean(param);
|
||||
|
||||
param=filterConfig.getInitParameter("partial");
|
||||
_partial=param!=null&&Boolean.parseBoolean(param) || (ContinuationSupport.__jetty6&&!jetty);
|
||||
if (param!=null)
|
||||
_partial=Boolean.parseBoolean(param);
|
||||
else
|
||||
_partial=ContinuationSupport.__jetty6 && !jetty_7_or_greater;
|
||||
|
||||
param=filterConfig.getInitParameter("faux");
|
||||
_faux=(param!=null&&Boolean.parseBoolean(param)) || !(jetty || _partial || _context.getMajorVersion()>=3);
|
||||
if (param!=null)
|
||||
_faux=Boolean.parseBoolean(param);
|
||||
else
|
||||
_faux=!(jetty_7_or_greater || _partial || _context.getMajorVersion()>=3);
|
||||
|
||||
if (_debug)
|
||||
_context.log("ContinuationFilter "+
|
||||
" jetty="+jetty+
|
||||
" jetty="+jetty_7_or_greater+
|
||||
" partial="+_partial+
|
||||
" jetty6="+ContinuationSupport.__jetty6+
|
||||
" faux="+_faux+
|
||||
|
@ -58,7 +64,7 @@ public class ContinuationFilter implements Filter
|
|||
{
|
||||
if (_faux)
|
||||
{
|
||||
final FauxContinuation fc = new FauxContinuation(request,response);
|
||||
final FauxContinuation fc = new FauxContinuation(request);
|
||||
request.setAttribute(Continuation.ATTRIBUTE,fc);
|
||||
boolean complete=false;
|
||||
|
||||
|
@ -68,20 +74,6 @@ public class ContinuationFilter implements Filter
|
|||
{
|
||||
chain.doFilter(request,response);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
if (fc.isSuspended())
|
||||
debug("ContinuationFilter caught ",e);
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
catch(ServletException e)
|
||||
{
|
||||
if (fc.isSuspended())
|
||||
debug("ContinuationFilter caught ",e);
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
complete=fc.handleSuspension();
|
||||
|
|
|
@ -15,7 +15,9 @@ package org.eclipse.jetty.continuation;
|
|||
|
||||
import java.lang.reflect.Constructor;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletRequestWrapper;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.ServletResponseWrapper;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** ContinuationSupport.
|
||||
|
@ -62,7 +64,7 @@ public class ContinuationSupport
|
|||
if (jetty6)
|
||||
{
|
||||
Class<? extends Continuation> j6c = ContinuationSupport.class.getClassLoader().loadClass("org.eclipse.jetty.continuation.Jetty6Continuation").asSubclass(Continuation.class);
|
||||
j6cc=j6c.getConstructor(ServletRequest.class, ServletResponse.class, jetty6ContinuationClass);
|
||||
j6cc=j6c.getConstructor(ServletRequest.class, jetty6ContinuationClass);
|
||||
jetty6Support=true;
|
||||
}
|
||||
}
|
||||
|
@ -78,35 +80,22 @@ public class ContinuationSupport
|
|||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param request
|
||||
* @deprecated use {@link #getContinuation(ServletRequest, ServletResponse)}
|
||||
* @return a Continuation instance
|
||||
*/
|
||||
public static Continuation getContinuation(final ServletRequest request)
|
||||
{
|
||||
return getContinuation(request,null);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
public static Continuation getContinuation(final ServletRequest request, final ServletResponse response)
|
||||
public static Continuation getContinuation(ServletRequest request)
|
||||
{
|
||||
Continuation continuation = (Continuation) request.getAttribute(Continuation.ATTRIBUTE);
|
||||
if (continuation!=null)
|
||||
{
|
||||
// TODO save wrappers?
|
||||
|
||||
return continuation;
|
||||
}
|
||||
|
||||
|
||||
while (request instanceof ServletRequestWrapper)
|
||||
request=((ServletRequestWrapper)request).getRequest();
|
||||
|
||||
if (__servlet3 )
|
||||
{
|
||||
try
|
||||
{
|
||||
continuation=__newServlet3Continuation.newInstance(request,response);
|
||||
continuation=__newServlet3Continuation.newInstance(request);
|
||||
request.setAttribute(Continuation.ATTRIBUTE,continuation);
|
||||
return continuation;
|
||||
}
|
||||
|
@ -121,7 +110,7 @@ public class ContinuationSupport
|
|||
Object c=request.getAttribute("org.mortbay.jetty.ajax.Continuation");
|
||||
try
|
||||
{
|
||||
continuation= __newJetty6Continuation.newInstance(request,response,c);
|
||||
continuation= __newJetty6Continuation.newInstance(request,c);
|
||||
request.setAttribute(Continuation.ATTRIBUTE,continuation);
|
||||
return continuation;
|
||||
}
|
||||
|
@ -133,4 +122,16 @@ public class ContinuationSupport
|
|||
|
||||
throw new IllegalStateException("!(Jetty || Servlet 3.0 || ContinuationFilter)");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param request
|
||||
* @param response
|
||||
* @deprecated use {@link #getContinuation(ServletRequest)}
|
||||
* @return
|
||||
*/
|
||||
public static Continuation getContinuation(final ServletRequest request, final ServletResponse response)
|
||||
{
|
||||
return getContinuation(request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.ArrayList;
|
|||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.ServletResponseWrapper;
|
||||
|
||||
class FauxContinuation implements Continuation
|
||||
{
|
||||
|
@ -30,21 +31,20 @@ class FauxContinuation implements Continuation
|
|||
private static final int __COMPLETE=7;
|
||||
|
||||
private final ServletRequest _request;
|
||||
private final ServletResponse _response;
|
||||
private ServletResponse _response;
|
||||
|
||||
private int _state=__HANDLING;
|
||||
private boolean _initial=true;
|
||||
private boolean _resumed=false;
|
||||
private boolean _timeout=false;
|
||||
private boolean _keepWrappers=false;
|
||||
private boolean _responseWrapped=false;
|
||||
private long _timeoutMs=30000; // TODO configure
|
||||
|
||||
private ArrayList<ContinuationListener> _listeners;
|
||||
|
||||
FauxContinuation(final ServletRequest request,final ServletResponse response)
|
||||
FauxContinuation(final ServletRequest request)
|
||||
{
|
||||
_request=request;
|
||||
_response=response;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -65,20 +65,11 @@ class FauxContinuation implements Continuation
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#keepWrappers()
|
||||
* @see org.eclipse.jetty.continuation.Continuation#isResponseWrapped()
|
||||
*/
|
||||
public void keepWrappers()
|
||||
public boolean isResponseWrapped()
|
||||
{
|
||||
_keepWrappers=true;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#wrappersKept()
|
||||
*/
|
||||
public boolean wrappersKept()
|
||||
{
|
||||
return _keepWrappers;
|
||||
return _responseWrapped;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -135,6 +126,14 @@ class FauxContinuation implements Continuation
|
|||
_timeoutMs = timeoutMs;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void suspend(ServletResponse response)
|
||||
{
|
||||
_response=response;
|
||||
_responseWrapped=response instanceof ServletResponseWrapper;
|
||||
suspend();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void suspend()
|
||||
{
|
||||
|
@ -241,17 +240,6 @@ class FauxContinuation implements Continuation
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#getServletRequest()
|
||||
*/
|
||||
public ServletRequest getServletRequest()
|
||||
{
|
||||
return _request;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
|
@ -268,7 +256,7 @@ class FauxContinuation implements Continuation
|
|||
{
|
||||
synchronized (this)
|
||||
{
|
||||
_keepWrappers=false;
|
||||
_responseWrapped=false;
|
||||
switch(_state)
|
||||
{
|
||||
case __HANDLING:
|
||||
|
@ -441,6 +429,33 @@ class FauxContinuation implements Continuation
|
|||
_listeners.add(listener);
|
||||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#getAttribute(java.lang.String)
|
||||
*/
|
||||
public Object getAttribute(String name)
|
||||
{
|
||||
return _request.getAttribute(name);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#removeAttribute(java.lang.String)
|
||||
*/
|
||||
public void removeAttribute(String name)
|
||||
{
|
||||
_request.removeAttribute(name);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#setAttribute(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public void setAttribute(String name, Object attribute)
|
||||
{
|
||||
_request.setAttribute(name,attribute);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -4,12 +4,13 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.ServletResponseWrapper;
|
||||
|
||||
|
||||
public class Jetty6Continuation implements ContinuationFilter.PartialContinuation
|
||||
{
|
||||
private final ServletRequest _request;
|
||||
private final ServletResponse _response;
|
||||
private ServletResponse _response;
|
||||
private final org.mortbay.util.ajax.Continuation _j6Continuation;
|
||||
|
||||
private Throwable _retry;
|
||||
|
@ -18,13 +19,12 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
private volatile boolean _completed=false;
|
||||
private volatile boolean _resumed=false;
|
||||
private volatile boolean _expired=false;
|
||||
private boolean _wrappers=false;
|
||||
private boolean _responseWrapped=false;
|
||||
private List<ContinuationListener> _listeners;
|
||||
|
||||
public Jetty6Continuation(ServletRequest request, ServletResponse response, org.mortbay.util.ajax.Continuation continuation)
|
||||
public Jetty6Continuation(ServletRequest request, org.mortbay.util.ajax.Continuation continuation)
|
||||
{
|
||||
_request=request;
|
||||
_response=response;
|
||||
_j6Continuation=continuation;
|
||||
}
|
||||
|
||||
|
@ -46,12 +46,34 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
_j6Continuation.resume();
|
||||
}
|
||||
}
|
||||
|
||||
public ServletRequest getServletRequest()
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#getAttribute(java.lang.String)
|
||||
*/
|
||||
public Object getAttribute(String name)
|
||||
{
|
||||
return _request;
|
||||
return _request.getAttribute(name);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#removeAttribute(java.lang.String)
|
||||
*/
|
||||
public void removeAttribute(String name)
|
||||
{
|
||||
_request.removeAttribute(name);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#setAttribute(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public void setAttribute(String name, Object attribute)
|
||||
{
|
||||
_request.setAttribute(name,attribute);
|
||||
}
|
||||
|
||||
public ServletResponse getServletResponse()
|
||||
{
|
||||
return _response;
|
||||
|
@ -77,11 +99,6 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
return _retry!=null;
|
||||
}
|
||||
|
||||
public void keepWrappers()
|
||||
{
|
||||
_wrappers=true;
|
||||
}
|
||||
|
||||
public void resume()
|
||||
{
|
||||
synchronized(this)
|
||||
|
@ -99,10 +116,16 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
_timeout=(timeoutMs>Integer.MAX_VALUE)?Integer.MAX_VALUE:(int)timeoutMs;
|
||||
}
|
||||
|
||||
public void suspend()
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#suspend(javax.servlet.ServletResponse)
|
||||
*/
|
||||
public void suspend(ServletResponse response)
|
||||
{
|
||||
try
|
||||
{
|
||||
_response=response;
|
||||
_responseWrapped=_response instanceof ServletResponseWrapper;
|
||||
_resumed=false;
|
||||
_expired=false;
|
||||
_completed=false;
|
||||
|
@ -114,9 +137,26 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
}
|
||||
}
|
||||
|
||||
public boolean wrappersKept()
|
||||
public void suspend()
|
||||
{
|
||||
return _wrappers;
|
||||
try
|
||||
{
|
||||
_response=null;
|
||||
_responseWrapped=false;
|
||||
_resumed=false;
|
||||
_expired=false;
|
||||
_completed=false;
|
||||
_j6Continuation.suspend(_timeout);
|
||||
}
|
||||
catch(Throwable retry)
|
||||
{
|
||||
_retry=retry;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isResponseWrapped()
|
||||
{
|
||||
return _responseWrapped;
|
||||
}
|
||||
|
||||
public boolean enter()
|
||||
|
@ -160,6 +200,5 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
for (ContinuationListener l: _listeners)
|
||||
l.onComplete(this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,13 @@ import javax.servlet.AsyncListener;
|
|||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.ServletResponseWrapper;
|
||||
|
||||
|
||||
public class Servlet3Continuation implements Continuation
|
||||
{
|
||||
private final ServletRequest _request;
|
||||
private final ServletResponse _response;
|
||||
private ServletResponse _response;
|
||||
private AsyncContext _context;
|
||||
private final AsyncListener _listener = new AsyncListener()
|
||||
{
|
||||
|
@ -30,12 +31,11 @@ public class Servlet3Continuation implements Continuation
|
|||
private volatile boolean _initial=true;
|
||||
private volatile boolean _resumed=false;
|
||||
private volatile boolean _expired=false;
|
||||
private volatile boolean _wrappers=false;
|
||||
private volatile boolean _responseWrapped=false;
|
||||
|
||||
public Servlet3Continuation(ServletRequest request, ServletResponse response)
|
||||
public Servlet3Continuation(ServletRequest request)
|
||||
{
|
||||
_request=request;
|
||||
_response=response;
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,11 +64,6 @@ public class Servlet3Continuation implements Continuation
|
|||
_context.complete();
|
||||
}
|
||||
|
||||
public ServletRequest getServletRequest()
|
||||
{
|
||||
return _request;
|
||||
}
|
||||
|
||||
public ServletResponse getServletResponse()
|
||||
{
|
||||
return _response;
|
||||
|
@ -97,7 +92,7 @@ public class Servlet3Continuation implements Continuation
|
|||
|
||||
public void keepWrappers()
|
||||
{
|
||||
_wrappers=true;
|
||||
_responseWrapped=true;
|
||||
}
|
||||
|
||||
public void resume()
|
||||
|
@ -114,6 +109,16 @@ public class Servlet3Continuation implements Continuation
|
|||
_request.setAsyncTimeout(timeoutMs);
|
||||
}
|
||||
|
||||
public void suspend(ServletResponse response)
|
||||
{
|
||||
_response=response;
|
||||
_responseWrapped=response instanceof ServletResponseWrapper;
|
||||
_request.addAsyncListener(_listener);
|
||||
_resumed=false;
|
||||
_expired=false;
|
||||
_context=_request.startAsync();
|
||||
}
|
||||
|
||||
public void suspend()
|
||||
{
|
||||
_request.addAsyncListener(_listener);
|
||||
|
@ -122,9 +127,37 @@ public class Servlet3Continuation implements Continuation
|
|||
_context=_request.startAsync();
|
||||
}
|
||||
|
||||
public boolean wrappersKept()
|
||||
public boolean isResponseWrapped()
|
||||
{
|
||||
return _wrappers;
|
||||
return _responseWrapped;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#getAttribute(java.lang.String)
|
||||
*/
|
||||
public Object getAttribute(String name)
|
||||
{
|
||||
return _request.getAttribute(name);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#removeAttribute(java.lang.String)
|
||||
*/
|
||||
public void removeAttribute(String name)
|
||||
{
|
||||
_request.removeAttribute(name);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#setAttribute(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public void setAttribute(String name, Object attribute)
|
||||
{
|
||||
_request.setAttribute(name,attribute);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.eclipse.jetty.server;
|
|||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.ServletResponseWrapper;
|
||||
|
||||
import org.eclipse.jetty.continuation.ContinuationListener;
|
||||
import org.eclipse.jetty.continuation.Continuation;
|
||||
|
@ -66,7 +67,7 @@ public class AsyncContinuation implements AsyncContext, Continuation
|
|||
private boolean _initial;
|
||||
private boolean _resumed;
|
||||
private boolean _expired;
|
||||
private boolean _keepWrappers;
|
||||
private volatile boolean _responseWrapped;
|
||||
private long _timeoutMs;
|
||||
private AsyncEventState _event;
|
||||
|
||||
|
@ -136,25 +137,14 @@ public class AsyncContinuation implements AsyncContext, Continuation
|
|||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#keepWrappers()
|
||||
*/
|
||||
public void keepWrappers()
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
// _history.append('W');
|
||||
_keepWrappers=true;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#wrappersKept()
|
||||
* @see org.eclipse.jetty.continuation.Continuation#isResponseWrapped()
|
||||
*/
|
||||
public boolean wrappersKept()
|
||||
public boolean isResponseWrapped()
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
return _keepWrappers;
|
||||
}
|
||||
return _responseWrapped;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -234,7 +224,7 @@ public class AsyncContinuation implements AsyncContext, Continuation
|
|||
// _history.append('H');
|
||||
// _history.append(_connection.getRequest().getUri().toString());
|
||||
// _history.append(':');
|
||||
_keepWrappers=false;
|
||||
_responseWrapped=false;
|
||||
|
||||
switch(_state)
|
||||
{
|
||||
|
@ -283,6 +273,7 @@ public class AsyncContinuation implements AsyncContext, Continuation
|
|||
_resumed=false;
|
||||
_expired=false;
|
||||
|
||||
// TODO move this to callers
|
||||
if (_event==null || request!=_event.getRequest() || response != _event.getResponse() || context != _event.getServletContext())
|
||||
_event=new AsyncEventState(context,request,response);
|
||||
else
|
||||
|
@ -577,7 +568,7 @@ public class AsyncContinuation implements AsyncContext, Continuation
|
|||
_initial = true;
|
||||
_resumed=false;
|
||||
_expired=false;
|
||||
_keepWrappers=false;
|
||||
_responseWrapped=false;
|
||||
cancelTimeout();
|
||||
_timeoutMs=60000L; // TODO configure
|
||||
_listeners=null;
|
||||
|
@ -824,19 +815,29 @@ public class AsyncContinuation implements AsyncContext, Continuation
|
|||
/**
|
||||
* @see Continuation#suspend()
|
||||
*/
|
||||
public void suspend()
|
||||
public void suspend(ServletResponse response)
|
||||
{
|
||||
// TODO simplify?
|
||||
AsyncContinuation.this.suspend(_connection.getRequest().getServletContext(),_connection.getRequest(),_connection.getResponse());
|
||||
if (response instanceof ServletResponseWrapper)
|
||||
{
|
||||
_responseWrapped=true;
|
||||
AsyncContinuation.this.suspend(_connection.getRequest().getServletContext(),_connection.getRequest(),response);
|
||||
}
|
||||
else
|
||||
{
|
||||
_responseWrapped=false;
|
||||
AsyncContinuation.this.suspend(_connection.getRequest().getServletContext(),_connection.getRequest(),_connection.getResponse());
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#getServletRequest()
|
||||
* @see Continuation#suspend()
|
||||
*/
|
||||
public ServletRequest getServletRequest()
|
||||
public void suspend()
|
||||
{
|
||||
return _connection.getRequest();
|
||||
// TODO simplify? move event creation to suspend(args)
|
||||
_responseWrapped=false;
|
||||
AsyncContinuation.this.suspend(_connection.getRequest().getServletContext(),_connection.getRequest(),_connection.getResponse());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -845,9 +846,38 @@ public class AsyncContinuation implements AsyncContext, Continuation
|
|||
*/
|
||||
public ServletResponse getServletResponse()
|
||||
{
|
||||
if (_responseWrapped && _event!=null && _event.getResponse()!=null)
|
||||
return _event.getResponse();
|
||||
return _connection.getResponse();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#getAttribute(java.lang.String)
|
||||
*/
|
||||
public Object getAttribute(String name)
|
||||
{
|
||||
return _connection.getRequest().getAttribute(name);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#removeAttribute(java.lang.String)
|
||||
*/
|
||||
public void removeAttribute(String name)
|
||||
{
|
||||
_connection.getRequest().removeAttribute(name);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.continuation.Continuation#setAttribute(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public void setAttribute(String name, Object attribute)
|
||||
{
|
||||
_connection.getRequest().setAttribute(name,attribute);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
public class AsyncEventState
|
||||
|
|
|
@ -116,7 +116,7 @@ public class Request implements HttpServletRequest
|
|||
}
|
||||
protected final AsyncContinuation _async = new AsyncContinuation();
|
||||
private boolean _asyncSupported=true;
|
||||
private Attributes _attributes;
|
||||
private volatile Attributes _attributes;
|
||||
private Authentication _authentication;
|
||||
private MultiMap<String> _baseParameters;
|
||||
private String _characterEncoding;
|
||||
|
@ -310,12 +310,10 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public Object getAttribute(String name)
|
||||
{
|
||||
if (Continuation.ATTRIBUTE.equals(name))
|
||||
Object attr=(_attributes==null)?null:_attributes.getAttribute(name);
|
||||
if (attr==null && Continuation.ATTRIBUTE.equals(name))
|
||||
return _async;
|
||||
|
||||
if (_attributes==null)
|
||||
return null;
|
||||
return _attributes.getAttribute(name);
|
||||
return attr;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -281,7 +281,7 @@ public class AsyncContextTest extends TestCase
|
|||
|
||||
public void onTimeout(Continuation continuation)
|
||||
{
|
||||
continuation.getServletRequest().setAttribute("TIMEOUT",Boolean.TRUE);
|
||||
continuation.setAttribute("TIMEOUT",Boolean.TRUE);
|
||||
continuation.resume();
|
||||
}
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@ public class AsyncStressTest extends TestCase
|
|||
|
||||
public void onTimeout(Continuation continuation)
|
||||
{
|
||||
continuation.getServletRequest().setAttribute("TIMEOUT",Boolean.TRUE);
|
||||
continuation.setAttribute("TIMEOUT",Boolean.TRUE);
|
||||
continuation.resume();
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ public class GzipFilter extends UserAgentFilter
|
|||
finally
|
||||
{
|
||||
Continuation continuation = ContinuationSupport.getContinuation(request,response);
|
||||
if (continuation.isSuspended() && continuation.wrappersKept())
|
||||
if (continuation.isSuspended() && continuation.isResponseWrapped())
|
||||
{
|
||||
continuation.addContinuationListener(new ContinuationListener()
|
||||
{
|
||||
|
|
|
@ -271,8 +271,7 @@ public class ProxyServlet implements Servlet
|
|||
if (hasContent)
|
||||
exchange.setRequestContentSource(in);
|
||||
|
||||
continuation.suspend();
|
||||
continuation.keepWrappers();
|
||||
continuation.suspend(response);
|
||||
_client.send(exchange);
|
||||
|
||||
}
|
||||
|
|
|
@ -178,7 +178,8 @@ public class QoSFilterTest extends TestCase
|
|||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.warn(url.toString(),e);
|
||||
Log.warn(url.toString());
|
||||
Log.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -573,8 +573,9 @@ public class BlockingArrayQueue<E> extends AbstractList<E> implements Queue<E>
|
|||
else
|
||||
{
|
||||
s=_elements.length+tail-head;
|
||||
System.arraycopy(_elements,head,elements,0,s-head);
|
||||
System.arraycopy(_elements,0,elements,s-head,tail);
|
||||
int cut=_elements.length-head;
|
||||
System.arraycopy(_elements,head,elements,0,cut);
|
||||
System.arraycopy(_elements,0,elements,cut,tail);
|
||||
}
|
||||
_elements=elements;
|
||||
_head=0;
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>7.0.0.M3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-continuation-jetty6</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Test :: Continuation</name>
|
||||
<description>Asynchronous API</description>
|
||||
<build>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>test-continuation</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty</artifactId>
|
||||
<version>6.1.18</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>servlet-api-2.5</artifactId>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -16,6 +16,7 @@ package org.eclipse.jetty.continuation;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.jetty.continuation.test.ContinuationBase;
|
||||
import org.mortbay.jetty.Connector;
|
||||
import org.mortbay.jetty.Server;
|
||||
import org.mortbay.jetty.nio.SelectChannelConnector;
|
||||
|
@ -59,7 +60,16 @@ public class Jetty6ContinuationTest extends ContinuationBase
|
|||
|
||||
doit("Jetty6Continuation");
|
||||
}
|
||||
|
||||
|
||||
public void testFaux() throws Exception
|
||||
{
|
||||
_filter.setInitParameter("debug","true");
|
||||
_filter.setInitParameter("faux","true");
|
||||
_server.start();
|
||||
_port=_connector.getLocalPort();
|
||||
|
||||
doit("FauxContinuation");
|
||||
}
|
||||
|
||||
protected String toString(InputStream in) throws IOException
|
||||
{
|
|
@ -15,26 +15,13 @@
|
|||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty</artifactId>
|
||||
<version>6.1.18</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>servlet-api-2.5</artifactId>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.continuation;
|
||||
package org.eclipse.jetty.continuation.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -24,6 +24,10 @@ import javax.servlet.http.HttpServlet;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.continuation.Continuation;
|
||||
import org.eclipse.jetty.continuation.ContinuationListener;
|
||||
import org.eclipse.jetty.continuation.ContinuationSupport;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
|
@ -153,7 +157,7 @@ public abstract class ContinuationBase extends TestCase
|
|||
assertEquals("HTTP/1.1 200 OK",response.substring(0,15));
|
||||
if (response.indexOf(content,15)<0)
|
||||
{
|
||||
System.err.println(content+" NOT IN '"+response+"'");
|
||||
System.err.println("'"+content+"' NOT IN:\n"+response+"\n--");
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
@ -163,7 +167,7 @@ public abstract class ContinuationBase extends TestCase
|
|||
assertEquals("HTTP/1.1 200 OK",response.substring(0,15));
|
||||
if (response.indexOf(content,15)>=0)
|
||||
{
|
||||
System.err.println(content+" IS IN '"+response+"'");
|
||||
System.err.println("'"+content+"' IS IN:\n"+response+"'\n--");
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
@ -252,8 +256,8 @@ public abstract class ContinuationBase extends TestCase
|
|||
if (suspend_for>0)
|
||||
continuation.setTimeout(suspend_for);
|
||||
continuation.addContinuationListener(__listener);
|
||||
((HttpServletResponse)continuation.getServletResponse()).addHeader("history","suspend");
|
||||
continuation.suspend();
|
||||
((HttpServletResponse)response).addHeader("history","suspend");
|
||||
continuation.suspend(response);
|
||||
|
||||
if (complete_after>0)
|
||||
{
|
||||
|
@ -331,8 +335,8 @@ public abstract class ContinuationBase extends TestCase
|
|||
if (suspend2_for>0)
|
||||
continuation.setTimeout(suspend2_for);
|
||||
// continuation.addContinuationListener(__listener);
|
||||
((HttpServletResponse)continuation.getServletResponse()).addHeader("history","suspend");
|
||||
continuation.suspend();
|
||||
((HttpServletResponse)response).addHeader("history","suspend");
|
||||
continuation.suspend(response);
|
||||
|
||||
if (complete2_after>0)
|
||||
{
|
||||
|
@ -369,7 +373,7 @@ public abstract class ContinuationBase extends TestCase
|
|||
{
|
||||
public void run()
|
||||
{
|
||||
((HttpServletResponse)continuation.getServletResponse()).addHeader("history","resume");
|
||||
((HttpServletResponse)response).addHeader("history","resume");
|
||||
continuation.resume();
|
||||
}
|
||||
};
|
||||
|
@ -380,7 +384,7 @@ public abstract class ContinuationBase extends TestCase
|
|||
}
|
||||
else if (resume2_after==0)
|
||||
{
|
||||
((HttpServletResponse)continuation.getServletResponse()).addHeader("history","resume");
|
||||
((HttpServletResponse)response).addHeader("history","resume");
|
||||
continuation.resume();
|
||||
}
|
||||
return;
|
|
@ -16,6 +16,7 @@ package org.eclipse.jetty.continuation;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.jetty.continuation.test.ContinuationBase;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
|
@ -45,35 +46,12 @@ public class ContinuationTest extends ContinuationBase
|
|||
_servletHandler.addServletWithMapping(holder,"/");
|
||||
}
|
||||
|
||||
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
_server.stop();
|
||||
}
|
||||
|
||||
public void testNotFaux() throws Exception
|
||||
{
|
||||
_filter=_servletHandler.addFilterWithMapping(ContinuationFilter.class,"/*",0);
|
||||
_filter.setInitParameter("debug","true");
|
||||
_filter.setInitParameter("faux","true");
|
||||
_server.start();
|
||||
_port=_connector.getLocalPort();
|
||||
|
||||
doit("AsyncContinuation");
|
||||
}
|
||||
|
||||
public void testNotJetty6() throws Exception
|
||||
{
|
||||
_filter=_servletHandler.addFilterWithMapping(ContinuationFilter.class,"/*",0);
|
||||
_filter.setInitParameter("debug","true");
|
||||
_filter.setInitParameter("faux","false");
|
||||
_server.start();
|
||||
_port=_connector.getLocalPort();
|
||||
|
||||
doit("AsyncContinuation");
|
||||
}
|
||||
|
||||
public void testNoFilter() throws Exception
|
||||
|
||||
public void testContinuation() throws Exception
|
||||
{
|
||||
_server.start();
|
||||
_port=_connector.getLocalPort();
|
||||
|
|
|
@ -16,14 +16,15 @@ package org.eclipse.jetty.continuation;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.mortbay.jetty.Connector;
|
||||
import org.mortbay.jetty.Server;
|
||||
import org.mortbay.jetty.nio.SelectChannelConnector;
|
||||
import org.mortbay.jetty.servlet.Context;
|
||||
import org.mortbay.jetty.servlet.FilterHolder;
|
||||
import org.mortbay.jetty.servlet.ServletHandler;
|
||||
import org.mortbay.jetty.servlet.ServletHolder;
|
||||
import org.mortbay.util.IO;
|
||||
import org.eclipse.jetty.continuation.test.ContinuationBase;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
|
||||
|
||||
public class FauxContinuationTest extends ContinuationBase
|
||||
|
@ -37,12 +38,11 @@ public class FauxContinuationTest extends ContinuationBase
|
|||
{
|
||||
_connector = new SelectChannelConnector();
|
||||
_server.setConnectors(new Connector[]{ _connector });
|
||||
Context servletContext = new Context(Context.NO_SECURITY|Context.NO_SESSIONS);
|
||||
ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.NO_SECURITY|ServletContextHandler.NO_SESSIONS);
|
||||
_server.setHandler(servletContext);
|
||||
_servletHandler=servletContext.getServletHandler();
|
||||
ServletHolder holder=new ServletHolder(_servlet);
|
||||
_servletHandler.addServletWithMapping(holder,"/");
|
||||
_filter=_servletHandler.addFilterWithMapping(ContinuationFilter.class,"/*",0);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception
|
||||
|
@ -52,6 +52,7 @@ public class FauxContinuationTest extends ContinuationBase
|
|||
|
||||
public void testFaux() throws Exception
|
||||
{
|
||||
_filter=_servletHandler.addFilterWithMapping(ContinuationFilter.class,"/*",0);
|
||||
_filter.setInitParameter("debug","true");
|
||||
_filter.setInitParameter("faux","true");
|
||||
_server.start();
|
||||
|
@ -60,7 +61,15 @@ public class FauxContinuationTest extends ContinuationBase
|
|||
doit("FauxContinuation");
|
||||
}
|
||||
|
||||
|
||||
public void testNoFauxDefaults() throws Exception
|
||||
{
|
||||
_filter=_servletHandler.addFilterWithMapping(ContinuationFilter.class,"/*",0);
|
||||
_filter.setInitParameter("debug","true");
|
||||
_server.start();
|
||||
_port=_connector.getLocalPort();
|
||||
|
||||
doit("AsyncContinuation");
|
||||
}
|
||||
|
||||
protected String toString(InputStream in) throws IOException
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue