From 9a4e5f3301aad09659b8d281b5c7d187aaa847f5 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 26 Nov 2012 16:56:39 +1100 Subject: [PATCH] jetty-9 Added proxy test webapp. Refined no servlet context handling --- .../jetty/ant/WebApplicationProxyImpl.java | 3 +- .../bindings/GlobalWebappConfigBinding.java | 8 + .../deploy/providers/WebAppProvider.java | 7 +- jetty-distribution/pom.xml | 150 +++--- .../main/resources/webapps/ROOT/index.html | 1 + .../src/main/resources/webapps/javadoc.xml | 19 - .../src/main/config/etc/jetty-proxy.xml | 25 +- .../jetty/server/handler/ContextHandler.java | 450 +++++++++++------- .../eclipse/jetty/servlet/FilterHolder.java | 6 +- .../org/eclipse/jetty/servlet/Holder.java | 4 +- .../eclipse/jetty/servlet/ServletHandler.java | 20 +- .../eclipse/jetty/servlet/ServletHolder.java | 13 +- .../jetty/servlets/AbstractDoSFilterTest.java | 7 +- .../servlets/CloseableDoSFilterTest.java | 1 + tests/test-webapps/pom.xml | 1 + .../src/main/webapp/index.html | 1 - .../java/org/eclipse/jetty/TestServer.java | 2 - .../test-proxy-webapp/jetty-chat.jmx | 318 +++++++++++++ tests/test-webapps/test-proxy-webapp/pom.xml | 237 +++++++++ .../src/main/webapp/WEB-INF/jetty-web.xml | 6 + .../src/main/webapp/WEB-INF/web.xml | 32 ++ .../jetty/TestTransparentProxyServer.java | 142 ++++++ 22 files changed, 1146 insertions(+), 307 deletions(-) delete mode 100644 jetty-distribution/src/main/resources/webapps/javadoc.xml create mode 100644 tests/test-webapps/test-proxy-webapp/jetty-chat.jmx create mode 100644 tests/test-webapps/test-proxy-webapp/pom.xml create mode 100644 tests/test-webapps/test-proxy-webapp/src/main/webapp/WEB-INF/jetty-web.xml create mode 100644 tests/test-webapps/test-proxy-webapp/src/main/webapp/WEB-INF/web.xml create mode 100644 tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/TestTransparentProxyServer.java diff --git a/jetty-ant/src/main/java/org/eclipse/jetty/ant/WebApplicationProxyImpl.java b/jetty-ant/src/main/java/org/eclipse/jetty/ant/WebApplicationProxyImpl.java index 22fa07d0ff2..dc29b1fcfb2 100644 --- a/jetty-ant/src/main/java/org/eclipse/jetty/ant/WebApplicationProxyImpl.java +++ b/jetty-ant/src/main/java/org/eclipse/jetty/ant/WebApplicationProxyImpl.java @@ -27,6 +27,7 @@ import java.net.URLClassLoader; import java.util.Iterator; import java.util.List; import javax.servlet.Servlet; +import javax.servlet.ServletContext; import org.apache.tools.ant.AntClassLoader; import org.eclipse.jetty.annotations.AnnotationConfiguration; @@ -141,7 +142,7 @@ public class WebApplicationProxyImpl implements WebApplicationProxy { //super.initJspServlet(); - ContextHandler ch = ((ContextHandler.Context)getServletHandler().getServletContext()).getContextHandler(); + ContextHandler ch = ContextHandler.getContextHandler(getServletHandler().getServletContext()); /* Set the webapp's classpath for Jasper */ ch.setAttribute("org.apache.catalina.jsp_classpath", ch.getClassPath()); diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java index 416d4ec1216..ef9179ce449 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.deploy.bindings; +import java.io.File; + import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.AppLifeCycle; import org.eclipse.jetty.deploy.graph.Node; @@ -92,6 +94,12 @@ public class GlobalWebappConfigBinding implements AppLifeCycle.Binding { XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream()); + Resource resource = Resource.newResource(app.getOriginId()); + File file = resource.getFile(); + jettyXmlConfig.getIdMap().put("Server",app.getDeploymentManager().getServer()); + jettyXmlConfig.getProperties().put("jetty.webapp",file.getCanonicalPath()); + jettyXmlConfig.getProperties().put("jetty.webapps",file.getParentFile().getCanonicalPath()); + jettyXmlConfig.configure(context); } else diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java index 8b301d8035d..a2b5bfeb487 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java @@ -27,6 +27,7 @@ import java.util.Locale; import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.ConfigurationManager; import org.eclipse.jetty.deploy.util.FileID; +import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.annotation.ManagedAttribute; @@ -57,7 +58,8 @@ import org.eclipse.jetty.xml.XmlConfiguration; *
  • If a WAR file and a matching XML exist (eg foo.war and foo.xml) then the WAR is assumed to * be configured by the XML and only the XML is deployed. * - * + *

    For XML configured contexts, the ID map will contain a reference to the {@link Server} instance called "Server" and + * properties for the webapp file as "jetty.webapp" and directory as "jetty.webapps". */ @ManagedObject("Provider for start-up deployement of webapps based on presence in directory") public class WebAppProvider extends ScanningAppProvider @@ -267,6 +269,9 @@ public class WebAppProvider extends ScanningAppProvider XmlConfiguration xmlc = new XmlConfiguration(resource.getURL()); xmlc.getIdMap().put("Server",getDeploymentManager().getServer()); + xmlc.getProperties().put("jetty.webapp",file.getCanonicalPath()); + xmlc.getProperties().put("jetty.webapps",file.getParentFile().getCanonicalPath()); + if (getConfigurationManager() != null) xmlc.getProperties().putAll(getConfigurationManager().getProperties()); return (ContextHandler)xmlc.configure(); diff --git a/jetty-distribution/pom.xml b/jetty-distribution/pom.xml index 99c199d06e5..314cc8a1139 100644 --- a/jetty-distribution/pom.xml +++ b/jetty-distribution/pom.xml @@ -102,6 +102,16 @@ ${assembly-directory}/webapps test.war + + org.eclipse.jetty + test-proxy-webapp + ${project.version} + war + true + ** + ${assembly-directory}/webapps + javadoc-proxy.war + org.eclipse.jetty.example-async-rest example-async-rest-webapp @@ -343,6 +353,12 @@ war ${project.version} + + org.eclipse.jetty + test-proxy-webapp + war + ${project.version} + org.eclipse.jetty jetty-jmx @@ -376,6 +392,12 @@ ${project.version} + + org.eclipse.jetty + jetty-proxy + ${project.version} + + org.eclipse.jetty jetty-jaas @@ -393,6 +415,38 @@ jetty-rewrite ${project.version} + + + org.eclipse.jetty.spdy + spdy-core + ${project.version} + + + + org.eclipse.jetty.spdy + spdy-server + ${project.version} + + + + org.eclipse.jetty.spdy + spdy-http-server + ${project.version} + + + + org.eclipse.jetty.spdy + spdy-example-webapp + ${project.version} + war + + + + org.eclipse.jetty.example-async-rest + example-async-rest-webapp + ${project.version} + war + - - - - JDK7-plus-modules - - [1.7,) - - - - - maven-dependency-plugin - - - copy-lib-spdy-deps - process-resources - - copy-dependencies - - - org.eclipse.jetty.spdy - jar - ${assembly-directory}/lib/spdy - - - - - unpack-spdy - process-resources - - unpack-dependencies - - - org.eclipse.jetty.spdy - config - false - META-INF/** - ${assembly-directory} - - - - - - - - - org.eclipse.jetty.spdy - spdy-core - ${project.version} - - - org.eclipse.jetty.spdy - spdy-server - ${project.version} - - - org.eclipse.jetty.spdy - spdy-http-server - ${project.version} - - - org.eclipse.jetty.spdy - spdy-example-webapp - ${project.version} - war - - - org.eclipse.jetty.example-async-rest - example-async-rest-webapp - ${project.version} - war - - - - diff --git a/jetty-distribution/src/main/resources/webapps/ROOT/index.html b/jetty-distribution/src/main/resources/webapps/ROOT/index.html index 6dd73af75d6..4c925459377 100644 --- a/jetty-distribution/src/main/resources/webapps/ROOT/index.html +++ b/jetty-distribution/src/main/resources/webapps/ROOT/index.html @@ -29,6 +29,7 @@ The project is 100% Open Sour

    diff --git a/jetty-distribution/src/main/resources/webapps/javadoc.xml b/jetty-distribution/src/main/resources/webapps/javadoc.xml deleted file mode 100644 index 71567efd934..00000000000 --- a/jetty-distribution/src/main/resources/webapps/javadoc.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - /javadoc - /javadoc/ - - - - - index.html - - - max-age=3600,public - - - - diff --git a/jetty-proxy/src/main/config/etc/jetty-proxy.xml b/jetty-proxy/src/main/config/etc/jetty-proxy.xml index 15659c1c406..b5729ecdde0 100644 --- a/jetty-proxy/src/main/config/etc/jetty-proxy.xml +++ b/jetty-proxy/src/main/config/etc/jetty-proxy.xml @@ -1,10 +1,10 @@ - - - - + + + + @@ -17,7 +17,7 @@ - + 300000 @@ -26,25 +26,22 @@ - + - org.eclipse.jetty.servlets.ProxyServlet + org.eclipse.jetty.proxy.ProxyServlet / + + maxThreads + 128 + - - - maxThreads - 128 - - - true true true diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index e0ad4f216ab..85be23f4440 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -100,7 +100,13 @@ import org.eclipse.jetty.util.resource.Resource; @ManagedObject("URI Context") public class ContextHandler extends ScopedHandler implements Attributes, Graceful { + public static int SERVLET_MAJOR_VERSION=3; + public static int SERVLET_MINOR_VERSION=0; + + final private static String __unimplmented="Unimplemented - use org.eclipse.jetty.servlet.ServletContextHandler"; + + private static final Logger LOG = Log.getLogger(ContextHandler.class); private static final ThreadLocal __context = new ThreadLocal(); @@ -123,10 +129,20 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu return __context.get(); } + /* ------------------------------------------------------------ */ + public static ContextHandler getContextHandler(ServletContext context) + { + if(context instanceof ContextHandler.Context) + return ((ContextHandler.Context)context).getContextHandler(); + Context c= getCurrentContext(); + if (c!=null) + return c.getContextHandler(); + return null; + } + + protected Context _scontext; - private final AttributesMap _attributes; - private final AttributesMap _contextAttributes; private final Map _initParams; private ClassLoader _classLoader; private String _contextPath = "/"; @@ -168,7 +184,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu super(); _scontext = new Context(); _attributes = new AttributesMap(); - _contextAttributes = new AttributesMap(); _initParams = new HashMap(); } @@ -181,7 +196,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu super(); _scontext = context; _attributes = new AttributesMap(); - _contextAttributes = new AttributesMap(); _initParams = new HashMap(); } @@ -217,7 +231,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu Collections.singletonList(new ClassLoaderDump(getClassLoader())), _initParams.entrySet(), _attributes.getAttributeEntrySet(), - _contextAttributes.getAttributeEntrySet()); + _scontext.getAttributeEntrySet()); } /* ------------------------------------------------------------ */ @@ -825,7 +839,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu current_thread.setContextClassLoader(old_classloader); } - _contextAttributes.clearAttributes(); + _scontext.clearAttributes(); } /* ------------------------------------------------------------ */ @@ -1652,10 +1666,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu * * */ - public class Context implements ServletContext + public class Context extends NoContext { - protected int _majorVersion = 3; - protected int _minorVersion = 0; protected boolean _enabled = true; //whether or not the dynamic API is enabled for callers /* ------------------------------------------------------------ */ @@ -1755,17 +1767,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu return null; } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletContext#getMajorVersion() - */ - @Override - public int getMajorVersion() - { - return 3; - } - - /* ------------------------------------------------------------ */ /* * @see javax.servlet.ServletContext#getMimeType(java.lang.String) @@ -1777,27 +1778,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu return null; return _mimeTypes.getMimeByExtension(file); } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletContext#getMinorVersion() - */ - @Override - public int getMinorVersion() - { - return 0; - } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String) - */ - @Override - public RequestDispatcher getNamedDispatcher(String name) - { - return null; - } - + /* ------------------------------------------------------------ */ /* * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String) @@ -1909,51 +1890,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu return ContextHandler.this.getResourcePaths(path); } - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletContext#getServerInfo() - */ - @Override - public String getServerInfo() - { - return "jetty/" + Server.getVersion(); - } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletContext#getServlet(java.lang.String) - */ - @Override - @Deprecated - public Servlet getServlet(String name) throws ServletException - { - return null; - } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletContext#getServletNames() - */ - @SuppressWarnings("unchecked") - @Override - @Deprecated - public Enumeration getServletNames() - { - return Collections.enumeration(Collections.EMPTY_LIST); - } - - /* ------------------------------------------------------------ */ - /* - * @see javax.servlet.ServletContext#getServlets() - */ - @SuppressWarnings("unchecked") - @Override - @Deprecated - public Enumeration getServlets() - { - return Collections.enumeration(Collections.EMPTY_LIST); - } - /* ------------------------------------------------------------ */ /* * @see javax.servlet.ServletContext#log(java.lang.Exception, java.lang.String) @@ -2013,8 +1949,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu public synchronized Object getAttribute(String name) { Object o = ContextHandler.this.getAttribute(name); - if (o == null && _contextAttributes != null) - o = _contextAttributes.getAttribute(name); + if (o == null) + o = super.getAttribute(name); return o; } @@ -2026,13 +1962,10 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu public synchronized Enumeration getAttributeNames() { HashSet set = new HashSet(); - if (_contextAttributes != null) - { - Enumeration e = _contextAttributes.getAttributeNames(); - while (e.hasMoreElements()) - set.add(e.nextElement()); - } - Enumeration e = _attributes.getAttributeNames(); + Enumeration e = super.getAttributeNames(); + while (e.hasMoreElements()) + set.add(e.nextElement()); + e = _attributes.getAttributeNames(); while (e.hasMoreElements()) set.add(e.nextElement()); @@ -2047,12 +1980,12 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu public synchronized void setAttribute(String name, Object value) { checkManagedAttribute(name,value); - Object old_value = _contextAttributes.getAttribute(name); + Object old_value = super.getAttribute(name); if (value == null) - _contextAttributes.removeAttribute(name); + super.removeAttribute(name); else - _contextAttributes.setAttribute(name,value); + super.setAttribute(name,value); if (!_contextAttributeListeners.isEmpty()) { @@ -2079,15 +2012,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu { checkManagedAttribute(name,null); - if (_contextAttributes == null) - { - // Set it on the handler - _attributes.removeAttribute(name); - return; - } - - Object old_value = _contextAttributes.getAttribute(name); - _contextAttributes.removeAttribute(name); + Object old_value = super.getAttribute(name); + super.removeAttribute(name); if (old_value != null &&!_contextAttributeListeners.isEmpty()) { ServletContextAttributeEvent event = new ServletContextAttributeEvent(_scontext,name,old_value); @@ -2137,8 +2063,255 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu return true; } + @Override + public void addListener(String className) + { + if (!_enabled) + throw new UnsupportedOperationException(); + + try + { + Class clazz = _classLoader==null?Loader.loadClass(ContextHandler.class,className):_classLoader.loadClass(className); + addListener(clazz); + } + catch (ClassNotFoundException e) + { + throw new IllegalArgumentException(e); + } + } + + @Override + public void addListener(T t) + { + if (!_enabled) + throw new UnsupportedOperationException(); + ContextHandler.this.addEventListener(t); + } + + @Override + public void addListener(Class listenerClass) + { + if (!_enabled) + throw new UnsupportedOperationException(); + + try + { + EventListener e = createListener(listenerClass); + ContextHandler.this.addEventListener(e); + ContextHandler.this.addProgrammaticListener(e); + } + catch (ServletException e) + { + throw new IllegalArgumentException(e); + } + } + + @Override + public T createListener(Class clazz) throws ServletException + { + try + { + return clazz.newInstance(); + } + catch (InstantiationException e) + { + throw new ServletException(e); + } + catch (IllegalAccessException e) + { + throw new ServletException(e); + } + } + + @Override + public ClassLoader getClassLoader() + { + AccessController.checkPermission(new RuntimePermission("getClassLoader")); + return _classLoader; + } + + @Override + public JspConfigDescriptor getJspConfigDescriptor() + { + LOG.warn(__unimplmented); + return null; + } + + public void setJspConfigDescriptor(JspConfigDescriptor d) + { + + } + + @Override + public void declareRoles(String... roleNames) + { + if (!isStarting()) + throw new IllegalStateException (); + if (!_enabled) + throw new UnsupportedOperationException(); + } + + public void setEnabled(boolean enabled) + { + _enabled = enabled; + } + + public boolean isEnabled() + { + return _enabled; + } + } + + + public static class NoContext extends AttributesMap implements ServletContext + { + private int _effectiveMajorVersion = SERVLET_MAJOR_VERSION; + private int _effectiveMinorVersion = SERVLET_MINOR_VERSION; + /* ------------------------------------------------------------ */ - final private static String __unimplmented="Unimplemented - use org.eclipse.jetty.servlet.ServletContextHandler"; + public NoContext() + { + } + + @Override + public ServletContext getContext(String uripath) + { + return null; + } + + @Override + public int getMajorVersion() + { + return SERVLET_MAJOR_VERSION; + } + + @Override + public String getMimeType(String file) + { + return null; + } + + @Override + public int getMinorVersion() + { + return SERVLET_MINOR_VERSION; + } + + @Override + public RequestDispatcher getNamedDispatcher(String name) + { + return null; + } + + @Override + public RequestDispatcher getRequestDispatcher(String uriInContext) + { + return null; + } + + @Override + public String getRealPath(String path) + { + return null; + } + + @Override + public URL getResource(String path) throws MalformedURLException + { + return null; + } + + @Override + public InputStream getResourceAsStream(String path) + { + return null; + } + + @Override + public Set getResourcePaths(String path) + { + return null; + } + + @Override + public String getServerInfo() + { + return "jetty/" + Server.getVersion(); + } + + @Override + @Deprecated + public Servlet getServlet(String name) throws ServletException + { + return null; + } + + @SuppressWarnings("unchecked") + @Override + @Deprecated + public Enumeration getServletNames() + { + return Collections.enumeration(Collections.EMPTY_LIST); + } + + @SuppressWarnings("unchecked") + @Override + @Deprecated + public Enumeration getServlets() + { + return Collections.enumeration(Collections.EMPTY_LIST); + } + + @Override + public void log(Exception exception, String msg) + { + LOG.warn(msg,exception); + } + + @Override + public void log(String msg) + { + LOG.info(msg); + } + + @Override + public void log(String message, Throwable throwable) + { + LOG.warn(message,throwable); + } + + @Override + public String getInitParameter(String name) + { + return null; + } + + @SuppressWarnings("unchecked") + @Override + public Enumeration getInitParameterNames() + { + return Collections.enumeration(Collections.EMPTY_LIST); + } + + + @Override + public String getServletContextName() + { + return "No Context"; + } + + @Override + public String getContextPath() + { + return null; + } + + + @Override + public boolean setInitParameter(String name, String value) + { + return false; + } @Override public Dynamic addFilter(String filterName, Class filterClass) @@ -2254,44 +2427,19 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu @Override public void addListener(String className) { - if (!_enabled) - throw new UnsupportedOperationException(); - - try - { - Class clazz = _classLoader==null?Loader.loadClass(ContextHandler.class,className):_classLoader.loadClass(className); - addListener(clazz); - } - catch (ClassNotFoundException e) - { - throw new IllegalArgumentException(e); - } + LOG.warn(__unimplmented); } @Override public void addListener(T t) { - if (!_enabled) - throw new UnsupportedOperationException(); - ContextHandler.this.addEventListener(t); + LOG.warn(__unimplmented); } @Override public void addListener(Class listenerClass) { - if (!_enabled) - throw new UnsupportedOperationException(); - - try - { - EventListener e = createListener(listenerClass); - ContextHandler.this.addEventListener(e); - ContextHandler.this.addProgrammaticListener(e); - } - catch (ServletException e) - { - throw new IllegalArgumentException(e); - } + LOG.warn(__unimplmented); } @Override @@ -2315,29 +2463,29 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu public ClassLoader getClassLoader() { AccessController.checkPermission(new RuntimePermission("getClassLoader")); - return _classLoader; + return ContextHandler.class.getClassLoader(); } @Override public int getEffectiveMajorVersion() { - return _majorVersion; + return _effectiveMajorVersion; } @Override public int getEffectiveMinorVersion() { - return _minorVersion; + return _effectiveMinorVersion; } public void setEffectiveMajorVersion (int v) { - _majorVersion = v; + _effectiveMajorVersion = v; } public void setEffectiveMinorVersion (int v) { - _minorVersion = v; + _effectiveMinorVersion = v; } @Override @@ -2347,28 +2495,10 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu return null; } - public void setJspConfigDescriptor(JspConfigDescriptor d) - { - - } - @Override public void declareRoles(String... roleNames) { - if (!isStarting()) - throw new IllegalStateException (); - if (!_enabled) - throw new UnsupportedOperationException(); - } - - public void setEnabled(boolean enabled) - { - _enabled = enabled; - } - - public boolean isEnabled() - { - return _enabled; + LOG.warn(__unimplmented); } } } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java index bcc3b5c648a..6c0000d47ee 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java @@ -27,6 +27,7 @@ import javax.servlet.DispatcherType; import javax.servlet.Filter; import javax.servlet.FilterConfig; import javax.servlet.FilterRegistration; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import org.eclipse.jetty.util.TypeUtil; @@ -100,7 +101,10 @@ public class FilterHolder extends Holder { try { - _filter=((ServletContextHandler.Context)_servletHandler.getServletContext()).createFilter(getHeldClass()); + ServletContext context=_servletHandler.getServletContext(); + _filter=(context instanceof ServletContextHandler.Context) + ?((ServletContextHandler.Context)context).createFilter(getHeldClass()) + :getHeldClass().newInstance(); } catch (ServletException se) { diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java index d058c336a58..47a049255ae 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java @@ -265,8 +265,8 @@ public class Holder extends AbstractLifeCycle implements Dumpable { if (_servletHandler!=null) { - ContextHandler.Context context=(ContextHandler.Context)_servletHandler.getServletContext(); - if (context!=null && context.getContextHandler().isStarted()) + ServletContext context=_servletHandler.getServletContext(); + if ((context instanceof ContextHandler.Context) && ((ContextHandler.Context)context).getContextHandler().isStarted()) throw new IllegalStateException("Started"); } } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java index 1768e357547..f976002948e 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java @@ -19,10 +19,15 @@ package org.eclipse.jetty.servlet; import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; +import java.util.Enumeration; +import java.util.EventListener; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -34,15 +39,20 @@ import java.util.concurrent.ConcurrentMap; import javax.servlet.DispatcherType; import javax.servlet.Filter; import javax.servlet.FilterChain; +import javax.servlet.FilterRegistration; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; +import javax.servlet.ServletRegistration.Dynamic; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.ServletSecurityElement; +import javax.servlet.SessionCookieConfig; +import javax.servlet.SessionTrackingMode; import javax.servlet.UnavailableException; +import javax.servlet.descriptor.JspConfigDescriptor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -61,6 +71,7 @@ import org.eclipse.jetty.server.UserIdentity; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ScopedHandler; import org.eclipse.jetty.util.ArrayUtil; +import org.eclipse.jetty.util.AttributesMap; import org.eclipse.jetty.util.LazyList; import org.eclipse.jetty.util.MultiException; import org.eclipse.jetty.util.MultiMap; @@ -94,7 +105,7 @@ public class ServletHandler extends ScopedHandler /* ------------------------------------------------------------ */ private ServletContextHandler _contextHandler; - private ContextHandler.Context _servletContext; + private ServletContext _servletContext; private FilterHolder[] _filters=new FilterHolder[0]; private FilterMapping[] _filterMappings; private boolean _filterChainsCached=true; @@ -128,8 +139,9 @@ public class ServletHandler extends ScopedHandler protected synchronized void doStart() throws Exception { - _servletContext=ContextHandler.getCurrentContext(); - _contextHandler=(ServletContextHandler)(_servletContext==null?null:_servletContext.getContextHandler()); + ContextHandler.Context context=ContextHandler.getCurrentContext(); + _servletContext=context==null?new ContextHandler.NoContext():context; + _contextHandler=(ServletContextHandler)(context==null?null:context.getContextHandler()); if (_contextHandler!=null) { @@ -1464,4 +1476,6 @@ public class ServletHandler extends ScopedHandler if (_contextHandler!=null) _contextHandler.destroyFilter(filter); } + + } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java index 538821c1027..c46c0ebf35b 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java @@ -551,8 +551,8 @@ public class ServletHolder extends Holder implements UserIdentity.Scope */ protected void initJspServlet () throws Exception { - ContextHandler ch = ((ContextHandler.Context)getServletHandler().getServletContext()).getContextHandler(); - + ContextHandler ch = ContextHandler.getContextHandler(getServletHandler().getServletContext()); + /* Set the webapp's classpath for Jasper */ ch.setAttribute("org.apache.catalina.jsp_classpath", ch.getClassPath()); @@ -584,7 +584,8 @@ public class ServletHolder extends Holder implements UserIdentity.Scope { //Register a listener to delete tmp files that are created as a result of this //servlet calling Request.getPart() or Request.getParts() - ContextHandler ch = ((ContextHandler.Context)getServletHandler().getServletContext()).getContextHandler(); + + ContextHandler ch = ContextHandler.getContextHandler(getServletHandler().getServletContext()); ch.addEventListener(new Request.MultiPartCleanerListener()); } } @@ -945,9 +946,9 @@ public class ServletHolder extends Holder implements UserIdentity.Scope try { ServletContext ctx = getServletHandler().getServletContext(); - if (ctx==null) - return getHeldClass().newInstance(); - return ((ServletContextHandler.Context)ctx).createServlet(getHeldClass()); + if (ctx instanceof ServletContextHandler.Context) + return ((ServletContextHandler.Context)ctx).createServlet(getHeldClass()); + return getHeldClass().newInstance(); } catch (ServletException se) { diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java index 54945d56d22..554d2f74594 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java @@ -33,13 +33,17 @@ import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletTester; import org.eclipse.jetty.util.IO; +import org.hamcrest.Matchers; import org.junit.After; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import static org.hamcrest.Matchers.greaterThan; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** @@ -321,7 +325,8 @@ public abstract class AbstractDoSFilterTest // was expired, and stopped before reaching the end of the requests int responseLines = count(responses, "Line:"); assertTrue(responses.contains("DoSFilter: timeout")); - assertTrue(responseLines > 0 && responseLines < numRequests); + assertThat(responseLines,greaterThan(0)); + assertThat(responseLines,Matchers.lessThan(numRequests)); } public static class TestServlet extends HttpServlet implements Servlet diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CloseableDoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CloseableDoSFilterTest.java index 4203e6a91d7..6c4a72ac262 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CloseableDoSFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CloseableDoSFilterTest.java @@ -38,6 +38,7 @@ public class CloseableDoSFilterTest extends AbstractDoSFilterTest public static class CloseableDoSFilter2 extends CloseableDoSFilter { + @Override public void closeConnection(HttpServletRequest request, HttpServletResponse response, Thread thread) { try diff --git a/tests/test-webapps/pom.xml b/tests/test-webapps/pom.xml index 0e1e831f29f..c7541fb9f65 100644 --- a/tests/test-webapps/pom.xml +++ b/tests/test-webapps/pom.xml @@ -41,6 +41,7 @@ test-jetty-webapp + test-proxy-webapp test-webapp-rfc2616 test-mock-resources test-servlet-spec diff --git a/tests/test-webapps/test-jetty-webapp/src/main/webapp/index.html b/tests/test-webapps/test-jetty-webapp/src/main/webapp/index.html index 52b596ddea3..370c1e9c3b0 100644 --- a/tests/test-webapps/test-jetty-webapp/src/main/webapp/index.html +++ b/tests/test-webapps/test-jetty-webapp/src/main/webapp/index.html @@ -34,7 +34,6 @@ This is a test context that serves:
  • Dispatcher Servlet
  • Request Rewrite Servlet
  • JSP examples
  • -
  • Transparent Proxy (to javadoc @ eclipse.org)
  • Comet Chat: Long Polling, WebSocket
  • Authentication
  • diff --git a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java index 75f1580c663..607f0149122 100644 --- a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java +++ b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java @@ -150,7 +150,6 @@ public class TestServer // Setup context - HashLoginService login = new HashLoginService(); login.setName("Test Realm"); login.setConfig(jetty_root + "/test-jetty-webapp/src/main/config/etc/realm.properties"); @@ -166,7 +165,6 @@ public class TestServer WebAppContext webapp = new WebAppContext(); webapp.setParentLoaderPriority(true); - webapp.prependServerClass("-org.eclipse.jetty.websocket.server."); webapp.setResourceBase("./src/main/webapp"); webapp.setAttribute("testAttribute","testValue"); File sessiondir=File.createTempFile("sessions",null); diff --git a/tests/test-webapps/test-proxy-webapp/jetty-chat.jmx b/tests/test-webapps/test-proxy-webapp/jetty-chat.jmx new file mode 100644 index 00000000000..088b7e0c485 --- /dev/null +++ b/tests/test-webapps/test-proxy-webapp/jetty-chat.jmx @@ -0,0 +1,318 @@ + + + + + + + + false + false + + + + + 1165945030000 + + + 400 + false + + 1 + false + + 1165945030000 + continue + 10 + + + + + + = + 50 + rooms + + + = + + + + + + + + /test/chat/ + localhost + http + + + + 8080 + + + + true + + + + + + GET + true + + true + + + + + = + poll + true + ajax + false + + + = + poll + true + message + false + + + = + 0 + true + timeout + false + + + = + ${__javaScript(${__threadNum}%${rooms},room)} + true + room + false + + + + + + false + + + false + + + + + POST + true + + false + + + + + = + join + true + ajax + false + + + = + Elvis${__threadNum} + true + message + false + + + = + ${__javaScript(${__threadNum}%${rooms},room)} + true + room + false + + + + + + false + + + false + + + + -1 + true + + + + ${__Random(3,20,random)} + true + + + + + GET + true + + true + + + + + = + poll + true + ajax + false + + + = + poll + true + message + false + + + = + ${__Random(3000,10000,poll)} + true + timeout + false + + + = + ${__javaScript(${__threadNum}%${rooms},room)} + true + room + false + + + + + + false + + + false + + + + + + POST + true + + false + + + + + = + chat + true + ajax + false + + + = + Give me ${__Random(1,200,mars)} deep fried mars bars + true + message + false + + + = + ${__javaScript(${__threadNum}%${rooms},room)} + true + room + false + + + + + + false + + + false + + + + + + POST + true + + false + + + + + = + leave + true + ajax + false + + + = + Elvis${__threadNum} + true + message + false + + + = + ${__javaScript(${__threadNum}%${rooms},room)} + true + room + false + + + + + + false + + + false + + + + + + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + false + false + false + false + false + 0 + + saveConfig + + + false + + + + + diff --git a/tests/test-webapps/test-proxy-webapp/pom.xml b/tests/test-webapps/test-proxy-webapp/pom.xml new file mode 100644 index 00000000000..42bdebe3dc8 --- /dev/null +++ b/tests/test-webapps/test-proxy-webapp/pom.xml @@ -0,0 +1,237 @@ + + + + + org.eclipse.jetty.tests + test-webapps-parent + 9.0.0-SNAPSHOT + ../pom.xml + + 4.0.0 + org.eclipse.jetty + test-proxy-webapp + Test :: Jetty Proxy Webapp + war + + + + org.apache.maven.plugins + maven-surefire-plugin + + + test + test + + + + + **/WebAppTest.java + **/Test*.java + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + config + + + src/main/assembly/web-bundle.xml + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + + + + maven-war-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.apache.felix + maven-bundle-plugin + true + + + war + + + + + bundle-manifest + process-classes + + manifest + + + + org.eclipse.jetty.test-jetty-webapp + javax.servlet.jsp.*;version="2.2.0",javax.servlet.*;version="[2.6,3.0)",org.eclipse.jetty.*;version="9.0",* + !com.acme* + + / + + .,WEB-INF/classes + + + + + + + org.eclipse.jetty + jetty-maven-plugin + ${project.version} + + + org.eclipse.jetty + jetty-client + ${project.version} + + + + 8087 + foo + 1 + + + fooprop + 222 + + + + + /test + ${project.build.directory}/work + + + ${basedir}/target/sessions + + + + + + Test Realm + src/main/config/etc/realm.properties + + + + + + + + + + + org.eclipse.jetty + jetty-proxy + ${project.version} + + + org.eclipse.jetty.orbit + javax.servlet + provided + + + org.eclipse.jetty + jetty-webapp + ${project.version} + test + + + org.eclipse.jetty + jetty-jmx + ${project.version} + test + + + org.eclipse.jetty.toolchain + jetty-test-helper + test + + + org.eclipse.jetty + jetty-server + ${project.version} + provided + + + javax.servlet.jsp + jsp-api + 2.1 + provided + + + org.eclipse.jetty.spdy + spdy-http-server + ${project.version} + test + + + javax.servlet + jstl + 1.2 + provided + + + diff --git a/tests/test-webapps/test-proxy-webapp/src/main/webapp/WEB-INF/jetty-web.xml b/tests/test-webapps/test-proxy-webapp/src/main/webapp/WEB-INF/jetty-web.xml new file mode 100644 index 00000000000..e4b4f3cadf6 --- /dev/null +++ b/tests/test-webapps/test-proxy-webapp/src/main/webapp/WEB-INF/jetty-web.xml @@ -0,0 +1,6 @@ + + + + + /javadoc + diff --git a/tests/test-webapps/test-proxy-webapp/src/main/webapp/WEB-INF/web.xml b/tests/test-webapps/test-proxy-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000000..410591f567d --- /dev/null +++ b/tests/test-webapps/test-proxy-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,32 @@ + + + + Transparent Proxy WebApp + + + + TransparentProxy + org.eclipse.jetty.proxy.ProxyServlet$Transparent + + proxyTohttp://download.eclipse.org/jetty/stable-9/apidocs + + + hostHeaderdownload.eclipse.org + + 1 + true + + + + TransparentProxy + / + + + + + diff --git a/tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/TestTransparentProxyServer.java b/tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/TestTransparentProxyServer.java new file mode 100644 index 00000000000..4fda0d70a82 --- /dev/null +++ b/tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/TestTransparentProxyServer.java @@ -0,0 +1,142 @@ +// +// ======================================================================== +// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty; + +import java.lang.management.ManagementFactory; + +import org.eclipse.jetty.jmx.MBeanContainer; +import org.eclipse.jetty.server.ForwardedRequestCustomizer; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; +import org.eclipse.jetty.server.SecureRequestCustomizer; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.SslConnectionFactory; +import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.server.handler.ContextHandlerCollection; +import org.eclipse.jetty.server.handler.DefaultHandler; +import org.eclipse.jetty.server.handler.HandlerCollection; +import org.eclipse.jetty.server.handler.ResourceHandler; +import org.eclipse.jetty.spdy.server.NPNServerConnectionFactory; +import org.eclipse.jetty.spdy.server.SPDYServerConnectionFactory; +import org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnectionFactory; +import org.eclipse.jetty.spdy.server.http.PushStrategy; +import org.eclipse.jetty.spdy.server.http.ReferrerPushStrategy; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.StdErrLog; +import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.util.thread.QueuedThreadPool; +import org.eclipse.jetty.webapp.WebAppContext; +import org.junit.Ignore; + +@Ignore("Not a test case") +public class TestTransparentProxyServer +{ + public static void main(String[] args) throws Exception + { + ((StdErrLog)Log.getLog()).setSource(false); + + String jetty_root = "../../.."; + + // Setup Threadpool + QueuedThreadPool threadPool = new QueuedThreadPool(); + threadPool.setMaxThreads(100); + + // Setup server + Server server = new Server(threadPool); + server.manage(threadPool); + server.setSendDateHeader(true); + + // Setup JMX + MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); + server.addBean(mbContainer); + server.addBean(Log.getLog()); + + + // Common HTTP configuration + HttpConfiguration config = new HttpConfiguration(); + config.setSecurePort(8443); + config.addCustomizer(new ForwardedRequestCustomizer()); + config.addCustomizer(new SecureRequestCustomizer()); + + + // Http Connector + HttpConnectionFactory http = new HttpConnectionFactory(config); + ServerConnector httpConnector = new ServerConnector(server,http); + httpConnector.setPort(8080); + httpConnector.setIdleTimeout(30000); + server.addConnector(httpConnector); + + + // SSL configurations + SslContextFactory sslContextFactory = new SslContextFactory(); + sslContextFactory.setKeyStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore"); + sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); + sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g"); + sslContextFactory.setTrustStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore"); + sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); + sslContextFactory.setExcludeCipherSuites( + "SSL_RSA_WITH_DES_CBC_SHA", + "SSL_DHE_RSA_WITH_DES_CBC_SHA", + "SSL_DHE_DSS_WITH_DES_CBC_SHA", + "SSL_RSA_EXPORT_WITH_RC4_40_MD5", + "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", + "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", + "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"); + + + // Spdy Connector + SPDYServerConnectionFactory.checkNPNAvailable(); + PushStrategy push = new ReferrerPushStrategy(); + HTTPSPDYServerConnectionFactory spdy2 = new HTTPSPDYServerConnectionFactory(2,config,push); + spdy2.setInputBufferSize(8192); + spdy2.setInitialWindowSize(32768); + HTTPSPDYServerConnectionFactory spdy3 = new HTTPSPDYServerConnectionFactory(3,config,push); + spdy2.setInputBufferSize(8192); + NPNServerConnectionFactory npn = new NPNServerConnectionFactory(spdy3.getProtocol(),spdy2.getProtocol(),http.getProtocol()); + npn.setDefaultProtocol(http.getProtocol()); + npn.setInputBufferSize(1024); + SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory,npn.getProtocol()); + ServerConnector spdyConnector = new ServerConnector(server,ssl,npn,spdy3,spdy2,http); + spdyConnector.setPort(8443); + spdyConnector.setIdleTimeout(15000); + server.addConnector(spdyConnector); + + // Handlers + HandlerCollection handlers = new HandlerCollection(); + ContextHandlerCollection contexts = new ContextHandlerCollection(); + handlers.setHandlers(new Handler[] + { contexts, new DefaultHandler() }); + + server.setHandler(handlers); + + // Setup proxy webapp + WebAppContext webapp = new WebAppContext(); + webapp.setResourceBase("src/main/webapp"); + contexts.addHandler(webapp); + + // start server + server.setStopAtShutdown(true); + server.setSendServerVersion(true); + server.start(); + server.join(); + } + +}