From 36836530528d9d02ebc4a5ff32094d7536ede24e Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 1 Nov 2012 20:20:13 +1100 Subject: [PATCH] 393303 use jetty-web.xml to explicitly add the jetty packages that need visability. This commit also sucked in some changes made to help with the documentation process (improving deployer configuration management --- .../src/main/config/etc/jetty-deploy.xml | 10 +++ ...va => PropertiesConfigurationManager.java} | 56 +++++++++++------ .../resources/binding-test-contexts-1.xml | 2 +- .../resources/jetty-deploymgr-contexts.xml | 2 +- .../jetty/webapp/ClasspathPattern.java | 46 ++++++++++++-- .../eclipse/jetty/webapp/WebAppContext.java | 61 +++++++++++++++++-- test-jetty-webapp/pom.xml | 2 + .../main/java/com/acme/DispatchServlet.java | 8 +-- .../src/main/java/com/acme/Dump.java | 18 +++--- .../src/main/java/com/acme/LoginServlet.java | 3 - .../java/com/acme/WebSocketChatServlet.java | 6 +- .../src/main/webapp/WEB-INF/jetty-web.xml | 2 + .../java/org/eclipse/jetty/TestServer.java | 2 +- .../src/test/resources/RFC2616Base.xml | 2 +- 14 files changed, 163 insertions(+), 57 deletions(-) rename jetty-deploy/src/main/java/org/eclipse/jetty/deploy/{FileConfigurationManager.java => PropertiesConfigurationManager.java} (54%) diff --git a/jetty-deploy/src/main/config/etc/jetty-deploy.xml b/jetty-deploy/src/main/config/etc/jetty-deploy.xml index 5316b500ddf..9b42604d6d3 100644 --- a/jetty-deploy/src/main/config/etc/jetty-deploy.xml +++ b/jetty-deploy/src/main/config/etc/jetty-deploy.xml @@ -43,6 +43,16 @@ /etc/webdefault.xml 1 true + + + + + + diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/FileConfigurationManager.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/PropertiesConfigurationManager.java similarity index 54% rename from jetty-deploy/src/main/java/org/eclipse/jetty/deploy/FileConfigurationManager.java rename to jetty-deploy/src/main/java/org/eclipse/jetty/deploy/PropertiesConfigurationManager.java index 076dafe93f6..8cb5c344e82 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/FileConfigurationManager.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/PropertiesConfigurationManager.java @@ -21,10 +21,15 @@ package org.eclipse.jetty.deploy; import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Properties; +import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.eclipse.jetty.util.annotation.ManagedObject; +import org.eclipse.jetty.util.annotation.ManagedOperation; +import org.eclipse.jetty.util.annotation.Name; import org.eclipse.jetty.util.resource.Resource; /** @@ -32,42 +37,55 @@ import org.eclipse.jetty.util.resource.Resource; * * Supplies properties defined in a file. */ -public class FileConfigurationManager implements ConfigurationManager +@ManagedObject("Configure deployed webapps via properties") +public class PropertiesConfigurationManager implements ConfigurationManager { - private Resource _file; - private Map _map = new HashMap(); + private String _properties; + private final Map _map = new HashMap(); - public FileConfigurationManager() + public PropertiesConfigurationManager(String properties) + { + } + + public PropertiesConfigurationManager() { } - public void setFile(String filename) throws MalformedURLException, IOException + @ManagedAttribute("A file or URL of properties") + public void setFile(String resource) throws MalformedURLException, IOException { - _file = Resource.newResource(filename); + _properties=resource; + _map.clear(); + loadProperties(_properties); } + public String getFile() + { + return _properties; + } + + @ManagedOperation("Set a property") + public void put(@Name("name")String name, @Name("value")String value) + { + _map.put(name,value); + } + /** * @see org.eclipse.jetty.deploy.ConfigurationManager#getProperties() */ + @Override public Map getProperties() { - try - { - loadProperties(); - return _map; - } - catch (Exception e) - { - throw new RuntimeException(e); - } + return new HashMap<>(_map); } - private void loadProperties() throws FileNotFoundException, IOException - { - if (_map.isEmpty() && _file!=null) + private void loadProperties(String resource) throws FileNotFoundException, IOException + { + Resource file=Resource.newResource(resource); + if (file!=null && file.exists()) { Properties properties = new Properties(); - properties.load(_file.getInputStream()); + properties.load(file.getInputStream()); for (Map.Entry entry : properties.entrySet()) _map.put(entry.getKey().toString(),String.valueOf(entry.getValue())); } diff --git a/jetty-deploy/src/test/resources/binding-test-contexts-1.xml b/jetty-deploy/src/test/resources/binding-test-contexts-1.xml index 1614056f430..37f5292ff2e 100644 --- a/jetty-deploy/src/test/resources/binding-test-contexts-1.xml +++ b/jetty-deploy/src/test/resources/binding-test-contexts-1.xml @@ -50,7 +50,7 @@ /webapps 1 - + /xml-configured-jetty.properties diff --git a/jetty-deploy/src/test/resources/jetty-deploymgr-contexts.xml b/jetty-deploy/src/test/resources/jetty-deploymgr-contexts.xml index acf69585ff5..ba38daef80d 100644 --- a/jetty-deploy/src/test/resources/jetty-deploymgr-contexts.xml +++ b/jetty-deploy/src/test/resources/jetty-deploymgr-contexts.xml @@ -17,7 +17,7 @@ /webapps 1 - + /xml-configured-jetty.properties diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java index 63ec5b4ca76..f402b3191c9 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java @@ -81,8 +81,6 @@ public class ClasspathPattern /* ------------------------------------------------------------ */ /** - * Initialize the matcher by parsing each classpath pattern in an array - * * @param patterns array of classpath patterns */ private void addPatterns(String[] patterns) @@ -93,7 +91,8 @@ public class ClasspathPattern for (String pattern : patterns) { entry = createEntry(pattern); - if (entry != null) { + if (entry != null) + { _patterns.add(pattern); _entries.add(entry); } @@ -101,6 +100,29 @@ public class ClasspathPattern } } + /* ------------------------------------------------------------ */ + /** + * @param patterns array of classpath patterns + */ + private void prependPatterns(String[] patterns) + { + if (patterns != null) + { + Entry entry = null; + int i=0; + for (String pattern : patterns) + { + entry = createEntry(pattern); + if (entry != null) + { + _patterns.add(i,pattern); + _entries.add(i,entry); + i++; + } + } + } + } + /* ------------------------------------------------------------ */ /** * Create an entry object containing information about @@ -156,9 +178,24 @@ public class ClasspathPattern patterns.add(entries.nextToken()); } - addPatterns((String[])patterns.toArray(new String[patterns.size()])); + addPatterns(patterns.toArray(new String[patterns.size()])); } + + /* ------------------------------------------------------------ */ + public void prependPattern(String classOrPackage) + { + ArrayList patterns = new ArrayList(); + StringTokenizer entries = new StringTokenizer(classOrPackage, ":,"); + while (entries.hasMoreTokens()) + { + patterns.add(entries.nextToken()); + } + + prependPatterns(patterns.toArray(new String[patterns.size()])); + } + + /* ------------------------------------------------------------ */ /** * @return array of classpath patterns @@ -217,4 +254,5 @@ public class ClasspathPattern } return result; } + } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java index c7aad9f25bd..137dc15e9ec 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java @@ -128,6 +128,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL "-org.eclipse.jetty.jndi.", // don't hide naming classes "-org.eclipse.jetty.jaas.", // don't hide jaas classes "-org.eclipse.jetty.websocket.", // WebSocket is a jetty extension + "-org.eclipse.jetty.servlets.", // don't hide jetty servlets "-org.eclipse.jetty.servlet.DefaultServlet", // don't hide default servlet "-org.eclipse.jetty.servlet.listener.", // don't hide useful listeners "org.eclipse.jetty." // hide other jetty classes @@ -650,12 +651,38 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL return _serverClasses.getPatterns(); } - public void addServerClass(String classname) + /* ------------------------------------------------------------ */ + /** Add to the list of Server classes. + * @see #setServerClasses(String[]) + * @param classOrPackage A fully qualified class name (eg com.foo.MyClass) + * or a qualified package name ending with '.' (eg com.foo.). If the class + * or package has '-' it is excluded from the server classes and order is thus + * important when added system class patterns. This argument may also be a comma + * separated list of classOrPackage patterns. + */ + public void addServerClass(String classOrPackage) { if (_serverClasses == null) loadServerClasses(); - _serverClasses.addPattern(classname); + _serverClasses.addPattern(classOrPackage); + } + + /* ------------------------------------------------------------ */ + /** Prepend to the list of Server classes. + * @see #setServerClasses(String[]) + * @param classOrPackage A fully qualified class name (eg com.foo.MyClass) + * or a qualified package name ending with '.' (eg com.foo.). If the class + * or package has '-' it is excluded from the server classes and order is thus + * important when added system class patterns. This argument may also be a comma + * separated list of classOrPackage patterns. + */ + public void prependServerClass(String classOrPackage) + { + if (_serverClasses == null) + loadServerClasses(); + + _serverClasses.prependPattern(classOrPackage); } /* ------------------------------------------------------------ */ @@ -673,12 +700,38 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL } /* ------------------------------------------------------------ */ - public void addSystemClass(String classname) + /** Add to the list of System classes. + * @see #setSystemClasses(String[]) + * @param classOrPackage A fully qualified class name (eg com.foo.MyClass) + * or a qualified package name ending with '.' (eg com.foo.). If the class + * or package has '-' it is excluded from the system classes and order is thus + * important when added system class patterns. This argument may also be a comma + * separated list of classOrPackage patterns. + */ + public void addSystemClass(String classOrPackage) { if (_systemClasses == null) loadSystemClasses(); - _systemClasses.addPattern(classname); + _systemClasses.addPattern(classOrPackage); + } + + + /* ------------------------------------------------------------ */ + /** Prepend to the list of System classes. + * @see #setSystemClasses(String[]) + * @param classOrPackage A fully qualified class name (eg com.foo.MyClass) + * or a qualified package name ending with '.' (eg com.foo.). If the class + * or package has '-' it is excluded from the system classes and order is thus + * important when added system class patterns.This argument may also be a comma + * separated list of classOrPackage patterns. + */ + public void prependSystemClass(String classOrPackage) + { + if (_systemClasses == null) + loadSystemClasses(); + + _systemClasses.prependPattern(classOrPackage); } /* ------------------------------------------------------------ */ diff --git a/test-jetty-webapp/pom.xml b/test-jetty-webapp/pom.xml index d729339925f..90be3ee99aa 100644 --- a/test-jetty-webapp/pom.xml +++ b/test-jetty-webapp/pom.xml @@ -159,6 +159,7 @@ org.eclipse.jetty jetty-servlets ${project.version} + provided org.eclipse.jetty.orbit @@ -169,6 +170,7 @@ org.eclipse.jetty.websocket websocket-server ${project.version} + provided org.eclipse.jetty diff --git a/test-jetty-webapp/src/main/java/com/acme/DispatchServlet.java b/test-jetty-webapp/src/main/java/com/acme/DispatchServlet.java index 38945f6c2a4..2f6434c1fc0 100644 --- a/test-jetty-webapp/src/main/java/com/acme/DispatchServlet.java +++ b/test-jetty-webapp/src/main/java/com/acme/DispatchServlet.java @@ -31,10 +31,6 @@ import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; - - /* ------------------------------------------------------------ */ /** Test Servlet RequestDispatcher. * @@ -43,8 +39,6 @@ import org.eclipse.jetty.util.log.Logger; @SuppressWarnings("serial") public class DispatchServlet extends HttpServlet { - private static final Logger LOG = Log.getLogger(DispatchServlet.class); - /* ------------------------------------------------------------ */ String pageType; @@ -165,7 +159,7 @@ public class DispatchServlet extends HttpServlet } catch(IOException e) { - LOG.ignore(e); + // getServletContext().log("ignore",e); } } else diff --git a/test-jetty-webapp/src/main/java/com/acme/Dump.java b/test-jetty-webapp/src/main/java/com/acme/Dump.java index da4c22be2b6..01f9b16cffd 100644 --- a/test-jetty-webapp/src/main/java/com/acme/Dump.java +++ b/test-jetty-webapp/src/main/java/com/acme/Dump.java @@ -53,10 +53,6 @@ import javax.servlet.http.HttpServletResponseWrapper; import org.eclipse.jetty.continuation.Continuation; import org.eclipse.jetty.continuation.ContinuationListener; import org.eclipse.jetty.continuation.ContinuationSupport; -import org.eclipse.jetty.http.HttpHeader; -import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; /** * Dump Servlet Request. @@ -64,8 +60,6 @@ import org.eclipse.jetty.util.log.Logger; @SuppressWarnings("serial") public class Dump extends HttpServlet { - private static final Logger LOG = Log.getLogger(Dump.class); - boolean fixed; Timer _timer; @@ -162,7 +156,7 @@ public class Dump extends HttpServlet try { long s = Long.parseLong(request.getParameter("sleep")); - if (request.getHeader(HttpHeader.EXPECT.asString())!=null && request.getHeader(HttpHeader.EXPECT.asString()).indexOf("102")>=0) + if (request.getHeader("Expect")!=null && request.getHeader("Expect").indexOf("102")>=0) { Thread.sleep(s/2); response.sendError(102); @@ -232,6 +226,7 @@ public class Dump extends HttpServlet continuation.addContinuationListener(new ContinuationListener() { + @Override public void onTimeout(Continuation continuation) { response.addHeader("Dump","onTimeout"); @@ -246,10 +241,11 @@ public class Dump extends HttpServlet } catch (IOException e) { - LOG.ignore(e); + getServletContext().log("",e); } } + @Override public void onComplete(Continuation continuation) { response.addHeader("Dump","onComplete"); @@ -1004,9 +1000,9 @@ public class Dump extends HttpServlet { if (s==null) return "null"; - s=StringUtil.replace(s,"&","&"); - s=StringUtil.replace(s,"<","<"); - s=StringUtil.replace(s,">",">"); + s=s.replaceAll("&","&"); + s=s.replaceAll("<","<"); + s=s.replaceAll(">",">"); return s; } } diff --git a/test-jetty-webapp/src/main/java/com/acme/LoginServlet.java b/test-jetty-webapp/src/main/java/com/acme/LoginServlet.java index e86598d2811..84bd79e3263 100644 --- a/test-jetty-webapp/src/main/java/com/acme/LoginServlet.java +++ b/test-jetty-webapp/src/main/java/com/acme/LoginServlet.java @@ -43,8 +43,6 @@ import org.eclipse.jetty.util.log.Logger; */ public class LoginServlet extends HttpServlet { - private static final Logger LOG = Log.getLogger(SecureModeServlet.class); - /* ------------------------------------------------------------ */ @Override public void init(ServletConfig config) throws ServletException @@ -63,7 +61,6 @@ public class LoginServlet extends HttpServlet @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - response.setContentType("text/html"); ServletOutputStream out = response.getOutputStream(); out.println(""); diff --git a/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java b/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java index f0ddb2a5113..46c6196403d 100644 --- a/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java +++ b/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java @@ -47,8 +47,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.util.FutureCallback; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.annotations.OnWebSocketClose; import org.eclipse.jetty.websocket.core.annotations.OnWebSocketConnect; import org.eclipse.jetty.websocket.core.annotations.OnWebSocketMessage; @@ -63,8 +61,6 @@ import org.eclipse.jetty.websocket.server.WebSocketServlet; @SuppressWarnings("serial") public class WebSocketChatServlet extends WebSocketServlet implements WebSocketCreator { - private static final Logger LOG = Log.getLogger(WebSocketChatServlet.class); - /** Holds active sockets to other members of the chat */ private final List members = new CopyOnWriteArrayList(); @@ -131,7 +127,7 @@ public class WebSocketChatServlet extends WebSocketServlet implements WebSocketC } catch (IOException e) { - LOG.warn(e); + getServletContext().log("write failed",e); } } } diff --git a/test-jetty-webapp/src/main/webapp/WEB-INF/jetty-web.xml b/test-jetty-webapp/src/main/webapp/WEB-INF/jetty-web.xml index bbaf1969170..ca48bb7ac9a 100644 --- a/test-jetty-webapp/src/main/webapp/WEB-INF/jetty-web.xml +++ b/test-jetty-webapp/src/main/webapp/WEB-INF/jetty-web.xml @@ -9,6 +9,8 @@ org.eclipse.jetty.servlet.WebApplicationContext object --> + -org.eclipse.jetty.util. + -org.eclipse.jetty.servlets. test webapp is deployed. DO NOT USE IN PRODUCTION! diff --git a/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java b/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java index e4372b6f9f9..f138697b3b3 100644 --- a/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java +++ b/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java @@ -165,7 +165,7 @@ public class TestServer server.setSendServerVersion(true); WebAppContext webapp = new WebAppContext(); - webapp.setParentLoaderPriority(true); + //webapp.setParentLoaderPriority(true); webapp.setResourceBase("./src/main/webapp"); webapp.setAttribute("testAttribute","testValue"); File sessiondir=File.createTempFile("sessions",null); diff --git a/tests/test-integration/src/test/resources/RFC2616Base.xml b/tests/test-integration/src/test/resources/RFC2616Base.xml index 878b1291129..f791c1af004 100644 --- a/tests/test-integration/src/test/resources/RFC2616Base.xml +++ b/tests/test-integration/src/test/resources/RFC2616Base.xml @@ -95,7 +95,7 @@ /webapp-contexts/RFC2616 0 - + /testable-jetty-server-config.properties