incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r591023 - /incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingServletResolver.java
Date Thu, 01 Nov 2007 14:33:05 GMT
Author: fmeschbe
Date: Thu Nov  1 07:33:05 2007
New Revision: 591023

URL: http://svn.apache.org/viewvc?rev=591023&view=rev
Log:
Make sure the DefaultSlingServlet is initialized. Otherwise the (new) spooling functionality
will fail.

Modified:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingServletResolver.java

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingServletResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingServletResolver.java?rev=591023&r1=591022&r2=591023&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingServletResolver.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingServletResolver.java
Thu Nov  1 07:33:05 2007
@@ -51,27 +51,38 @@
 
     private DefaultSlingServlet defaultSlingServlet;
 
-    MicroslingServletResolver(ServletContext servletContext) {
+    MicroslingServletResolver(ServletContext servletContext)
+            throws ServletException {
         this.servletContext = servletContext;
         this.servlets = new HashMap<String, Servlet>();
 
         // TODO use a utility class to map nt:file to the magic NODETYPES path
         addServlet("NODETYPES/nt/file", new StreamServlet());
+
         defaultSlingServlet = new DefaultSlingServlet();
+        ServletConfig config = new MicroslingServletConfig(
+            "Default microsling Servlet", getServletContext());
+        defaultSlingServlet.init(config);
     }
 
     protected void destroy() {
-        Servlet[] servletList = servlets.values().toArray(
-            new Servlet[servlets.size()]);
-        for (Servlet servlet : servletList) {
-            try {
-                servlet.destroy();
-            } catch (Throwable t) {
-                getServletContext().log(
-                    "Unexpected problem destroying servlet " + servlet, t);
+        if (servlets != null) {
+            Servlet[] servletList = servlets.values().toArray(
+                new Servlet[servlets.size()]);
+            for (Servlet servlet : servletList) {
+                try {
+                    servlet.destroy();
+                } catch (Throwable t) {
+                    getServletContext().log(
+                        "Unexpected problem destroying servlet " + servlet, t);
+                }
             }
+            servlets.clear();
+        }
+
+        if (defaultSlingServlet != null) {
+            defaultSlingServlet.destroy();
         }
-        servlets.clear();
     }
 
     public Servlet resolveServlet(SlingHttpServletRequest request)
@@ -129,23 +140,7 @@
     protected void addServlet(final String resourceType, Servlet servlet) {
 
         try {
-            ServletConfig config = new ServletConfig() {
-                public String getInitParameter(String name) {
-                    return null;
-                }
-
-                public Enumeration<?> getInitParameterNames() {
-                    return Collections.enumeration(Collections.emptyList());
-                }
-
-                public ServletContext getServletContext() {
-                    return MicroslingServletResolver.this.getServletContext();
-                }
-
-                public String getServletName() {
-                    return resourceType;
-                }
-            };
+            ServletConfig config = new MicroslingServletConfig(resourceType, getServletContext());
             servlet.init(config);
 
             // only register if initialization succeeds
@@ -160,5 +155,32 @@
 
     protected ServletContext getServletContext() {
         return servletContext;
+    }
+
+    private static class MicroslingServletConfig implements ServletConfig {
+
+        private final String servletName;
+        private final ServletContext servletContext;
+
+        public MicroslingServletConfig(String servletName, ServletContext servletContext)
{
+            this.servletName = servletName;
+            this.servletContext = servletContext;
+        }
+
+        public String getInitParameter(String name) {
+            return null;
+        }
+
+        public Enumeration<?> getInitParameterNames() {
+            return Collections.enumeration(Collections.emptyList());
+        }
+
+        public ServletContext getServletContext() {
+            return servletContext;
+        }
+
+        public String getServletName() {
+            return servletName;
+        }
     }
 }



Mime
View raw message