incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r585138 - in /incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling: api/ api/exceptions/ api/helpers/ contenttype/ etc/ requestcontext/ resource/ servlet/ slingservlets/
Date Tue, 16 Oct 2007 13:17:50 GMT
Author: bdelacretaz
Date: Tue Oct 16 06:17:39 2007
New Revision: 585138

URL: http://svn.apache.org/viewvc?rev=585138&view=rev
Log:
SLING-59 - move some classes to subpackages to make the code more self-explaining

Added:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/exceptions/
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/exceptions/HttpStatusCodeException.java
      - copied, changed from r585126, incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/HttpStatusCodeException.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/exceptions/SlingException.java
      - copied, changed from r585126, incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingException.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/helpers/
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/helpers/AbstractFilter.java
      - copied, changed from r585126, incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/AbstractFilter.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
  (with props)
Removed:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/AbstractFilter.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/HttpStatusCodeException.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingException.java
Modified:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/AbstractSlingServlet.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/MissingRequestAttributeException.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java

Copied: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/exceptions/HttpStatusCodeException.java
(from r585126, incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/HttpStatusCodeException.java)
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/exceptions/HttpStatusCodeException.java?p2=incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/exceptions/HttpStatusCodeException.java&p1=incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/HttpStatusCodeException.java&r1=585126&r2=585138&rev=585138&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/HttpStatusCodeException.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/exceptions/HttpStatusCodeException.java
Tue Oct 16 06:17:39 2007
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.microsling.api;
+package org.apache.sling.microsling.api.exceptions;
 
 import java.io.IOException;
 

Copied: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/exceptions/SlingException.java
(from r585126, incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingException.java)
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/exceptions/SlingException.java?p2=incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/exceptions/SlingException.java&p1=incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingException.java&r1=585126&r2=585138&rev=585138&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingException.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/exceptions/SlingException.java
Tue Oct 16 06:17:39 2007
@@ -1,4 +1,4 @@
-package org.apache.sling.microsling.api;
+package org.apache.sling.microsling.api.exceptions;
 
 import javax.servlet.ServletException;
 

Copied: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/helpers/AbstractFilter.java
(from r585126, incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/AbstractFilter.java)
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/helpers/AbstractFilter.java?p2=incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/helpers/AbstractFilter.java&p1=incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/AbstractFilter.java&r1=585126&r2=585138&rev=585138&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/AbstractFilter.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/helpers/AbstractFilter.java
Tue Oct 16 06:17:39 2007
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.microsling.api;
+package org.apache.sling.microsling.api.helpers;
 
 import java.io.IOException;
 

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java?rev=585138&r1=585137&r2=585138&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
Tue Oct 16 06:17:39 2007
@@ -7,7 +7,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.sling.microsling.api.AbstractFilter;
+import org.apache.sling.microsling.api.helpers.AbstractFilter;
 import org.apache.sling.microsling.requestcontext.SlingRequestContext;
 
 public class ResponseContentTypeResolverFilter extends AbstractFilter {

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/AbstractSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/AbstractSlingServlet.java?rev=585138&r1=585137&r2=585138&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/AbstractSlingServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/AbstractSlingServlet.java
Tue Oct 16 06:17:39 2007
@@ -19,8 +19,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.sling.microsling.api.HttpStatusCodeException;
 import org.apache.sling.microsling.api.SlingServlet;
+import org.apache.sling.microsling.api.exceptions.HttpStatusCodeException;
 
 /** Base class for SlingServlets, fails with "not implemented"
  *  for all HTTP methods supported by SlingServlet

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/MissingRequestAttributeException.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/MissingRequestAttributeException.java?rev=585138&r1=585137&r2=585138&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/MissingRequestAttributeException.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/MissingRequestAttributeException.java
Tue Oct 16 06:17:39 2007
@@ -1,6 +1,6 @@
 package org.apache.sling.microsling.etc;
 
-import org.apache.sling.microsling.api.SlingException;
+import org.apache.sling.microsling.api.exceptions.SlingException;
 
 /** Indicates a missing Request attribute */
 public class MissingRequestAttributeException extends SlingException {

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java?rev=585138&r1=585137&r2=585138&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java
Tue Oct 16 06:17:39 2007
@@ -26,7 +26,7 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.sling.microsling.api.Resource;
-import org.apache.sling.microsling.api.SlingException;
+import org.apache.sling.microsling.api.exceptions.SlingException;
 import org.apache.sling.microsling.etc.MissingRequestAttributeException;
 
 /** Additional Request-based info used by for SlingServlets */

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java?rev=585138&r1=585137&r2=585138&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java
Tue Oct 16 06:17:39 2007
@@ -24,8 +24,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.sling.microsling.api.AbstractFilter;
 import org.apache.sling.microsling.api.Resource;
+import org.apache.sling.microsling.api.helpers.AbstractFilter;
 import org.apache.sling.microsling.requestcontext.SlingRequestContext;
 
 /** A RequestFilter that selects the Resource to process */

Added: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java?rev=585138&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
(added)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
Tue Oct 16 06:17:39 2007
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.microsling.servlet;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.microsling.servlet.MicroSlingServlet;
+
+/** This is helper code, not very interesting to study (but it's
+ *  not in an "helpers" package as that would require too much public
+ *  stuff).
+ * 
+ *  Manages the microsling chain of servlet Filters:
+ *  stores the list, calls them when processing a request
+ *  and calls microSlingServlet.doService after that.
+ */
+class MicroSlingFilterHelper {
+
+    private MicroSlingServlet microSling;
+
+    private List<Filter> requestFilterList = new LinkedList<Filter>();
+
+    private Filter[] requestFilters;
+
+    MicroSlingFilterHelper(MicroSlingServlet microSling) {
+        this.microSling = microSling;
+    }
+
+    void destroy() {
+        Filter[] filters = getFilters();
+
+        // clean up
+        requestFilterList.clear();
+        requestFilters = null;
+
+        // destroy the filters
+        for (int i=0; i < filters.length; i++) {
+            try {
+                filters[i].destroy();
+            } catch (Throwable t) {
+                // TODO: some logging would probably be usefull
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see javax.servlet.FilterChain#doFilter(javax.servlet.ServletRequest,
+     *      javax.servlet.ServletResponse)
+     */
+    void service(ServletRequest request, ServletResponse response)
+            throws IOException, ServletException {
+
+        MicroSlingFilterChain filterChain = new MicroSlingFilterChain(
+            microSling, getFilters());
+        filterChain.doFilter(request, response);
+
+    }
+
+    /** return our Filters as a (lazily created) array */
+    private Filter[] getFilters() {
+        if (requestFilters == null) {
+            requestFilters = requestFilterList.toArray(new Filter[requestFilterList.size()]);
+        }
+        return requestFilters;
+    }
+
+    /** Add a Filter at the end of our current chain */
+    void addFilter(final Filter filter) throws ServletException {
+        FilterConfig config = new FilterConfig() {
+            public String getFilterName() {
+                return filter.getClass().getName();
+            }
+
+            public String getInitParameter(String arg0) {
+                // no parameters for now
+                return null;
+            }
+
+            public Enumeration<?> getInitParameterNames() {
+                // no parameters for now
+                return Collections.enumeration(Collections.emptyList());
+            }
+
+            public ServletContext getServletContext() {
+                return microSling.getServletContext();
+            }
+        };
+
+        // initialize the filter and add it to the list
+        filter.init(config);
+        requestFilterList.add(filter);
+
+        // force recreation of filter list
+        requestFilters = null;
+    }
+
+    /** A FilterChain that applies all Filters in an array and calls
+     *  MicroSlingServlet.doFilter when done
+     */
+    private static class MicroSlingFilterChain implements FilterChain {
+
+        private final MicroSlingServlet microSlingServlet;
+
+        private final Filter[] requestFilters;
+
+        private int currentFilter;
+
+        private MicroSlingFilterChain(MicroSlingServlet microSlingServlet,
+                Filter[] requestFilters) {
+            this.microSlingServlet = microSlingServlet;
+            this.requestFilters = requestFilters;
+            this.currentFilter = -1;
+        }
+
+        public void doFilter(ServletRequest request, ServletResponse response)
+                throws IOException, ServletException {
+
+            currentFilter++;
+
+            if (currentFilter < requestFilters.length) {
+                // call the next filter
+                requestFilters[currentFilter].doFilter(request, response, this);
+
+            } else {
+                // done with filters, call microsling servlet
+                HttpServletRequest hReq = null;
+                HttpServletResponse hRep = null;
+                try {
+                    hReq = (HttpServletRequest)request;
+                    hRep = (HttpServletResponse)response;
+                } catch(ClassCastException cce) {
+                    throw new ServletException("Expected an HttpServletRequest and HttpServletResponse",cce);
+                }
+                microSlingServlet.doService(hReq,hRep);
+            }
+
+        }
+    }
+}

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java?rev=585138&r1=585137&r2=585138&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
Tue Oct 16 06:17:39 2007
@@ -30,8 +30,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.sling.microsling.api.HttpStatusCodeException;
 import org.apache.sling.microsling.api.SlingServlet;
+import org.apache.sling.microsling.api.exceptions.HttpStatusCodeException;
 import org.apache.sling.microsling.contenttype.ResponseContentTypeResolverFilter;
 import org.apache.sling.microsling.etc.HttpConstants;
 import org.apache.sling.microsling.requestcontext.SlingRequestContext;

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java?rev=585138&r1=585137&r2=585138&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
Tue Oct 16 06:17:39 2007
@@ -28,7 +28,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.sling.microsling.api.HttpStatusCodeException;
+import org.apache.sling.microsling.api.exceptions.HttpStatusCodeException;
 import org.apache.sling.microsling.etc.AbstractSlingServlet;
 import org.apache.sling.microsling.requestcontext.SlingRequestContext;
 



Mime
View raw message