From dedc2b648dabf9884cc3290ca244ac9106611795 Mon Sep 17 00:00:00 2001 From: Hugues Malphettes Date: Tue, 10 May 2011 03:29:29 +0000 Subject: [PATCH] bug 336056 Ability to override the computation of the ContextHandler to deploy the DefaultServlet on equinox's HttpServiceServlet. git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@3104 7e9141cc-0065-0410-87d8-b60c137991c4 --- VERSION.txt | 1 + .../eclipse/jetty/servlet/DefaultServlet.java | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 468733deaa4..6b92548f6bf 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -19,6 +19,7 @@ jetty-7.4.1-SNAPSHOT + JETTY-1326 Invoker names not hashCode based + JETTY-1343 IllegalArgumentException for bad % encodings + JETTY-1347 Updated ServletHander javadoc + + 336056 Ability to override the computation of the ContextHandler to deploy the DefaultServlet on the HttpService jetty-7.4.0.v20110414 + 342504 Scanner Listener diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java index bc4dc3b742a..92befe7e30e 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java @@ -162,11 +162,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory throws UnavailableException { _servletContext=getServletContext(); - ContextHandler.Context scontext=ContextHandler.getCurrentContext(); - if (scontext==null) - _contextHandler=((ContextHandler.Context)_servletContext).getContextHandler(); - else - _contextHandler = ContextHandler.getCurrentContext().getContextHandler(); + _contextHandler = initContextHandler(_servletContext); _mimeTypes = _contextHandler.getMimeTypes(); @@ -284,6 +280,29 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory if (Log.isDebugEnabled()) Log.debug("resource base = "+_resourceBase); } + /** + * Compute the field _contextHandler.
+ * In the case where the DefaultServlet is deployed on the HttpService it is likely that + * this method needs to be overwritten to unwrap the ServletContext facade until we reach + * the original jetty's ContextHandler. + * @param servletContext The servletContext of this servlet. + * @return the jetty's ContextHandler for this servletContext. + */ + protected ContextHandler initContextHandler(ServletContext servletContext) + { + ContextHandler.Context scontext=ContextHandler.getCurrentContext(); + if (scontext==null) + { + if (servletContext instanceof ContextHandler.Context) + return ((ContextHandler.Context)servletContext).getContextHandler(); + else + throw new IllegalArgumentException("The servletContext " + servletContext + " " + + servletContext.getClass().getName() + " is not " + ContextHandler.Context.class.getName()); + } + else + return ContextHandler.getCurrentContext().getContextHandler(); + } + /* ------------------------------------------------------------ */ @Override public String getInitParameter(String name)