275396 Added ScopedHandler to set servlet scope before security handler
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@209 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
08938580c3
commit
5255060588
|
@ -9,6 +9,7 @@ jetty-7.0.0.M2-SNAPSHOT
|
|||
+ JETTY-1004 CERT VU#402580 Canonical path handling includes ? in path segment
|
||||
+ JETTY-1014 Enable start-stop-daemon by default on jetty.sh (START_STOP_DAEMON=1)
|
||||
+ JETTY-1015 Reduce BayeuxClient and HttpClient lock contention
|
||||
+ 275396 Added ScopedHandler to set servlet scope before security handler
|
||||
|
||||
jetty-6.1.17 30 April 2009
|
||||
+ JETTY-936 Make optional dispatching to welcome files as servlets
|
||||
|
|
|
@ -299,10 +299,9 @@ public class Ajp13ConnectionTest extends TestCase
|
|||
|
||||
public static class Handler extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Request base_request=(request instanceof Request) ? (Request) request : HttpConnection.getCurrentConnection().getRequest();
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
response.setContentType("text/plain");
|
||||
response.getWriter().println("success");
|
||||
|
|
|
@ -70,7 +70,7 @@ public class ExpireTest extends TestCase
|
|||
server.setConnectors( new Connector[] { connector } );
|
||||
server.setHandler( new AbstractHandler()
|
||||
{
|
||||
public void handle( String target, HttpServletRequest servletRequest, HttpServletResponse response ) throws IOException,
|
||||
public void handle( String target, Request baseRequest, HttpServletRequest servletRequest, HttpServletResponse response ) throws IOException,
|
||||
ServletException
|
||||
{
|
||||
Request request = (Request) servletRequest;
|
||||
|
|
|
@ -336,13 +336,12 @@ public class HttpExchangeTest extends TestCase
|
|||
newServer();
|
||||
_server.setHandler(new AbstractHandler()
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
int i=0;
|
||||
try
|
||||
{
|
||||
Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
response.setStatus(200);
|
||||
_count.incrementAndGet();
|
||||
|
||||
|
|
|
@ -288,11 +288,10 @@ public class SecurityListenerTest extends TestCase
|
|||
|
||||
Handler testHandler = new AbstractHandler()
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
// System.out.println("passed authentication!");
|
||||
Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
response.setStatus(200);
|
||||
if (request.getServerName().equals("jetty.eclipse.org"))
|
||||
{
|
||||
|
|
|
@ -168,12 +168,11 @@ public class SslSecurityListenerTest extends TestCase
|
|||
Handler testHandler = new AbstractHandler()
|
||||
{
|
||||
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
// System.err.println("passed authentication!\n"+((Request)request).getConnection().getRequestFields());
|
||||
|
||||
Request base_request = (request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
response.setStatus(200);
|
||||
response.setContentType("text/plain");
|
||||
if (request.getServerName().equals("jetty.eclipse.org"))
|
||||
|
|
|
@ -67,7 +67,7 @@ public class ManyConnectors
|
|||
|
||||
public static class HelloHandler extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
response.setContentType("text/html");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
|
|
@ -84,7 +84,7 @@ public class ManyContexts
|
|||
_welcome=welcome;
|
||||
}
|
||||
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
((Request)request).setHandled(true);
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
|
|
@ -72,10 +72,10 @@ public class ManyHandlers
|
|||
Handler param=new ParamHandler();
|
||||
HandlerWrapper wrapper = new HandlerWrapper()
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
request.setAttribute("welcome","Hello");
|
||||
super.handle(target,request,response);
|
||||
super.handle(target,baseRequest,request, response);
|
||||
}
|
||||
};
|
||||
Handler hello=new HelloHandler();
|
||||
|
@ -103,7 +103,7 @@ public class ManyHandlers
|
|||
|
||||
public static class ParamHandler extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Map params = request.getParameterMap();
|
||||
if (params.size()>0)
|
||||
|
@ -117,7 +117,7 @@ public class ManyHandlers
|
|||
|
||||
public static class HelloHandler extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
response.setContentType("text/html");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
|
|
@ -55,7 +55,7 @@ public class OneContext
|
|||
|
||||
public static class HelloHandler extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
response.setContentType("text/html");
|
||||
|
|
|
@ -41,7 +41,7 @@ public class OneHandler
|
|||
|
||||
public static class HelloHandler extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
response.setContentType("text/html");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
|
|
@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.http.PathMap;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -322,7 +323,7 @@ public class RewriteHandler extends HandlerWrapper
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jetty.server.handler.HandlerWrapper#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (isStarted())
|
||||
{
|
||||
|
@ -331,7 +332,7 @@ public class RewriteHandler extends HandlerWrapper
|
|||
|
||||
if (!_rules.isHandled())
|
||||
{
|
||||
super.handle(target, request, response);
|
||||
super.handle(target, baseRequest, request, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
|
||||
|
||||
|
@ -35,7 +36,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_server.setHandler(_handler);
|
||||
_handler.setHandler(new AbstractHandler(){
|
||||
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
response.setStatus(201);
|
||||
request.setAttribute("target",target);
|
||||
|
@ -70,7 +71,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_handler.setRewritePathInfo(false);
|
||||
_request.setRequestURI("/foo/bar");
|
||||
_request.setPathInfo("/foo/bar");
|
||||
_handler.handle("/foo/bar",_request,_response);
|
||||
_handler.handle("/foo/bar",_request,_request, _response);
|
||||
assertEquals(201,_response.getStatus());
|
||||
assertEquals("/foo/bar",_request.getAttribute("target"));
|
||||
assertEquals("/foo/bar",_request.getAttribute("URI"));
|
||||
|
@ -83,7 +84,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_handler.setOriginalPathAttribute(null);
|
||||
_request.setRequestURI("/aaa/bar");
|
||||
_request.setPathInfo("/aaa/bar");
|
||||
_handler.handle("/aaa/bar",_request,_response);
|
||||
_handler.handle("/aaa/bar",_request,_request, _response);
|
||||
assertEquals(201,_response.getStatus());
|
||||
assertEquals("/ddd/bar",_request.getAttribute("target"));
|
||||
assertEquals("/aaa/bar",_request.getAttribute("URI"));
|
||||
|
@ -98,7 +99,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_handler.setRewritePathInfo(true);
|
||||
_request.setRequestURI("/aaa/bar");
|
||||
_request.setPathInfo("/aaa/bar");
|
||||
_handler.handle("/aaa/bar",_request,_response);
|
||||
_handler.handle("/aaa/bar",_request,_request, _response);
|
||||
assertEquals(201,_response.getStatus());
|
||||
assertEquals("/ddd/bar",_request.getAttribute("target"));
|
||||
assertEquals("/ddd/bar",_request.getAttribute("URI"));
|
||||
|
@ -111,7 +112,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_rule2.setTerminating(true);
|
||||
_request.setRequestURI("/aaa/bar");
|
||||
_request.setPathInfo("/aaa/bar");
|
||||
_handler.handle("/aaa/bar",_request,_response);
|
||||
_handler.handle("/aaa/bar",_request,_request, _response);
|
||||
assertEquals(201,_response.getStatus());
|
||||
assertEquals("/ccc/bar",_request.getAttribute("target"));
|
||||
assertEquals("/ccc/bar",_request.getAttribute("URI"));
|
||||
|
@ -127,7 +128,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_request.setAttribute("info",null);
|
||||
_request.setRequestURI("/aaa/bar");
|
||||
_request.setPathInfo("/aaa/bar");
|
||||
_handler.handle("/aaa/bar",_request,_response);
|
||||
_handler.handle("/aaa/bar",_request,_request, _response);
|
||||
assertEquals(200,_response.getStatus());
|
||||
assertEquals(null,_request.getAttribute("target"));
|
||||
assertEquals(null,_request.getAttribute("URI"));
|
||||
|
|
|
@ -178,7 +178,7 @@ public class VirtualHostRuleContainerTest extends AbstractRuleTestCase
|
|||
|
||||
private void handleRequest() throws Exception
|
||||
{
|
||||
_server.handle("/cheese/bar", _request, _response);
|
||||
_server.handle("/cheese/bar", _request, _request, _response);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -306,7 +306,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
|
||||
}
|
||||
|
||||
protected boolean isAuthMandatory(Request base_request, Response base_response, Object constraintInfo)
|
||||
protected boolean isAuthMandatory(Request baseRequest, Response base_response, Object constraintInfo)
|
||||
{
|
||||
if (constraintInfo == null)
|
||||
{
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.security.Principal;
|
|||
|
||||
import javax.security.auth.Subject;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.UserIdentity;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -32,7 +33,7 @@ public interface IdentityService
|
|||
/**
|
||||
* Associate a user identity with the current thread.
|
||||
* This is called with as a thread enters the
|
||||
* {@link SecurityHandler#handle(String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}
|
||||
* {@link SecurityHandler#handle(String, Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}
|
||||
* method and then again with a null argument as that call exits.
|
||||
* @param user The current user or null for no user to associated.
|
||||
*/
|
||||
|
|
|
@ -381,81 +381,80 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti
|
|||
* javax.servlet.http.HttpServletRequest,
|
||||
* javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void handle(String pathInContext, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String pathInContext, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
final Request base_request = (request instanceof Request) ? (Request) request : HttpConnection.getCurrentConnection().getRequest();
|
||||
final Response base_response = (response instanceof Response) ? (Response) response : HttpConnection.getCurrentConnection().getResponse();
|
||||
final Response base_response = baseRequest.getResponse();
|
||||
final Handler handler=getHandler();
|
||||
|
||||
if (handler==null)
|
||||
return;
|
||||
|
||||
if (_authenticator!=null && checkSecurity(base_request))
|
||||
if (_authenticator!=null && checkSecurity(baseRequest))
|
||||
{
|
||||
Object constraintInfo = prepareConstraintInfo(pathInContext, base_request);
|
||||
Object constraintInfo = prepareConstraintInfo(pathInContext, baseRequest);
|
||||
|
||||
// Check data constraints
|
||||
if (!checkUserDataPermissions(pathInContext, base_request, base_response, constraintInfo))
|
||||
if (!checkUserDataPermissions(pathInContext, baseRequest, base_response, constraintInfo))
|
||||
{
|
||||
if (!base_request.isHandled())
|
||||
if (!baseRequest.isHandled())
|
||||
{
|
||||
response.sendError(Response.SC_FORBIDDEN);
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// is Auth mandatory?
|
||||
boolean isAuthMandatory = isAuthMandatory(base_request, base_response, constraintInfo);
|
||||
boolean isAuthMandatory = isAuthMandatory(baseRequest, base_response, constraintInfo);
|
||||
|
||||
// check authentication
|
||||
try
|
||||
{
|
||||
final Authenticator authenticator = _authenticator;
|
||||
Authentication authentication = base_request.getAuthentication();
|
||||
Authentication authentication = baseRequest.getAuthentication();
|
||||
if (authentication==null || authentication==Authentication.NOT_CHECKED)
|
||||
authentication=authenticator.validateRequest(request, response, isAuthMandatory);
|
||||
|
||||
|
||||
if (authentication instanceof Authentication.ResponseSent)
|
||||
{
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
else if (authentication instanceof Authentication.User)
|
||||
{
|
||||
Authentication.User userAuth = (Authentication.User)authentication;
|
||||
base_request.setAuthentication(authentication);
|
||||
baseRequest.setAuthentication(authentication);
|
||||
_identityService.associate(userAuth.getUserIdentity());
|
||||
|
||||
if (isAuthMandatory)
|
||||
{
|
||||
boolean authorized=checkWebResourcePermissions(pathInContext, base_request, base_response, constraintInfo, userAuth.getUserIdentity());
|
||||
boolean authorized=checkWebResourcePermissions(pathInContext, baseRequest, base_response, constraintInfo, userAuth.getUserIdentity());
|
||||
if (!authorized)
|
||||
{
|
||||
response.sendError(Response.SC_FORBIDDEN, "!role");
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
handler.handle(pathInContext, request, response);
|
||||
handler.handle(pathInContext, baseRequest, request, response);
|
||||
authenticator.secureResponse(request, response, isAuthMandatory, userAuth);
|
||||
}
|
||||
else if (authentication instanceof Authentication.Deferred)
|
||||
{
|
||||
DeferredAuthentication lazy= (DeferredAuthentication)authentication;
|
||||
lazy.setIdentityService(_identityService);
|
||||
base_request.setAuthentication(authentication);
|
||||
baseRequest.setAuthentication(authentication);
|
||||
|
||||
try
|
||||
{
|
||||
handler.handle(pathInContext, request, response);
|
||||
handler.handle(pathInContext, baseRequest, request, response);
|
||||
}
|
||||
finally
|
||||
{
|
||||
lazy.setIdentityService(null);
|
||||
}
|
||||
Authentication auth=base_request.getAuthentication();
|
||||
Authentication auth=baseRequest.getAuthentication();
|
||||
if (auth instanceof Authentication.User)
|
||||
{
|
||||
Authentication.User userAuth = (Authentication.User)auth;
|
||||
|
@ -466,8 +465,8 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti
|
|||
}
|
||||
else
|
||||
{
|
||||
base_request.setAuthentication(authentication);
|
||||
handler.handle(pathInContext, request, response);
|
||||
baseRequest.setAuthentication(authentication);
|
||||
handler.handle(pathInContext, baseRequest, request, response);
|
||||
authenticator.secureResponse(request, response, isAuthMandatory, null);
|
||||
}
|
||||
}
|
||||
|
@ -483,7 +482,7 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti
|
|||
}
|
||||
}
|
||||
else
|
||||
handler.handle(pathInContext, request, response);
|
||||
handler.handle(pathInContext, baseRequest, request, response);
|
||||
}
|
||||
|
||||
|
||||
|
@ -494,7 +493,7 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti
|
|||
protected abstract boolean checkUserDataPermissions(String pathInContext, Request request, Response response, Object constraintInfo) throws IOException;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected abstract boolean isAuthMandatory(Request base_request, Response base_response, Object constraintInfo);
|
||||
protected abstract boolean isAuthMandatory(Request baseRequest, Response base_response, Object constraintInfo);
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected abstract boolean checkWebResourcePermissions(String pathInContext, Request request, Response response, Object constraintInfo,
|
||||
|
|
|
@ -570,10 +570,9 @@ public class ConstraintTest extends TestCase
|
|||
|
||||
class RequestHandler extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException
|
||||
{
|
||||
Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
if (request.getAuthType()==null || "user".equals(request.getRemoteUser()) || request.isUserInRole("user"))
|
||||
{
|
||||
response.setStatus(200);
|
||||
|
@ -591,10 +590,10 @@ public class ConstraintTest extends TestCase
|
|||
{
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.handler.HandlerWrapper#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
* @see org.eclipse.jetty.server.handler.HandlerWrapper#handle(java.lang.String, Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
UserIdentity.Scope old = ((Request) request).getUserIdentityScope();
|
||||
|
||||
|
@ -622,7 +621,7 @@ public class ConstraintTest extends TestCase
|
|||
|
||||
try
|
||||
{
|
||||
super.handle(target,request,response);
|
||||
super.handle(target,baseRequest,request, response);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -633,7 +632,7 @@ public class ConstraintTest extends TestCase
|
|||
|
||||
class RoleCheckHandler extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException
|
||||
{
|
||||
((Request) request).setHandled(true);
|
||||
if (request.getAuthType()==null || "user".equals(request.getRemoteUser()) || request.isUserInRole("untranslated"))
|
||||
|
|
|
@ -126,20 +126,20 @@ public class Dispatcher implements RequestDispatcher
|
|||
*/
|
||||
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
Request base_request=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
Request baseRequest=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
request.removeAttribute(__JSP_FILE); // TODO remove when glassfish 1044 is fixed
|
||||
|
||||
// TODO - allow stream or writer????
|
||||
|
||||
DispatcherType old_type = base_request.getDispatcherType();
|
||||
Attributes old_attr=base_request.getAttributes();
|
||||
MultiMap old_params=base_request.getParameters();
|
||||
DispatcherType old_type = baseRequest.getDispatcherType();
|
||||
Attributes old_attr=baseRequest.getAttributes();
|
||||
MultiMap old_params=baseRequest.getParameters();
|
||||
try
|
||||
{
|
||||
base_request.setDispatcherType(DispatcherType.INCLUDE);
|
||||
base_request.getConnection().include();
|
||||
baseRequest.setDispatcherType(DispatcherType.INCLUDE);
|
||||
baseRequest.getConnection().include();
|
||||
if (_named!=null)
|
||||
_contextHandler.doHandle(_named, base_request,(HttpServletRequest)request, (HttpServletResponse)response);
|
||||
_contextHandler.handle(_named,baseRequest, (HttpServletRequest)request, (HttpServletResponse)response);
|
||||
else
|
||||
{
|
||||
String query=_dQuery;
|
||||
|
@ -163,7 +163,7 @@ public class Dispatcher implements RequestDispatcher
|
|||
}
|
||||
|
||||
}
|
||||
base_request.setParameters(parameters);
|
||||
baseRequest.setParameters(parameters);
|
||||
}
|
||||
|
||||
IncludeAttributes attr = new IncludeAttributes(old_attr);
|
||||
|
@ -174,17 +174,17 @@ public class Dispatcher implements RequestDispatcher
|
|||
attr._pathInfo=_path;
|
||||
attr._query=query;
|
||||
|
||||
base_request.setAttributes(attr);
|
||||
baseRequest.setAttributes(attr);
|
||||
|
||||
_contextHandler.doHandle(_named==null?_path:_named, base_request,(HttpServletRequest)request, (HttpServletResponse)response);
|
||||
_contextHandler.handle(_named==null?_path:_named,baseRequest, (HttpServletRequest)request, (HttpServletResponse)response);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
base_request.setAttributes(old_attr);
|
||||
base_request.getConnection().included();
|
||||
base_request.setParameters(old_params);
|
||||
base_request.setDispatcherType(old_type);
|
||||
baseRequest.setAttributes(old_attr);
|
||||
baseRequest.getConnection().included();
|
||||
baseRequest.setParameters(old_params);
|
||||
baseRequest.setDispatcherType(old_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,26 +195,26 @@ public class Dispatcher implements RequestDispatcher
|
|||
*/
|
||||
protected void forward(ServletRequest request, ServletResponse response, DispatcherType dispatch) throws ServletException, IOException
|
||||
{
|
||||
Request base_request=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
Response base_response=(Response)base_request.getResponse();
|
||||
Request baseRequest=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
Response base_response=(Response)baseRequest.getResponse();
|
||||
base_response.fwdReset();
|
||||
request.removeAttribute(__JSP_FILE); // TODO remove when glassfish 1044 is fixed
|
||||
|
||||
String old_uri=base_request.getRequestURI();
|
||||
String old_context_path=base_request.getContextPath();
|
||||
String old_servlet_path=base_request.getServletPath();
|
||||
String old_path_info=base_request.getPathInfo();
|
||||
String old_query=base_request.getQueryString();
|
||||
Attributes old_attr=base_request.getAttributes();
|
||||
MultiMap old_params=base_request.getParameters();
|
||||
DispatcherType old_type=base_request.getDispatcherType();
|
||||
String old_uri=baseRequest.getRequestURI();
|
||||
String old_context_path=baseRequest.getContextPath();
|
||||
String old_servlet_path=baseRequest.getServletPath();
|
||||
String old_path_info=baseRequest.getPathInfo();
|
||||
String old_query=baseRequest.getQueryString();
|
||||
Attributes old_attr=baseRequest.getAttributes();
|
||||
MultiMap old_params=baseRequest.getParameters();
|
||||
DispatcherType old_type=baseRequest.getDispatcherType();
|
||||
|
||||
try
|
||||
{
|
||||
base_request.setDispatcherType(dispatch);
|
||||
baseRequest.setDispatcherType(dispatch);
|
||||
|
||||
if (_named!=null)
|
||||
_contextHandler.doHandle(_named, base_request,(HttpServletRequest)request, (HttpServletResponse)response);
|
||||
_contextHandler.handle(_named,baseRequest, (HttpServletRequest)request, (HttpServletResponse)response);
|
||||
else
|
||||
{
|
||||
String query=_dQuery;
|
||||
|
@ -228,8 +228,8 @@ public class Dispatcher implements RequestDispatcher
|
|||
|
||||
if( old_params == null )
|
||||
{
|
||||
base_request.getParameterNames(); // force parameters to be evaluated
|
||||
old_params = base_request.getParameters();
|
||||
baseRequest.getParameterNames(); // force parameters to be evaluated
|
||||
old_params = baseRequest.getParameters();
|
||||
}
|
||||
|
||||
if (old_params!=null && old_params.size()>0)
|
||||
|
@ -290,8 +290,8 @@ public class Dispatcher implements RequestDispatcher
|
|||
}
|
||||
}
|
||||
|
||||
base_request.setParameters(parameters);
|
||||
base_request.setQueryString(query);
|
||||
baseRequest.setParameters(parameters);
|
||||
baseRequest.setQueryString(query);
|
||||
}
|
||||
|
||||
ForwardAttributes attr = new ForwardAttributes(old_attr);
|
||||
|
@ -319,14 +319,14 @@ public class Dispatcher implements RequestDispatcher
|
|||
|
||||
|
||||
|
||||
base_request.setRequestURI(_uri);
|
||||
base_request.setContextPath(_contextHandler.getContextPath());
|
||||
base_request.setAttributes(attr);
|
||||
base_request.setQueryString(query);
|
||||
baseRequest.setRequestURI(_uri);
|
||||
baseRequest.setContextPath(_contextHandler.getContextPath());
|
||||
baseRequest.setAttributes(attr);
|
||||
baseRequest.setQueryString(query);
|
||||
|
||||
_contextHandler.doHandle(_path, base_request,(HttpServletRequest)request, (HttpServletResponse)response);
|
||||
_contextHandler.handle(_path,baseRequest, (HttpServletRequest)request, (HttpServletResponse)response);
|
||||
|
||||
if (base_request.getConnection().getResponse().isWriting())
|
||||
if (baseRequest.getConnection().getResponse().isWriting())
|
||||
{
|
||||
try {response.getWriter().close();}
|
||||
catch(IllegalStateException e) { response.getOutputStream().close(); }
|
||||
|
@ -340,14 +340,14 @@ public class Dispatcher implements RequestDispatcher
|
|||
}
|
||||
finally
|
||||
{
|
||||
base_request.setRequestURI(old_uri);
|
||||
base_request.setContextPath(old_context_path);
|
||||
base_request.setServletPath(old_servlet_path);
|
||||
base_request.setPathInfo(old_path_info);
|
||||
base_request.setAttributes(old_attr);
|
||||
base_request.setParameters(old_params);
|
||||
base_request.setQueryString(old_query);
|
||||
base_request.setDispatcherType(old_type);
|
||||
baseRequest.setRequestURI(old_uri);
|
||||
baseRequest.setContextPath(old_context_path);
|
||||
baseRequest.setServletPath(old_servlet_path);
|
||||
baseRequest.setPathInfo(old_path_info);
|
||||
baseRequest.setAttributes(old_attr);
|
||||
baseRequest.setParameters(old_params);
|
||||
baseRequest.setQueryString(old_query);
|
||||
baseRequest.setDispatcherType(old_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ public interface Handler extends LifeCycle
|
|||
/* ------------------------------------------------------------ */
|
||||
/** Handle a request.
|
||||
* @param target The target of the request - either a URI or a name.
|
||||
* @param baseRequest TODO
|
||||
* @param request The request either as the {@link Request}
|
||||
* object or a wrapper of that request. The {@link HttpConnection#getCurrentConnection()}
|
||||
* method can be used access the Request object if required.
|
||||
|
@ -36,7 +37,7 @@ public interface Handler extends LifeCycle
|
|||
* @throws IOException
|
||||
* @throws ServletException
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response)
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException;
|
||||
|
||||
public void setServer(Server server);
|
||||
|
|
|
@ -24,8 +24,29 @@ import org.eclipse.jetty.util.component.LifeCycle;
|
|||
*/
|
||||
public interface HandlerContainer extends LifeCycle
|
||||
{
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return array of handlers directly contained by this handler.
|
||||
*/
|
||||
public Handler[] getHandlers();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return array of all handlers contained by this handler and it's children
|
||||
*/
|
||||
public Handler[] getChildHandlers();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param byclass
|
||||
* @return array of all handlers contained by this handler and it's children of the passed type.
|
||||
*/
|
||||
public Handler[] getChildHandlersByClass(Class<?> byclass);
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param byclass
|
||||
* @return first handler of all handlers contained by this handler and it's children of the passed type.
|
||||
*/
|
||||
public Handler getChildHandlerByClass(Class<?> byclass);
|
||||
}
|
||||
|
|
|
@ -126,6 +126,7 @@ public class Request implements HttpServletRequest
|
|||
private String _characterEncoding;
|
||||
protected HttpConnection _connection;
|
||||
private ContextHandler.Context _context;
|
||||
private boolean _newContext;
|
||||
private String _contextPath;
|
||||
private CookieCutter _cookies;
|
||||
private boolean _cookiesExtracted=false;
|
||||
|
@ -149,7 +150,6 @@ public class Request implements HttpServletRequest
|
|||
private Object _requestAttributeListeners;
|
||||
private String _requestedSessionId;
|
||||
private boolean _requestedSessionIdFromCookie=false;
|
||||
private Object _requestListeners;
|
||||
private String _requestURI;
|
||||
private Map<Object,HttpSession> _savedNewSessions;
|
||||
private String _scheme=URIUtil.HTTP;
|
||||
|
@ -1545,9 +1545,21 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public void setContext(Context context)
|
||||
{
|
||||
_newContext=_context!=context;
|
||||
_context=context;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return True if this is the first call of takeNewContext() since the last {@link #setContext(Context)} call.
|
||||
*/
|
||||
public boolean takeNewContext()
|
||||
{
|
||||
boolean nc=_newContext;
|
||||
_newContext=false;
|
||||
return nc;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Sets the "context path" for this request
|
||||
|
@ -1679,14 +1691,6 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
_requestedSessionIdFromCookie = requestedSessionIdCookie;
|
||||
}
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param requestListeners {@link LazyList} of {@link ServletRequestListener}s
|
||||
*/
|
||||
public void setRequestListeners(Object requestListeners)
|
||||
{
|
||||
_requestListeners=requestListeners;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
|
@ -1790,17 +1794,6 @@ public class Request implements HttpServletRequest
|
|||
return _async;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return {@link LazyList} of {@link ServletRequestListener}s
|
||||
*/
|
||||
public Object takeRequestListeners()
|
||||
{
|
||||
final Object listeners=_requestListeners;
|
||||
_requestListeners=null;
|
||||
return listeners;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -302,7 +302,7 @@ public class Response implements HttpServletResponse
|
|||
request.setAttribute(Dispatcher.ERROR_REQUEST_URI, request.getRequestURI());
|
||||
request.setAttribute(Dispatcher.ERROR_SERVLET_NAME,request.getServletName());
|
||||
|
||||
error_handler.handle(null,_connection.getRequest(),this);
|
||||
error_handler.handle(null,_connection.getRequest(),_connection.getRequest(),this );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -312,17 +312,17 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
public void handle(HttpConnection connection) throws IOException, ServletException
|
||||
{
|
||||
final String target=connection.getRequest().getPathInfo();
|
||||
final HttpServletRequest request=connection.getRequest();
|
||||
final HttpServletResponse response=connection.getResponse();
|
||||
final Request request=connection.getRequest();
|
||||
final Response response=connection.getResponse();
|
||||
|
||||
if (Log.isDebugEnabled())
|
||||
{
|
||||
Log.debug("REQUEST "+target+" on "+connection);
|
||||
handle(target, request, response);
|
||||
handle(target, request, request, response);
|
||||
Log.debug("RESPONSE "+target+" "+connection.getResponse().getStatus());
|
||||
}
|
||||
else
|
||||
handle(target, request, response);
|
||||
handle(target, request, request, response);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -336,36 +336,36 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
final AsyncRequest async = connection.getRequest().getAsyncRequest();
|
||||
final AsyncRequest.AsyncEventState state = async.getAsyncEventState();
|
||||
|
||||
final Request base_request=connection.getRequest();
|
||||
final Request baseRequest=connection.getRequest();
|
||||
final String path=state.getPath();
|
||||
if (path!=null)
|
||||
{
|
||||
// this is a dispatch with a path
|
||||
base_request.setAttribute(AsyncContext.ASYNC_REQUEST_URI,base_request.getRequestURI());
|
||||
base_request.setAttribute(AsyncContext.ASYNC_QUERY_STRING,base_request.getQueryString());
|
||||
baseRequest.setAttribute(AsyncContext.ASYNC_REQUEST_URI,baseRequest.getRequestURI());
|
||||
baseRequest.setAttribute(AsyncContext.ASYNC_QUERY_STRING,baseRequest.getQueryString());
|
||||
|
||||
base_request.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH,state.getSuspendedContext().getContextPath());
|
||||
baseRequest.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH,state.getSuspendedContext().getContextPath());
|
||||
|
||||
final String contextPath=state.getServletContext().getContextPath();
|
||||
HttpURI uri = new HttpURI(URIUtil.addPaths(contextPath,path));
|
||||
base_request.setUri(uri);
|
||||
base_request.setRequestURI(null);
|
||||
base_request.setPathInfo(base_request.getRequestURI());
|
||||
base_request.setQueryString(uri.getQuery());
|
||||
baseRequest.setUri(uri);
|
||||
baseRequest.setRequestURI(null);
|
||||
baseRequest.setPathInfo(baseRequest.getRequestURI());
|
||||
baseRequest.setQueryString(uri.getQuery());
|
||||
}
|
||||
|
||||
final String target=base_request.getPathInfo();
|
||||
final String target=baseRequest.getPathInfo();
|
||||
final HttpServletRequest request=(HttpServletRequest)async.getRequest();
|
||||
final HttpServletResponse response=(HttpServletResponse)async.getResponse();
|
||||
|
||||
if (Log.isDebugEnabled())
|
||||
{
|
||||
Log.debug("REQUEST "+target+" on "+connection);
|
||||
handle(target, request, response);
|
||||
handle(target, baseRequest, request, response);
|
||||
Log.debug("RESPONSE "+target+" "+connection.getResponse().getStatus());
|
||||
}
|
||||
else
|
||||
handle(target, request, response);
|
||||
handle(target, baseRequest, request, response);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
*
|
||||
*
|
||||
*/
|
||||
public class ContextHandler extends HandlerWrapper implements Attributes, Server.Graceful, CompleteHandler
|
||||
public class ContextHandler extends ScopedHandler implements Attributes, Server.Graceful, CompleteHandler
|
||||
{
|
||||
private static ThreadLocal<Context> __context=new ThreadLocal<Context>();
|
||||
public static final String MANAGED_ATTRIBUTES = "org.eclipse.jetty.server.servlet.ManagedAttributes";
|
||||
|
@ -116,7 +116,6 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
private Set<String> _connectors;
|
||||
private EventListener[] _eventListeners;
|
||||
private Logger _logger;
|
||||
private boolean _shutdown;
|
||||
private boolean _allowNullPathInfo;
|
||||
private int _maxFormContentSize=Integer.getInteger("org.eclipse.jetty.server.Request.maxFormContentSize",200000).intValue();
|
||||
private boolean _compactPath=false;
|
||||
|
@ -127,6 +126,13 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
private Object _requestListeners;
|
||||
private Object _requestAttributeListeners;
|
||||
private Set<String> _managedAttributes;
|
||||
|
||||
private boolean _shutdown=false;
|
||||
private boolean _available=true;
|
||||
private volatile int _availability; // 0=STOPPED, 1=AVAILABLE, 2=SHUTDOWN, 3=UNAVAILABLE
|
||||
|
||||
private final static int __STOPPED=0,__AVAILABLE=1,__SHUTDOWN=2,__UNAVAILABLE=3;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
|
@ -496,7 +502,32 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
*/
|
||||
public void setShutdown(boolean shutdown)
|
||||
{
|
||||
_shutdown = shutdown;
|
||||
synchronized(this)
|
||||
{
|
||||
_shutdown = shutdown;
|
||||
_availability=isRunning()?(_shutdown?__SHUTDOWN:_available?__AVAILABLE:__UNAVAILABLE):__STOPPED;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return false if this context is unavailable (sends 503)
|
||||
*/
|
||||
public boolean isAvailable()
|
||||
{
|
||||
return _available;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Set Available status.
|
||||
*/
|
||||
public void setAvailable(boolean available)
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
_available = available;
|
||||
_availability=isRunning()?(_shutdown?__SHUTDOWN:_available?__AVAILABLE:__UNAVAILABLE):__STOPPED;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -517,6 +548,8 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
*/
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
_availability=__STOPPED;
|
||||
|
||||
if (_contextPath==null)
|
||||
throw new IllegalStateException("Null contextPath");
|
||||
|
||||
|
@ -547,10 +580,12 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
if (_errorHandler==null)
|
||||
setErrorHandler(new ErrorHandler());
|
||||
|
||||
|
||||
// defers the calling of super.doStart()
|
||||
startContext();
|
||||
|
||||
|
||||
|
||||
_availability=_shutdown?__SHUTDOWN:_available?__AVAILABLE:__UNAVAILABLE;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -561,6 +596,7 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
{
|
||||
current_thread.setContextClassLoader(old_classloader);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -616,6 +652,8 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
*/
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
_availability=__STOPPED;
|
||||
|
||||
ClassLoader old_classloader=null;
|
||||
Thread current_thread=null;
|
||||
|
||||
|
@ -670,19 +708,28 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response)
|
||||
public boolean checkContext(final String target, final Request baseRequest, final HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
DispatcherType dispatch=base_request.getDispatcherType();
|
||||
DispatcherType dispatch=baseRequest.getDispatcherType();
|
||||
|
||||
switch(_availability)
|
||||
{
|
||||
case __STOPPED:
|
||||
case __SHUTDOWN:
|
||||
return false;
|
||||
case __UNAVAILABLE:
|
||||
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
|
||||
return false;
|
||||
default:
|
||||
if((DispatcherType.REQUEST.equals(dispatch) && baseRequest.isHandled()))
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !isStarted() || _shutdown || (DispatcherType.REQUEST.equals(dispatch) && base_request.isHandled()))
|
||||
return;
|
||||
|
||||
// Check the vhosts
|
||||
if (_vhosts!=null && _vhosts.length>0)
|
||||
{
|
||||
String vhost = normalizeHostname( request.getServerName());
|
||||
String vhost = normalizeHostname( baseRequest.getServerName());
|
||||
|
||||
boolean match=false;
|
||||
|
||||
|
@ -698,7 +745,7 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
match=contextVhost.equalsIgnoreCase(vhost);
|
||||
}
|
||||
if (!match)
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the connector
|
||||
|
@ -706,43 +753,41 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
{
|
||||
String connector=HttpConnection.getCurrentConnection().getConnector().getName();
|
||||
if (connector==null || !_connectors.contains(connector))
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_compactPath)
|
||||
target=URIUtil.compactPath(target);
|
||||
|
||||
if (target.startsWith(_contextPath))
|
||||
{
|
||||
if (_contextPath.length()==target.length() && _contextPath.length()>1 &&!_allowNullPathInfo)
|
||||
{
|
||||
// context request must end with /
|
||||
base_request.setHandled(true);
|
||||
if (request.getQueryString()!=null)
|
||||
response.sendRedirect(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH)+"?"+request.getQueryString());
|
||||
baseRequest.setHandled(true);
|
||||
if (baseRequest.getQueryString()!=null)
|
||||
response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(),URIUtil.SLASH)+"?"+baseRequest.getQueryString());
|
||||
else
|
||||
response.sendRedirect(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH));
|
||||
return;
|
||||
response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(),URIUtil.SLASH));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not for this context!
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
doHandle(target,base_request,request,response);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.jetty.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.handler.ScopedHandler#doScope(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
boolean new_context=false;
|
||||
@Override
|
||||
public void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Context old_context=null;
|
||||
String old_context_path=null;
|
||||
String old_servlet_path=null;
|
||||
|
@ -754,15 +799,18 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
DispatcherType dispatch=baseRequest.getDispatcherType();
|
||||
|
||||
old_context=baseRequest.getContext();
|
||||
|
||||
|
||||
// Are we already in this context?
|
||||
if (old_context!=_scontext)
|
||||
{
|
||||
new_context=true;
|
||||
|
||||
// check the target.
|
||||
if (DispatcherType.REQUEST.equals(dispatch) || DispatcherType.ASYNC.equals(dispatch))
|
||||
{
|
||||
if (_compactPath)
|
||||
target=URIUtil.compactPath(target);
|
||||
if (!checkContext(target,baseRequest,response))
|
||||
return;
|
||||
|
||||
if (target.length()>_contextPath.length())
|
||||
{
|
||||
if (_contextPath.length()>1)
|
||||
|
@ -780,6 +828,14 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
pathInfo=null;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the classloader
|
||||
if (_classLoader!=null)
|
||||
{
|
||||
current_thread=Thread.currentThread();
|
||||
old_classloader=current_thread.getContextClassLoader();
|
||||
current_thread.setContextClassLoader(_classLoader);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -799,56 +855,8 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
baseRequest.setServletPath(null);
|
||||
baseRequest.setPathInfo(pathInfo);
|
||||
}
|
||||
|
||||
ServletRequestEvent event=null;
|
||||
if (new_context)
|
||||
{
|
||||
// Set the classloader
|
||||
if (_classLoader!=null)
|
||||
{
|
||||
current_thread=Thread.currentThread();
|
||||
old_classloader=current_thread.getContextClassLoader();
|
||||
current_thread.setContextClassLoader(_classLoader);
|
||||
}
|
||||
|
||||
// Handle the REALLY SILLY request events!
|
||||
baseRequest.setRequestListeners(_requestListeners);
|
||||
if (_requestAttributeListeners!=null)
|
||||
{
|
||||
final int s=LazyList.size(_requestAttributeListeners);
|
||||
for(int i=0;i<s;i++)
|
||||
baseRequest.addEventListener(((EventListener)LazyList.get(_requestAttributeListeners,i)));
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the request
|
||||
try
|
||||
{
|
||||
if (DispatcherType.REQUEST.equals(dispatch) && isProtectedTarget(target))
|
||||
throw new HttpException(HttpServletResponse.SC_NOT_FOUND);
|
||||
|
||||
Handler handler = getHandler();
|
||||
if (handler!=null)
|
||||
handler.handle(target, request, response);
|
||||
}
|
||||
catch(HttpException e)
|
||||
{
|
||||
Log.debug(e);
|
||||
response.sendError(e.getStatus(), e.getReason());
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Handle more REALLY SILLY request events!
|
||||
if (new_context)
|
||||
{
|
||||
baseRequest.takeRequestListeners();
|
||||
if (_requestAttributeListeners!=null)
|
||||
{
|
||||
for(int i=LazyList.size(_requestAttributeListeners);i-->0;)
|
||||
baseRequest.removeEventListener(((EventListener)LazyList.get(_requestAttributeListeners,i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
nextScope(target,baseRequest,request,response);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -867,7 +875,69 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
baseRequest.setPathInfo(old_path_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.handler.ScopedHandler#doHandle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
public void doHandle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
final DispatcherType dispatch=baseRequest.getDispatcherType();
|
||||
final boolean new_context=baseRequest.takeNewContext();
|
||||
try
|
||||
{
|
||||
if (new_context)
|
||||
{
|
||||
// Handle the REALLY SILLY request events!
|
||||
if (_requestAttributeListeners!=null)
|
||||
{
|
||||
final int s=LazyList.size(_requestAttributeListeners);
|
||||
for(int i=0;i<s;i++)
|
||||
baseRequest.addEventListener(((EventListener)LazyList.get(_requestAttributeListeners,i)));
|
||||
}
|
||||
|
||||
if (_requestListeners!=null)
|
||||
{
|
||||
final int s=LazyList.size(_requestListeners);
|
||||
final ServletRequestEvent sre = new ServletRequestEvent(_scontext,request);
|
||||
for(int i=0;i<s;i++)
|
||||
((ServletRequestListener)LazyList.get(_requestListeners,i)).requestInitialized(sre);
|
||||
}
|
||||
}
|
||||
|
||||
if (DispatcherType.REQUEST.equals(dispatch) && isProtectedTarget(target))
|
||||
throw new HttpException(HttpServletResponse.SC_NOT_FOUND);
|
||||
|
||||
nextHandle(target,baseRequest,request,response);
|
||||
}
|
||||
catch(HttpException e)
|
||||
{
|
||||
Log.debug(e);
|
||||
response.sendError(e.getStatus(), e.getReason());
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Handle more REALLY SILLY request events!
|
||||
if (new_context)
|
||||
{
|
||||
if (_requestListeners!=null)
|
||||
{
|
||||
final int s=LazyList.size(_requestListeners);
|
||||
final ServletRequestEvent sre = new ServletRequestEvent(_scontext,request);
|
||||
for(int i=0;i<s;i++)
|
||||
((ServletRequestListener)LazyList.get(_requestListeners,i)).requestInitialized(sre);
|
||||
}
|
||||
|
||||
if (_requestAttributeListeners!=null)
|
||||
{
|
||||
for(int i=LazyList.size(_requestAttributeListeners);i-->0;)
|
||||
baseRequest.removeEventListener(((EventListener)LazyList.get(_requestAttributeListeners,i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* Handle a runnable in this context
|
||||
|
@ -899,7 +969,7 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Check the target.
|
||||
* Called by {@link #handle(String, HttpServletRequest, HttpServletResponse)} when a
|
||||
* Called by {@link #handle(String, Request, HttpServletRequest, HttpServletResponse)} when a
|
||||
* target within a context is determined. If the target is protected, 404 is returned.
|
||||
* The default implementation always returns false.
|
||||
* @see org.eclipse.jetty.webapp.WebAppContext#isProtectedTarget(String)
|
||||
|
|
|
@ -166,21 +166,19 @@ public class ContextHandlerCollection extends HandlerCollection
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.server.Handler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Handler[] handlers = getHandlers();
|
||||
if (handlers==null || handlers.length==0)
|
||||
return;
|
||||
|
||||
Request base_request = HttpConnection.getCurrentConnection().getRequest();
|
||||
|
||||
AsyncRequest async = base_request.getAsyncRequest();
|
||||
AsyncRequest async = baseRequest.getAsyncRequest();
|
||||
if (async.isAsync())
|
||||
{
|
||||
ContextHandler context=async.getContextHandler();
|
||||
if (context!=null)
|
||||
{
|
||||
context.doHandle(target,base_request,request,response);
|
||||
context.handle(target,baseRequest,request, response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -211,8 +209,8 @@ public class ContextHandlerCollection extends HandlerCollection
|
|||
for (int j=0; j<LazyList.size(list); j++)
|
||||
{
|
||||
Handler handler = (Handler)LazyList.get(list,j);
|
||||
handler.handle(target,request, response);
|
||||
if (base_request.isHandled())
|
||||
handler.handle(target,baseRequest, request, response);
|
||||
if (baseRequest.isHandled())
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -221,8 +219,8 @@ public class ContextHandlerCollection extends HandlerCollection
|
|||
for (int j=0; j<LazyList.size(list); j++)
|
||||
{
|
||||
Handler handler = (Handler)LazyList.get(list,j);
|
||||
handler.handle(target,request, response);
|
||||
if (base_request.isHandled())
|
||||
handler.handle(target,baseRequest, request, response);
|
||||
if (baseRequest.isHandled())
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -232,8 +230,8 @@ public class ContextHandlerCollection extends HandlerCollection
|
|||
for (int j=0; j<LazyList.size(list); j++)
|
||||
{
|
||||
Handler handler = (Handler)LazyList.get(list,j);
|
||||
handler.handle(target,request, response);
|
||||
if (base_request.isHandled())
|
||||
handler.handle(target,baseRequest, request, response);
|
||||
if (baseRequest.isHandled())
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -242,8 +240,8 @@ public class ContextHandlerCollection extends HandlerCollection
|
|||
for (int j=0; j<LazyList.size(list); j++)
|
||||
{
|
||||
Handler handler = (Handler)LazyList.get(list,j);
|
||||
handler.handle(target,request, response);
|
||||
if (base_request.isHandled())
|
||||
handler.handle(target,baseRequest, request, response);
|
||||
if (baseRequest.isHandled())
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -254,8 +252,8 @@ public class ContextHandlerCollection extends HandlerCollection
|
|||
// This may not work in all circumstances... but then I think it should never be called
|
||||
for (int i=0;i<handlers.length;i++)
|
||||
{
|
||||
handlers[i].handle(target,request, response);
|
||||
if ( base_request.isHandled())
|
||||
handlers[i].handle(target,baseRequest, request, response);
|
||||
if ( baseRequest.isHandled())
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,14 +70,12 @@ public class DefaultHandler extends AbstractHandler
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Request base_request = request instanceof Request?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
|
||||
if (response.isCommitted() || base_request.isHandled())
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (response.isCommitted() || baseRequest.isHandled())
|
||||
return;
|
||||
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
|
||||
String method=request.getMethod();
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.jetty.http.HttpMethods;
|
|||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http.MimeTypes;
|
||||
import org.eclipse.jetty.server.HttpConnection;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.util.ByteArrayISO8859Writer;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
|
||||
|
@ -44,7 +45,7 @@ public class ErrorHandler extends AbstractHandler
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||
{
|
||||
HttpConnection connection = HttpConnection.getCurrentConnection();
|
||||
connection.getRequest().setHandled(true);
|
||||
|
|
|
@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.LazyList;
|
||||
import org.eclipse.jetty.util.MultiException;
|
||||
|
@ -111,7 +112,7 @@ public class HandlerCollection extends AbstractHandlerContainer
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.server.EventHandler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response)
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
if (_handlers!=null && isStarted())
|
||||
|
@ -122,7 +123,7 @@ public class HandlerCollection extends AbstractHandlerContainer
|
|||
{
|
||||
try
|
||||
{
|
||||
_handlers[i].handle(target,request, response);
|
||||
_handlers[i].handle(target,baseRequest, request, response);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
|
|
|
@ -35,18 +35,17 @@ public class HandlerList extends HandlerCollection
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.server.EventHandler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response)
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
Handler[] handlers = getHandlers();
|
||||
|
||||
if (handlers!=null && isStarted())
|
||||
{
|
||||
Request base_request = HttpConnection.getCurrentConnection().getRequest();
|
||||
for (int i=0;i<handlers.length;i++)
|
||||
{
|
||||
handlers[i].handle(target,request, response);
|
||||
if ( base_request.isHandled())
|
||||
handlers[i].handle(target,baseRequest, request, response);
|
||||
if ( baseRequest.isHandled())
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.HandlerContainer;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
|
||||
|
@ -31,7 +32,7 @@ import org.eclipse.jetty.util.component.LifeCycle;
|
|||
*/
|
||||
public class HandlerWrapper extends AbstractHandlerContainer
|
||||
{
|
||||
private Handler _handler;
|
||||
protected Handler _handler;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
|
@ -107,11 +108,11 @@ public class HandlerWrapper extends AbstractHandlerContainer
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.server.EventHandler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (_handler!=null && isStarted())
|
||||
{
|
||||
_handler.handle(target,request, response);
|
||||
_handler.handle(target,baseRequest, request, response);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.HandlerContainer;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
|
||||
|
@ -128,11 +129,11 @@ public class HotSwapHandler extends AbstractHandlerContainer
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.server.EventHandler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (_handler!=null && isStarted())
|
||||
{
|
||||
_handler.handle(target,request, response);
|
||||
_handler.handle(target,baseRequest, request, response);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,13 +97,11 @@ public class MovedContextHandler extends ContextHandler
|
|||
|
||||
private class Redirector extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (_newContextURL==null)
|
||||
return;
|
||||
|
||||
Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
|
||||
|
||||
String url = _newContextURL;
|
||||
if (!_discardPathInfo && request.getPathInfo()!=null)
|
||||
url=URIUtil.addPaths(url, request.getPathInfo());
|
||||
|
@ -116,7 +114,7 @@ public class MovedContextHandler extends ContextHandler
|
|||
if (!_discardPathInfo && request.getPathInfo()!=null)
|
||||
path=URIUtil.addPaths(path, request.getPathInfo());
|
||||
|
||||
StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():base_request.getRootURL();
|
||||
StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
|
||||
|
||||
location.append(path);
|
||||
if (!_discardQuery && request.getQueryString()!=null)
|
||||
|
@ -132,7 +130,7 @@ public class MovedContextHandler extends ContextHandler
|
|||
|
||||
response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
|
||||
response.setContentLength(0);
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,12 +44,11 @@ public class RequestLogHandler extends HandlerWrapper
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.server.Handler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response)
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
super.handle(target, request, response);
|
||||
Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
if (DispatcherType.REQUEST.equals(base_request.getDispatcherType()) && _requestLog!=null)
|
||||
super.handle(target, baseRequest, request, response);
|
||||
if (DispatcherType.REQUEST.equals(baseRequest.getDispatcherType()) && _requestLog!=null)
|
||||
_requestLog.log((Request)request, (Response)response);
|
||||
}
|
||||
|
||||
|
|
|
@ -252,10 +252,9 @@ public class ResourceHandler extends AbstractHandler
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Request base_request = request instanceof Request?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
if (base_request.isHandled())
|
||||
if (baseRequest.isHandled())
|
||||
return;
|
||||
|
||||
boolean skipContentBody = false;
|
||||
|
@ -277,7 +276,7 @@ public class ResourceHandler extends AbstractHandler
|
|||
}
|
||||
|
||||
// We are going to server something
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
|
||||
if (resource.isDirectory())
|
||||
{
|
||||
|
@ -293,7 +292,7 @@ public class ResourceHandler extends AbstractHandler
|
|||
else
|
||||
{
|
||||
doDirectory(request,response,resource);
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
package org.eclipse.jetty.server.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** ScopedHandler.
|
||||
*
|
||||
* A ScopedHandler is a HandlerWrapper where the wrapped handlers
|
||||
* each define a scope. When {@link #handle(String, Request, HttpServletRequest, HttpServletResponse)}
|
||||
* is called on the first ScopedHandler in a chain of HandlerWrappers,
|
||||
* the {@link #doScope(String, Request, HttpServletRequest, HttpServletResponse)} method is
|
||||
* called on all contained ScopedHandlers, before the
|
||||
* {@link #doHandle(String, Request, HttpServletRequest, HttpServletResponse)} method
|
||||
* is called on all contained handlers.
|
||||
*
|
||||
* <p>For example if Scoped handlers A, B & C were chained together, then
|
||||
* the calling order would be:<pre>
|
||||
* A.handle(...)
|
||||
* A.doScope(...)
|
||||
* B.doScope(...)
|
||||
* C.doScope(...)
|
||||
* A.doHandle(...)
|
||||
* B.doHandle(...)
|
||||
* C.doHandle(...)
|
||||
* <pre>
|
||||
*
|
||||
* <p>If non scoped handler X was in the chained A, B, X & C, then
|
||||
* the calling order would be:<pre>
|
||||
* A.handle(...)
|
||||
* A.doScope(...)
|
||||
* B.doScope(...)
|
||||
* C.doScope(...)
|
||||
* A.doHandle(...)
|
||||
* B.doHandle(...)
|
||||
* X.handle(...)
|
||||
* C.handle(...)
|
||||
* C.doHandle(...)
|
||||
* <pre>
|
||||
*
|
||||
* <p>A typical usage pattern is:<pre>
|
||||
* private static class MyHandler extends ScopedHandler
|
||||
* {
|
||||
* public void doScope(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
* {
|
||||
* try
|
||||
* {
|
||||
* setUpMyScope();
|
||||
* super.doScope(target,request,response);
|
||||
* }
|
||||
* finally
|
||||
* {
|
||||
* tearDownMyScope();
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* public void doHandle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
* {
|
||||
* try
|
||||
* {
|
||||
* doMyHandling();
|
||||
* super.doHandle(target,request,response);
|
||||
* }
|
||||
* finally
|
||||
* {
|
||||
* cleanupMyHandling();
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public abstract class ScopedHandler extends HandlerWrapper
|
||||
{
|
||||
private static ThreadLocal<ScopedHandler> __outerScope= new ThreadLocal<ScopedHandler>();
|
||||
protected ScopedHandler _outerScope;
|
||||
protected ScopedHandler _nextScope;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.handler.HandlerWrapper#doStart()
|
||||
*/
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
_outerScope=__outerScope.get();
|
||||
if (_outerScope==null)
|
||||
__outerScope.set(this);
|
||||
|
||||
super.doStart();
|
||||
|
||||
_nextScope= (ScopedHandler)getChildHandlerByClass(ScopedHandler.class);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (_outerScope==null)
|
||||
__outerScope.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
*/
|
||||
public final void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (_outerScope==null)
|
||||
doScope(target,baseRequest,request, response);
|
||||
else
|
||||
doHandle(target,baseRequest,request, response);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* Scope the handler
|
||||
*/
|
||||
public abstract void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* Scope the handler
|
||||
*/
|
||||
public final void nextScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
if (_nextScope!=null)
|
||||
_nextScope.doScope(target,baseRequest,request, response);
|
||||
else if (_outerScope!=null)
|
||||
_outerScope.doHandle(target,baseRequest,request, response);
|
||||
else
|
||||
doHandle(target,baseRequest,request, response);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* Do the handler work within the scope.
|
||||
*/
|
||||
public abstract void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* Do the handler work within the scope.
|
||||
*/
|
||||
public final void nextHandle(String target, final Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (_nextScope!=null && _nextScope==_handler)
|
||||
_nextScope.doHandle(target,baseRequest,request, response);
|
||||
else if (_handler!=null)
|
||||
_handler.handle(target,baseRequest, request, response);
|
||||
}
|
||||
|
||||
}
|
|
@ -80,18 +80,17 @@ public class StatisticsHandler extends HandlerWrapper implements CompleteHandler
|
|||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
final Request base_request=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
final Response base_response=(response instanceof Response)?((Response)response):HttpConnection.getCurrentConnection().getResponse();
|
||||
final Response base_response=baseRequest.getResponse();
|
||||
|
||||
long timestamp0=base_request.getTimeStamp();
|
||||
long timestamp0=baseRequest.getTimeStamp();
|
||||
long timestamp1=timestamp0;
|
||||
try
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
AsyncRequest asyncContextState=base_request.getAsyncRequest();
|
||||
AsyncRequest asyncContextState=baseRequest.getAsyncRequest();
|
||||
|
||||
if(asyncContextState==null)
|
||||
{
|
||||
|
@ -118,7 +117,7 @@ public class StatisticsHandler extends HandlerWrapper implements CompleteHandler
|
|||
_requestsActiveMax=_requestsActive;
|
||||
}
|
||||
|
||||
super.handle(target, request, response);
|
||||
super.handle(target, baseRequest, request, response);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -138,10 +137,10 @@ public class StatisticsHandler extends HandlerWrapper implements CompleteHandler
|
|||
_requestsActiveDurationMax=duration;
|
||||
|
||||
|
||||
if(base_request.isAsyncStarted())
|
||||
if(baseRequest.isAsyncStarted())
|
||||
{
|
||||
Object list = base_request.getAttribute(COMPLETE_HANDLER_ATTR);
|
||||
base_request.setAttribute(COMPLETE_HANDLER_ATTR, LazyList.add(list, this));
|
||||
Object list = baseRequest.getAttribute(COMPLETE_HANDLER_ATTR);
|
||||
baseRequest.setAttribute(COMPLETE_HANDLER_ATTR, LazyList.add(list, this));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -130,46 +130,45 @@ public class SessionHandler extends HandlerWrapper
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response)
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
setRequestedId(request);
|
||||
|
||||
Request base_request = (request instanceof Request) ? (Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
SessionManager old_session_manager=null;
|
||||
HttpSession old_session=null;
|
||||
|
||||
try
|
||||
{
|
||||
old_session_manager = base_request.getSessionManager();
|
||||
old_session = base_request.getSession(false);
|
||||
old_session_manager = baseRequest.getSessionManager();
|
||||
old_session = baseRequest.getSession(false);
|
||||
|
||||
if (old_session_manager != _sessionManager)
|
||||
{
|
||||
// new session context
|
||||
base_request.setSessionManager(_sessionManager);
|
||||
base_request.setSession(null);
|
||||
baseRequest.setSessionManager(_sessionManager);
|
||||
baseRequest.setSession(null);
|
||||
}
|
||||
|
||||
// access any existing session
|
||||
HttpSession session=null;
|
||||
if (_sessionManager!=null)
|
||||
{
|
||||
session=base_request.getSession(false);
|
||||
session=baseRequest.getSession(false);
|
||||
if (session!=null)
|
||||
{
|
||||
if(session!=old_session)
|
||||
{
|
||||
HttpCookie cookie = _sessionManager.access(session,request.isSecure());
|
||||
if (cookie!=null ) // Handle changed ID or max-age refresh
|
||||
base_request.getResponse().addCookie(cookie);
|
||||
baseRequest.getResponse().addCookie(cookie);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
session=base_request.recoverNewSession(_sessionManager);
|
||||
session=baseRequest.recoverNewSession(_sessionManager);
|
||||
if (session!=null)
|
||||
base_request.setSession(session);
|
||||
baseRequest.setSession(session);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,13 +178,13 @@ public class SessionHandler extends HandlerWrapper
|
|||
Log.debug("session="+session);
|
||||
}
|
||||
|
||||
getHandler().handle(target, request, response);
|
||||
getHandler().handle(target, baseRequest, request, response);
|
||||
}
|
||||
catch (RetryRequest r)
|
||||
{
|
||||
HttpSession session=base_request.getSession(false);
|
||||
HttpSession session=baseRequest.getSession(false);
|
||||
if (session!=null && session.isNew())
|
||||
base_request.saveNewSession(_sessionManager,session);
|
||||
baseRequest.saveNewSession(_sessionManager,session);
|
||||
throw r;
|
||||
}
|
||||
finally
|
||||
|
@ -197,8 +196,8 @@ public class SessionHandler extends HandlerWrapper
|
|||
//leaving context, free up the session
|
||||
if (session!=null)
|
||||
_sessionManager.complete(session);
|
||||
base_request.setSessionManager(old_session_manager);
|
||||
base_request.setSession(old_session);
|
||||
baseRequest.setSessionManager(old_session_manager);
|
||||
baseRequest.setSession(old_session);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -210,9 +209,9 @@ public class SessionHandler extends HandlerWrapper
|
|||
*/
|
||||
protected void setRequestedId(HttpServletRequest request)
|
||||
{
|
||||
Request base_request = (request instanceof Request) ? (Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
Request baseRequest = (request instanceof Request) ? (Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
String requested_session_id=request.getRequestedSessionId();
|
||||
if (!DispatcherType.REQUEST.equals(base_request.getDispatcherType()) || requested_session_id!=null)
|
||||
if (!DispatcherType.REQUEST.equals(baseRequest.getDispatcherType()) || requested_session_id!=null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -266,8 +265,8 @@ public class SessionHandler extends HandlerWrapper
|
|||
}
|
||||
}
|
||||
|
||||
base_request.setRequestedSessionId(requested_session_id);
|
||||
base_request.setRequestedSessionIdFromCookie(requested_session_id!=null && requested_session_id_from_cookie);
|
||||
baseRequest.setRequestedSessionId(requested_session_id);
|
||||
baseRequest.setRequestedSessionIdFromCookie(requested_session_id!=null && requested_session_id_from_cookie);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -185,11 +185,9 @@ public class AsyncContextTest extends TestCase
|
|||
|
||||
|
||||
|
||||
public void handle(String target, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
final Request base_request = (request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
|
||||
if (DispatcherType.REQUEST.equals(base_request.getDispatcherType()))
|
||||
public void handle(String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (DispatcherType.REQUEST.equals(baseRequest.getDispatcherType()))
|
||||
{
|
||||
if (_read>0)
|
||||
{
|
||||
|
@ -205,9 +203,9 @@ public class AsyncContextTest extends TestCase
|
|||
}
|
||||
|
||||
if (_suspendFor>0)
|
||||
base_request.setAsyncTimeout(_suspendFor);
|
||||
base_request.addEventListener(__asyncListener);
|
||||
final AsyncContext asyncContext = base_request.startAsync();
|
||||
baseRequest.setAsyncTimeout(_suspendFor);
|
||||
baseRequest.addEventListener(__asyncListener);
|
||||
final AsyncContext asyncContext = baseRequest.startAsync();
|
||||
|
||||
if (_completeAfter>0)
|
||||
{
|
||||
|
@ -219,7 +217,7 @@ public class AsyncContextTest extends TestCase
|
|||
Thread.sleep(_completeAfter);
|
||||
response.getOutputStream().print("COMPLETED");
|
||||
response.setStatus(200);
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
asyncContext.complete();
|
||||
}
|
||||
catch(Exception e)
|
||||
|
@ -233,7 +231,7 @@ public class AsyncContextTest extends TestCase
|
|||
{
|
||||
response.getOutputStream().print("COMPLETED");
|
||||
response.setStatus(200);
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
asyncContext.complete();
|
||||
}
|
||||
|
||||
|
@ -263,13 +261,13 @@ public class AsyncContextTest extends TestCase
|
|||
{
|
||||
response.setStatus(200);
|
||||
response.getOutputStream().print("TIMEOUT");
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(200);
|
||||
response.getOutputStream().print("RESUMED");
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -226,10 +226,8 @@ public class AsyncStressTest extends TestCase
|
|||
_timer=new Timer();
|
||||
}
|
||||
|
||||
public void handle(String target, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
final Request base_request = (request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
|
||||
int read_before=0;
|
||||
long sleep_for=-1;
|
||||
long suspend_for=-1;
|
||||
|
@ -247,7 +245,7 @@ public class AsyncStressTest extends TestCase
|
|||
if (request.getParameter("complete")!=null)
|
||||
complete_after=Integer.parseInt(request.getParameter("complete"));
|
||||
|
||||
if (DispatcherType.REQUEST.equals(base_request.getDispatcherType()))
|
||||
if (DispatcherType.REQUEST.equals(baseRequest.getDispatcherType()))
|
||||
{
|
||||
if (read_before>0)
|
||||
{
|
||||
|
@ -265,9 +263,9 @@ public class AsyncStressTest extends TestCase
|
|||
if (suspend_for>=0)
|
||||
{
|
||||
if (suspend_for>0)
|
||||
base_request.setAsyncTimeout(suspend_for);
|
||||
base_request.addEventListener(__asyncListener);
|
||||
base_request.startAsync();
|
||||
baseRequest.setAsyncTimeout(suspend_for);
|
||||
baseRequest.addEventListener(__asyncListener);
|
||||
baseRequest.startAsync();
|
||||
}
|
||||
else if (sleep_for>=0)
|
||||
{
|
||||
|
@ -281,18 +279,18 @@ public class AsyncStressTest extends TestCase
|
|||
}
|
||||
response.setStatus(200);
|
||||
response.getOutputStream().print("SLEPT");
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(200);
|
||||
response.getOutputStream().print("NORMAL");
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final AsyncContext asyncContext = base_request.getAsyncContext();
|
||||
final AsyncContext asyncContext = baseRequest.getAsyncContext();
|
||||
|
||||
|
||||
if (complete_after>0)
|
||||
|
@ -305,7 +303,7 @@ public class AsyncStressTest extends TestCase
|
|||
{
|
||||
response.setStatus(200);
|
||||
response.getOutputStream().print("COMPLETED");
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
asyncContext.complete();
|
||||
}
|
||||
catch(Exception e)
|
||||
|
@ -323,7 +321,7 @@ public class AsyncStressTest extends TestCase
|
|||
{
|
||||
response.setStatus(200);
|
||||
response.getOutputStream().print("COMPLETED");
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
asyncContext.complete();
|
||||
}
|
||||
|
||||
|
@ -350,13 +348,13 @@ public class AsyncStressTest extends TestCase
|
|||
{
|
||||
response.setStatus(200);
|
||||
response.getOutputStream().print("TIMEOUT");
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(200);
|
||||
response.getOutputStream().print("RESUMED");
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ public class CheckReverseProxyHeadersTest extends TestCase
|
|||
return _error;
|
||||
}
|
||||
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -59,10 +59,8 @@ public class DumpHandler extends AbstractHandler
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.server.Handler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Request base_request = (request instanceof Request) ? (Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (!isStarted())
|
||||
return;
|
||||
|
||||
|
@ -73,7 +71,7 @@ public class DumpHandler extends AbstractHandler
|
|||
continuation.suspend();
|
||||
}
|
||||
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
response.setHeader(HttpHeaders.CONTENT_TYPE,MimeTypes.TEXT_HTML);
|
||||
|
||||
OutputStream out = response.getOutputStream();
|
||||
|
|
|
@ -817,10 +817,9 @@ public class HttpServerTestBase extends TestCase
|
|||
{
|
||||
// ~ Methods
|
||||
// ------------------------------------------------------------
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
|
||||
if (request.getContentType()!=null)
|
||||
response.setContentType(request.getContentType());
|
||||
|
@ -857,10 +856,9 @@ public class HttpServerTestBase extends TestCase
|
|||
private static class HelloWorldHandler extends AbstractHandler
|
||||
{
|
||||
// ------------------------------------------------------------
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
response.setStatus(200);
|
||||
response.getOutputStream().print("Hello world\r\n");
|
||||
}
|
||||
|
@ -870,10 +868,9 @@ public class HttpServerTestBase extends TestCase
|
|||
private static class DataHandler extends AbstractHandler
|
||||
{
|
||||
// ------------------------------------------------------------
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
response.setStatus(200);
|
||||
|
||||
InputStream in = request.getInputStream();
|
||||
|
|
|
@ -409,7 +409,7 @@ public class RequestTest extends TestCase
|
|||
RequestTester _checker;
|
||||
String _content;
|
||||
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
((Request)request).setHandled(true);
|
||||
|
||||
|
|
|
@ -365,7 +365,7 @@ public class ResponseTest extends TestCase
|
|||
server.addConnector(socketConnector);
|
||||
server.setHandler(new AbstractHandler()
|
||||
{
|
||||
public void handle(String string, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String string, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
response.setStatus(200);
|
||||
response.setContentType("text/plain");
|
||||
|
|
|
@ -39,8 +39,8 @@ public class UnreadInputTest extends TestCase
|
|||
|
||||
public class NoopHandler extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request,
|
||||
HttpServletResponse response) throws IOException,
|
||||
public void handle(String target, Request baseRequest,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException,
|
||||
ServletException
|
||||
{
|
||||
//don't read the input, just send something back
|
||||
|
|
|
@ -160,10 +160,9 @@ public class ContextHandlerCollectionTest extends TestCase
|
|||
return handled;
|
||||
}
|
||||
|
||||
public void handle(String s, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String s, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Request base_request = (request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
this.handled = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -210,10 +210,9 @@ public class ContextHandlerTest extends TestCase
|
|||
return handled;
|
||||
}
|
||||
|
||||
public void handle(String s, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String s, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
Request base_request = (request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
this.handled = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
package org.eclipse.jetty.server.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ScopedHandlerTest extends TestCase
|
||||
{
|
||||
StringBuilder _history=new StringBuilder();
|
||||
|
||||
public void testSingle()
|
||||
throws Exception
|
||||
{
|
||||
_history.setLength(0);
|
||||
TestHandler handler0 = new TestHandler("0");
|
||||
handler0.start();
|
||||
handler0.handle("target",null,null,null);
|
||||
handler0.stop();
|
||||
String history=_history.toString();
|
||||
System.err.println(history);
|
||||
assertEquals(">S0>W0<W0<S0",history);
|
||||
}
|
||||
|
||||
public void testSimpleDouble()
|
||||
throws Exception
|
||||
{
|
||||
_history.setLength(0);
|
||||
TestHandler handler0 = new TestHandler("0");
|
||||
TestHandler handler1 = new TestHandler("1");
|
||||
handler0.setHandler(handler1);
|
||||
handler0.start();
|
||||
handler0.handle("target",null,null,null);
|
||||
handler0.stop();
|
||||
String history=_history.toString();
|
||||
System.err.println(history);
|
||||
assertEquals(">S0>S1>W0>W1<W1<W0<S1<S0",history);
|
||||
}
|
||||
|
||||
public void testSimpleTriple()
|
||||
throws Exception
|
||||
{
|
||||
_history.setLength(0);
|
||||
TestHandler handler0 = new TestHandler("0");
|
||||
TestHandler handler1 = new TestHandler("1");
|
||||
TestHandler handler2 = new TestHandler("2");
|
||||
handler0.setHandler(handler1);
|
||||
handler1.setHandler(handler2);
|
||||
handler0.start();
|
||||
handler0.handle("target",null,null,null);
|
||||
handler0.stop();
|
||||
String history=_history.toString();
|
||||
System.err.println(history);
|
||||
assertEquals(">S0>S1>S2>W0>W1>W2<W2<W1<W0<S2<S1<S0",history);
|
||||
}
|
||||
|
||||
public void testDouble()
|
||||
throws Exception
|
||||
{
|
||||
_history.setLength(0);
|
||||
TestHandler handler0 = new TestHandler("0");
|
||||
OtherHandler handlerA = new OtherHandler("A");
|
||||
TestHandler handler1 = new TestHandler("1");
|
||||
OtherHandler handlerB = new OtherHandler("B");
|
||||
handler0.setHandler(handlerA);
|
||||
handlerA.setHandler(handler1);
|
||||
handler1.setHandler(handlerB);
|
||||
handler0.start();
|
||||
handler0.handle("target",null,null,null);
|
||||
handler0.stop();
|
||||
String history=_history.toString();
|
||||
System.err.println(history);
|
||||
assertEquals(">S0>S1>W0>HA>W1>HB<HB<W1<HA<W0<S1<S0",history);
|
||||
}
|
||||
|
||||
public void testTriple()
|
||||
throws Exception
|
||||
{
|
||||
_history.setLength(0);
|
||||
TestHandler handler0 = new TestHandler("0");
|
||||
OtherHandler handlerA = new OtherHandler("A");
|
||||
TestHandler handler1 = new TestHandler("1");
|
||||
OtherHandler handlerB = new OtherHandler("B");
|
||||
TestHandler handler2 = new TestHandler("2");
|
||||
OtherHandler handlerC = new OtherHandler("C");
|
||||
handler0.setHandler(handlerA);
|
||||
handlerA.setHandler(handler1);
|
||||
handler1.setHandler(handlerB);
|
||||
handlerB.setHandler(handler2);
|
||||
handler2.setHandler(handlerC);
|
||||
handler0.start();
|
||||
handler0.handle("target",null,null,null);
|
||||
handler0.stop();
|
||||
String history=_history.toString();
|
||||
System.err.println(history);
|
||||
assertEquals(">S0>S1>S2>W0>HA>W1>HB>W2>HC<HC<W2<HB<W1<HA<W0<S2<S1<S0",history);
|
||||
}
|
||||
|
||||
private class TestHandler extends ScopedHandler
|
||||
{
|
||||
String _name;
|
||||
TestHandler(String name)
|
||||
{
|
||||
_name=name;
|
||||
}
|
||||
|
||||
public void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
try
|
||||
{
|
||||
_history.append(">S"+_name);
|
||||
super.nextScope(target,baseRequest,request, response);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_history.append("<S"+_name);
|
||||
}
|
||||
}
|
||||
|
||||
public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
try
|
||||
{
|
||||
_history.append(">W"+_name);
|
||||
super.nextHandle(target,baseRequest,request,response);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_history.append("<W"+_name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class OtherHandler extends HandlerWrapper
|
||||
{
|
||||
String _name;
|
||||
|
||||
OtherHandler(String name)
|
||||
{
|
||||
_name=name;
|
||||
}
|
||||
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
try
|
||||
{
|
||||
_history.append(">H"+_name);
|
||||
super.handle(target,baseRequest,request, response);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_history.append("<H"+_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -210,7 +210,7 @@ public class StatisticsHandlerTest extends TestCase
|
|||
_lock = lock;
|
||||
}
|
||||
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (!((Request)request).isAsyncStarted())
|
||||
{
|
||||
|
@ -243,7 +243,7 @@ public class StatisticsHandlerTest extends TestCase
|
|||
_suspendFor = suspendFor;
|
||||
}
|
||||
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (!((Request)request).isAsyncStarted())
|
||||
{
|
||||
|
@ -256,7 +256,7 @@ public class StatisticsHandlerTest extends TestCase
|
|||
|
||||
private static class ResumeHandler extends HandlerWrapper
|
||||
{
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (!((Request)request).isAsyncStarted())
|
||||
{
|
||||
|
@ -276,7 +276,7 @@ public class StatisticsHandlerTest extends TestCase
|
|||
_duration = duration;
|
||||
}
|
||||
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (!((Request)request).isAsyncStarted())
|
||||
{
|
||||
|
@ -304,7 +304,7 @@ public class StatisticsHandlerTest extends TestCase
|
|||
_suspendFor = suspendFor;
|
||||
}
|
||||
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
|
||||
Integer i = (Integer)request.getAttribute("i");
|
||||
|
@ -346,11 +346,9 @@ public class StatisticsHandlerTest extends TestCase
|
|||
_lock = lock;
|
||||
}
|
||||
|
||||
public void handle(String target, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
final Request base_request=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
|
||||
if(!base_request.isAsyncStarted())
|
||||
public void handle(String target, final Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if(!baseRequest.isAsyncStarted())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -359,9 +357,9 @@ public class StatisticsHandlerTest extends TestCase
|
|||
{
|
||||
}
|
||||
|
||||
base_request.setAsyncTimeout(_completeDuration*10);
|
||||
baseRequest.setAsyncTimeout(_completeDuration*10);
|
||||
|
||||
base_request.startAsync();
|
||||
baseRequest.startAsync();
|
||||
|
||||
(new Thread() {
|
||||
public void run()
|
||||
|
@ -369,7 +367,7 @@ public class StatisticsHandlerTest extends TestCase
|
|||
try
|
||||
{
|
||||
Thread.sleep(_completeDuration);
|
||||
base_request.getAsyncContext().complete();
|
||||
baseRequest.getAsyncContext().complete();
|
||||
|
||||
synchronized(_lock)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
|
||||
|
@ -246,7 +247,7 @@ public class SSLEngineTest extends TestCase
|
|||
// ~ Methods
|
||||
// ------------------------------------------------------------
|
||||
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
// System.err.println("HANDLE "+request.getRequestURI());
|
||||
String ssl_id = (String)request.getAttribute("javax.servlet.request.ssl_session_id");
|
||||
|
|
|
@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import org.eclipse.jetty.http.HttpMethods;
|
||||
import org.eclipse.jetty.server.Dispatcher;
|
||||
import org.eclipse.jetty.server.HttpConnection;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ErrorHandler;
|
||||
import org.eclipse.jetty.util.TypeUtil;
|
||||
|
@ -59,7 +60,7 @@ public class ErrorPageErrorHandler extends ErrorHandler
|
|||
/*
|
||||
* @see org.eclipse.jetty.server.handler.ErrorHandler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||
{
|
||||
String method = request.getMethod();
|
||||
if(!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST))
|
||||
|
@ -145,7 +146,7 @@ public class ErrorPageErrorHandler extends ErrorHandler
|
|||
}
|
||||
}
|
||||
|
||||
super.handle(target, request, response);
|
||||
super.handle(target, baseRequest, request, response);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -216,8 +216,8 @@ public class Invoker extends HttpServlet
|
|||
|
||||
if (holder!=null)
|
||||
{
|
||||
final Request base_request=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
holder.handle(base_request,
|
||||
final Request baseRequest=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
holder.handle(baseRequest,
|
||||
new InvokedRequest(request,included,servlet,servlet_path,path_info),
|
||||
response);
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.UserIdentity;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ScopedHandler;
|
||||
import org.eclipse.jetty.util.LazyList;
|
||||
import org.eclipse.jetty.util.MultiException;
|
||||
import org.eclipse.jetty.util.MultiMap;
|
||||
|
@ -74,7 +75,7 @@ import org.eclipse.jetty.util.log.Log;
|
|||
* @see org.eclipse.jetty.webapp.WebAppContext
|
||||
*
|
||||
*/
|
||||
public class ServletHandler extends AbstractHandler
|
||||
public class ServletHandler extends ScopedHandler
|
||||
{
|
||||
/* ------------------------------------------------------------ */
|
||||
public static final String __DEFAULT_SERVLET="default";
|
||||
|
@ -299,27 +300,18 @@ public class ServletHandler extends AbstractHandler
|
|||
{
|
||||
return (ServletHolder)_servletNameMap.get(name);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.jetty.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request,HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
@Override
|
||||
public void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (!isStarted())
|
||||
return;
|
||||
|
||||
// Get the base requests
|
||||
final Request base_request=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
final String old_servlet_path=base_request.getServletPath();
|
||||
final String old_path_info=base_request.getPathInfo();
|
||||
final String old_servlet_path=baseRequest.getServletPath();
|
||||
final String old_path_info=baseRequest.getPathInfo();
|
||||
|
||||
DispatcherType type = base_request.getDispatcherType();
|
||||
Object request_listeners=null;
|
||||
ServletRequestEvent request_event=null;
|
||||
DispatcherType type = baseRequest.getDispatcherType();
|
||||
|
||||
ServletHolder servlet_holder=null;
|
||||
FilterChain chain=null;
|
||||
UserIdentity.Scope old_scope=null;
|
||||
|
||||
// find the servlet
|
||||
|
@ -339,38 +331,81 @@ public class ServletHandler extends AbstractHandler
|
|||
|
||||
if (DispatcherType.INCLUDE.equals(type))
|
||||
{
|
||||
base_request.setAttribute(Dispatcher.INCLUDE_SERVLET_PATH,servlet_path);
|
||||
base_request.setAttribute(Dispatcher.INCLUDE_PATH_INFO, path_info);
|
||||
baseRequest.setAttribute(Dispatcher.INCLUDE_SERVLET_PATH,servlet_path);
|
||||
baseRequest.setAttribute(Dispatcher.INCLUDE_PATH_INFO, path_info);
|
||||
}
|
||||
else
|
||||
{
|
||||
base_request.setServletPath(servlet_path);
|
||||
base_request.setPathInfo(path_info);
|
||||
baseRequest.setServletPath(servlet_path);
|
||||
baseRequest.setPathInfo(path_info);
|
||||
}
|
||||
|
||||
if (servlet_holder!=null && _filterMappings!=null && _filterMappings.length>0)
|
||||
chain=getFilterChain(base_request, target, servlet_holder);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// look for a servlet by name!
|
||||
servlet_holder=(ServletHolder)_servletNameMap.get(target);
|
||||
}
|
||||
|
||||
Log.debug("servlet holder=",servlet_holder);
|
||||
|
||||
try
|
||||
{
|
||||
// Do the filter/handling thang
|
||||
if (servlet_holder!=null)
|
||||
{
|
||||
old_scope=baseRequest.getUserIdentityScope();
|
||||
baseRequest.setUserIdentityScope(servlet_holder);
|
||||
|
||||
nextScope(target,baseRequest,request, response);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (old_scope!=null)
|
||||
baseRequest.setUserIdentityScope(old_scope);
|
||||
|
||||
if (!(DispatcherType.INCLUDE.equals(type)))
|
||||
{
|
||||
baseRequest.setServletPath(old_servlet_path);
|
||||
baseRequest.setPathInfo(old_path_info);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.jetty.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
|
||||
*/
|
||||
public void doHandle(String target, Request baseRequest,HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
DispatcherType type = baseRequest.getDispatcherType();
|
||||
|
||||
ServletHolder servlet_holder=(ServletHolder) baseRequest.getUserIdentityScope();
|
||||
FilterChain chain=null;
|
||||
|
||||
// find the servlet
|
||||
if (target.startsWith("/"))
|
||||
{
|
||||
if (servlet_holder!=null && _filterMappings!=null && _filterMappings.length>0)
|
||||
chain=getFilterChain(baseRequest, target, servlet_holder);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (servlet_holder!=null)
|
||||
{
|
||||
if (_filterMappings!=null && _filterMappings.length>0)
|
||||
{
|
||||
chain=getFilterChain(base_request, null,servlet_holder);
|
||||
chain=getFilterChain(baseRequest, null,servlet_holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Log.isDebugEnabled())
|
||||
{
|
||||
Log.debug("chain="+chain);
|
||||
Log.debug("servlet holder="+servlet_holder);
|
||||
}
|
||||
|
||||
Log.debug("chain=",chain);
|
||||
|
||||
try
|
||||
{
|
||||
// Do the filter/handling thang
|
||||
|
@ -380,28 +415,12 @@ public class ServletHandler extends AbstractHandler
|
|||
}
|
||||
else
|
||||
{
|
||||
old_scope=base_request.getUserIdentityScope();
|
||||
base_request.setUserIdentityScope(servlet_holder);
|
||||
|
||||
// Handle context listeners
|
||||
request_listeners = base_request.takeRequestListeners();
|
||||
if (request_listeners!=null)
|
||||
{
|
||||
request_event = new ServletRequestEvent(getServletContext(),request);
|
||||
final int s=LazyList.size(request_listeners);
|
||||
for(int i=0;i<s;i++)
|
||||
{
|
||||
final ServletRequestListener listener = (ServletRequestListener)LazyList.get(request_listeners,i);
|
||||
listener.requestInitialized(request_event);
|
||||
}
|
||||
}
|
||||
|
||||
base_request.setHandled(true);
|
||||
baseRequest.setHandled(true);
|
||||
|
||||
if (chain!=null)
|
||||
chain.doFilter(request, response);
|
||||
else
|
||||
servlet_holder.handle(base_request,request,response);
|
||||
servlet_holder.handle(baseRequest,request,response);
|
||||
}
|
||||
}
|
||||
catch(RetryRequest e)
|
||||
|
@ -424,7 +443,6 @@ public class ServletHandler extends AbstractHandler
|
|||
throw (ServletException)e;
|
||||
}
|
||||
|
||||
|
||||
// unwrap cause
|
||||
Throwable th=e;
|
||||
if (th instanceof UnavailableException)
|
||||
|
@ -442,7 +460,7 @@ public class ServletHandler extends AbstractHandler
|
|||
// handle or log exception
|
||||
if (th instanceof RetryRequest)
|
||||
{
|
||||
base_request.setHandled(false);
|
||||
baseRequest.setHandled(false);
|
||||
throw (RetryRequest)th;
|
||||
}
|
||||
else if (th instanceof HttpException)
|
||||
|
@ -499,26 +517,6 @@ public class ServletHandler extends AbstractHandler
|
|||
else
|
||||
if(Log.isDebugEnabled())Log.debug("Response already committed for handling ",e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (request_listeners!=null)
|
||||
{
|
||||
for(int i=LazyList.size(request_listeners);i-->0;)
|
||||
{
|
||||
final ServletRequestListener listener = (ServletRequestListener)LazyList.get(request_listeners,i);
|
||||
listener.requestDestroyed(request_event);
|
||||
}
|
||||
}
|
||||
|
||||
if (old_scope!=null)
|
||||
base_request.setUserIdentityScope(old_scope);
|
||||
|
||||
if (!(DispatcherType.INCLUDE.equals(type)))
|
||||
{
|
||||
base_request.setServletPath(old_servlet_path);
|
||||
base_request.setPathInfo(old_path_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1173,18 +1171,18 @@ public class ServletHandler extends AbstractHandler
|
|||
filter.doFilter(request, response, _next);
|
||||
else
|
||||
{
|
||||
final Request base_request=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
final boolean suspendable=base_request.isAsyncSupported();
|
||||
final Request baseRequest=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
final boolean suspendable=baseRequest.isAsyncSupported();
|
||||
if (suspendable)
|
||||
{
|
||||
try
|
||||
{
|
||||
base_request.setAsyncSupported(false);
|
||||
baseRequest.setAsyncSupported(false);
|
||||
filter.doFilter(request, response, _next);
|
||||
}
|
||||
finally
|
||||
{
|
||||
base_request.setAsyncSupported(true);
|
||||
baseRequest.setAsyncSupported(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1198,8 +1196,8 @@ public class ServletHandler extends AbstractHandler
|
|||
{
|
||||
if (Log.isDebugEnabled())
|
||||
Log.debug("call servlet " + _servletHolder);
|
||||
final Request base_request=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
_servletHolder.handle(base_request,request, response);
|
||||
final Request baseRequest=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
|
||||
_servletHolder.handle(baseRequest,request, response);
|
||||
}
|
||||
else // Not found
|
||||
notFound((HttpServletRequest)request, (HttpServletResponse)response);
|
||||
|
@ -1404,5 +1402,6 @@ public class ServletHandler extends AbstractHandler
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -211,12 +211,12 @@ public class QoSFilter implements Filter
|
|||
*/
|
||||
protected int getPriority(ServletRequest request)
|
||||
{
|
||||
HttpServletRequest base_request = (HttpServletRequest)request;
|
||||
if (base_request.getUserPrincipal() != null )
|
||||
HttpServletRequest baseRequest = (HttpServletRequest)request;
|
||||
if (baseRequest.getUserPrincipal() != null )
|
||||
return 2;
|
||||
else
|
||||
{
|
||||
HttpSession session = base_request.getSession(false);
|
||||
HttpSession session = baseRequest.getSession(false);
|
||||
if (session!=null && !session.isNew())
|
||||
return 1;
|
||||
else
|
||||
|
|
|
@ -112,9 +112,8 @@ public class WebAppContext extends ServletContextHandler
|
|||
private String _extraClasspath;
|
||||
private Throwable _unavailableException;
|
||||
|
||||
private transient Map _resourceAliases;
|
||||
private transient boolean _ownClassLoader=false;
|
||||
private transient boolean _unavailable;
|
||||
private Map _resourceAliases;
|
||||
private boolean _ownClassLoader=false;
|
||||
|
||||
public static ContextHandler getCurrentWebAppContext()
|
||||
{
|
||||
|
@ -286,21 +285,6 @@ public class WebAppContext extends ServletContextHandler
|
|||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.server.handler.ContextHandler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
if (_unavailable)
|
||||
{
|
||||
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
else
|
||||
super.handle(target, request, response);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.thread.AbstractLifeCycle#doStart()
|
||||
|
@ -357,7 +341,7 @@ public class WebAppContext extends ServletContextHandler
|
|||
//start up of the webapp context failed, make sure it is not started
|
||||
Log.warn("Failed startup of context "+this, e);
|
||||
_unavailableException=e;
|
||||
_unavailable = true;
|
||||
setAvailable(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -412,8 +396,8 @@ public class WebAppContext extends ServletContextHandler
|
|||
{
|
||||
if (_ownClassLoader)
|
||||
setClassLoader(null);
|
||||
|
||||
_unavailable = false;
|
||||
|
||||
setAvailable(true);
|
||||
_unavailableException=null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue