Fixed Jetty6 continuation support discovery.
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@331 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
ac3bd2b73f
commit
e09a8e17e0
|
@ -4,26 +4,25 @@
|
|||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.continuation;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** ContinuationSupport.
|
||||
*
|
||||
*
|
||||
* Factory class for accessing Continuation instances, which with either be
|
||||
* native to the container (jetty >= 6), a servlet 3.0 or a faux continuation.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ContinuationSupport
|
||||
{
|
||||
|
@ -31,40 +30,47 @@ public class ContinuationSupport
|
|||
static final boolean __servlet3;
|
||||
static final Constructor<? extends Continuation> __newServlet3Continuation;
|
||||
static final Constructor<? extends Continuation> __newJetty6Continuation;
|
||||
static
|
||||
static
|
||||
{
|
||||
boolean s3=false;
|
||||
boolean servlet3Support=false;
|
||||
Constructor<? extends Continuation>s3cc=null;
|
||||
try
|
||||
{
|
||||
s3=ServletRequest.class.getMethod("startAsync",null)!=null;
|
||||
Class<? extends Continuation> s3c = ContinuationSupport.class.getClassLoader().loadClass("org.eclipse.jetty.continuation.Servlet3Continuation").asSubclass(Continuation.class);
|
||||
s3cc=s3c.getConstructor(ServletRequest.class, ServletResponse.class);
|
||||
s3=true;
|
||||
{
|
||||
boolean servlet3=ServletRequest.class.getMethod("startAsync")!=null;
|
||||
if (servlet3)
|
||||
{
|
||||
Class<? extends Continuation> s3c = ContinuationSupport.class.getClassLoader().loadClass("org.eclipse.jetty.continuation.Servlet3Continuation").asSubclass(Continuation.class);
|
||||
s3cc=s3c.getConstructor(ServletRequest.class, ServletResponse.class);
|
||||
servlet3Support=true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{}
|
||||
finally
|
||||
{
|
||||
__servlet3=s3;
|
||||
__servlet3=servlet3Support;
|
||||
__newServlet3Continuation=s3cc;
|
||||
}
|
||||
|
||||
|
||||
boolean j6=false;
|
||||
|
||||
|
||||
boolean jetty6Support=false;
|
||||
Constructor<? extends Continuation>j6cc=null;
|
||||
try
|
||||
{
|
||||
j6=ContinuationSupport.class.getClassLoader().loadClass("org.mortbay.util.ajax.ContinuationSupport")!=null;
|
||||
Class<? extends Continuation> j6c = ContinuationSupport.class.getClassLoader().loadClass("org.eclipse.jetty.continuation.Jetty6Continuation").asSubclass(Continuation.class);
|
||||
j6cc=j6c.getConstructor(ServletRequest.class, ServletResponse.class, Continuation.class);
|
||||
j6=true;
|
||||
{
|
||||
Class<?> jetty6ContinuationClass = ContinuationSupport.class.getClassLoader().loadClass("org.mortbay.util.ajax.Continuation");
|
||||
boolean jetty6=jetty6ContinuationClass!=null;
|
||||
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);
|
||||
jetty6Support=true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{}
|
||||
finally
|
||||
{
|
||||
__jetty6=j6;
|
||||
__jetty6=jetty6Support;
|
||||
__newJetty6Continuation=j6cc;
|
||||
}
|
||||
}
|
||||
|
@ -76,10 +82,10 @@ public class ContinuationSupport
|
|||
* @return a Continuation instance
|
||||
*/
|
||||
public static Continuation getContinuation(final ServletRequest request)
|
||||
{
|
||||
{
|
||||
return getContinuation(request,null);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param request
|
||||
|
@ -87,17 +93,17 @@ public class ContinuationSupport
|
|||
* @return
|
||||
*/
|
||||
public static Continuation getContinuation(final ServletRequest request, final ServletResponse response)
|
||||
{
|
||||
{
|
||||
Continuation continuation = (Continuation) request.getAttribute(Continuation.ATTRIBUTE);
|
||||
if (continuation!=null)
|
||||
{
|
||||
// TODO save wrappers?
|
||||
|
||||
|
||||
return continuation;
|
||||
}
|
||||
|
||||
|
||||
if (__servlet3 )
|
||||
{
|
||||
{
|
||||
try
|
||||
{
|
||||
continuation=__newServlet3Continuation.newInstance(request,response);
|
||||
|
@ -109,7 +115,7 @@ public class ContinuationSupport
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (__jetty6)
|
||||
{
|
||||
Object c=request.getAttribute("org.mortbay.jetty.ajax.Continuation");
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.eclipse.jetty.continuation;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
|
@ -12,7 +11,7 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
private final ServletRequest _request;
|
||||
private final ServletResponse _response;
|
||||
private final org.mortbay.util.ajax.Continuation _j6Continuation;
|
||||
|
||||
|
||||
private Throwable _retry;
|
||||
private int _timeout;
|
||||
private boolean _initial=true;
|
||||
|
@ -21,14 +20,14 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
private volatile boolean _expired=false;
|
||||
private boolean _wrappers=false;
|
||||
private List<ContinuationListener> _listeners;
|
||||
|
||||
public Jetty6Continuation(ServletRequest request, ServletResponse response,org.mortbay.util.ajax.Continuation continuation)
|
||||
|
||||
public Jetty6Continuation(ServletRequest request, ServletResponse response, org.mortbay.util.ajax.Continuation continuation)
|
||||
{
|
||||
_request=request;
|
||||
_response=response;
|
||||
_j6Continuation=continuation;
|
||||
}
|
||||
|
||||
|
||||
public void addContinuationListener(final ContinuationListener listener)
|
||||
{
|
||||
if (_listeners==null)
|
||||
|
@ -54,7 +53,7 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
}
|
||||
|
||||
public ServletResponse getServletResponse()
|
||||
{
|
||||
{
|
||||
return _response;
|
||||
}
|
||||
|
||||
|
@ -108,7 +107,7 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
_expired=false;
|
||||
_completed=false;
|
||||
_j6Continuation.suspend(_timeout);
|
||||
}
|
||||
}
|
||||
catch(Throwable retry)
|
||||
{
|
||||
_retry=retry;
|
||||
|
@ -123,7 +122,7 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
public boolean enter()
|
||||
{
|
||||
_expired=!_j6Continuation.isResumed();
|
||||
|
||||
|
||||
if (_initial)
|
||||
return true;
|
||||
|
||||
|
@ -136,17 +135,17 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
for (ContinuationListener l: _listeners)
|
||||
l.onTimeout(this);
|
||||
}
|
||||
|
||||
|
||||
return !_completed;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void exit()
|
||||
{
|
||||
_initial=false;
|
||||
|
||||
|
||||
Throwable th=_retry;
|
||||
_retry=null;
|
||||
if (th instanceof ThreadDeath)
|
||||
|
@ -161,6 +160,6 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio
|
|||
for (ContinuationListener l: _listeners)
|
||||
l.onComplete(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue