Author: markt
Date: Wed Jun 22 18:30:41 2011
New Revision: 1138573

URL: http://svn.apache.org/viewvc?rev=1138573&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51418
Provide more control over Context creation when embedding Tomcat.
Based on a patch by Benson Margulies.

Modified:
    tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java?rev=1138573&r1=1138572&r2=1138573&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java Wed Jun 22 
18:30:41 2011
@@ -83,6 +83,35 @@ import org.apache.catalina.session.Stand
  * use if you have a webapp with a web.xml file, but it is 
  * optional - you can use your own servlets.
  * 
+ * There are a variety of 'add' methods to configure servlets and webapps. 
These
+ * methods, by default, create a simple in-memory security realm and apply it.
+ * If you need more complex security processing, you can define a subclass of
+ * this class.
+ * 
+ * This class provides a set of convenience methods for configuring webapp
+ * contexts, all overloads of the method <pre>addWebapp</pre>. These methods
+ * create a webapp context, configure it, and then add it to a {@link Host}.
+ * They do not use a global default web.xml; rather, they add a lifecycle
+ * listener that adds the standard DefaultServlet, JSP processing, and welcome
+ * files.
+ * 
+ * In complex cases, you may prefer to use the ordinary Tomcat API to create
+ * webapp contexts; for example, you might need to install a custom Loader
+ * before the call to {@link Host#addChild(Container)}. To replicate the basic
+ * behavior of the <pre>addWebapp</pre> methods, you may want to call three
+ * methods of this class: {@link #getDefaultRealm()}, 
+ * {@link #noDefaultWebXmlPath()}, and {@link #getDefaultWebXmlListener()}. 
+ * 
+ * {@link #getDefaultRealm()} returns the simple security realm.
+ * 
+ * {@link #getDefaultWebXmlListener()} returns a {@link LifecycleListener} that
+ * adds the standard DefaultServlet, JSP processing, and welcome files. If you
+ * add this listener, you must prevent Tomcat from applying any standard global
+ * web.xml with ...
+ * 
+ * {@link #noDefaultWebXmlPath()} returns a dummy pathname to configure to
+ * prevent {@link ContextConfig} from trying to apply a global web.xml file. 
+ * 
  * This class provides a main() and few simple CLI arguments,
  * see setters for doc. It can be used for simple tests and
  * demo.
@@ -116,9 +145,10 @@ public class Tomcat {
     // the context.
     protected Realm defaultRealm;
     private Map<String, String> userPass = new HashMap<String, String>();
-    private Map<String, List<String>> userRoles = 
-            new HashMap<String, List<String>>();
-    private Map<String, Principal> userPrincipals = new HashMap<String, 
Principal>();
+    private Map<String, List<String>> userRoles =
+        new HashMap<String, List<String>>();
+    private Map<String, Principal> userPrincipals =
+        new HashMap<String, Principal>();
     
     public Tomcat() {
         // NOOP
@@ -511,6 +541,39 @@ public class Tomcat {
 
         return ctx;
     }
+    
+    /**
+     * Return a listener that provides the required configuration items for JSP
+     * processing. From the standard Tomcat global web.xml. Pass this to
+     * {@link Context#addLifecycleListener(LifecycleListener)} and then pass 
the
+     * result of {@link #noDefaultWebXmlPath()} to 
+     * {@link ContextConfig#setDefaultWebXml(String)}. 
+     * @return a listener object that configures default JSP processing.
+     */
+    public LifecycleListener getDefaultWebXmlListener() {
+        return new DefaultWebXmlListener();
+    }
+    
+    /**
+     * @return a pathname to pass to
+     * {@link ContextConfig#setDefaultWebXml(String)} when using
+     * {@link #getDefaultWebXmlListener()}.
+     */
+    public String noDefaultWebXmlPath() {
+        return "org/apache/catalin/startup/NO_DEFAULT_XML";
+    }
+    
+    /**
+     * For complex configurations, this accessor allows callers of this class
+     * to obtain the simple realm created by default.
+     * @return the simple in-memory realm created by default.
+     */
+    public Realm getDefaultRealm() {
+        if (defaultRealm == null) {
+            initSimpleAuth();
+        }
+        return defaultRealm;
+    }
 
 
     // ---------- Helper methods and classes -------------------

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1138573&r1=1138572&r2=1138573&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Jun 22 18:30:41 2011
@@ -126,6 +126,10 @@
         performance penalty for some use cases. This fix addresses those
         performance penalties while retaining the original improvements. 
(markt) 
       </fix>
+      <add>
+        <bug>51418</bug>: Provide more control over Context creation when
+        embedding Tomcat. Based on a patch by Benson Margulies. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to