incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r620447 - /incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
Date Mon, 11 Feb 2008 09:56:20 GMT
Author: fmeschbe
Date: Mon Feb 11 01:56:15 2008
New Revision: 620447

URL: http://svn.apache.org/viewvc?rev=620447&view=rev
Log:
SLING-243 If baseName is not the method name, try finding the script with the method name

Modified:
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java

Modified: incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java?rev=620447&r1=620446&r2=620447&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
(original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
Mon Feb 11 01:56:15 2008
@@ -132,26 +132,36 @@
             }
         }
 
+        Servlet servlet = null;
+
         ResourceResolver resolver = request.getResourceResolver();
+        String[] path = resolver.getSearchPath();
         String baseName = PathSupport.getScriptBaseName(request);
 
-        // search the servlet by absolute path and resource type
+        // (1) default script name and according to resource type and selectors
         Iterator<String> pathIterator = PathSupport.getPathIterator(request,
             path);
-        Servlet servlet = null;
-        while (servlet == null && pathIterator.hasNext()) {
-            servlet = getServletAt(resolver, pathIterator.next(), baseName);
+        servlet = getServlet(resolver, pathIterator, baseName);
+        
+        // (2) GET/HEAD and according to resource type and selectors
+        if (servlet == null && !baseName.equals(request.getMethod())) {
+            pathIterator = PathSupport.getPathIterator(request, path);
+            servlet = getServlet(resolver, pathIterator, request.getMethod());
         }
-
-        // fall back to default servlet for the request
+    
+        // (3) default script name and default servlet name and selectors
         if (servlet == null) {
             pathIterator = PathSupport.getPathIterator(DEFAULT_SERVLET_NAME, path);
-            while (servlet == null && pathIterator.hasNext()) {
-                servlet = getServletAt(resolver, pathIterator.next(), baseName);
-            }
+            servlet = getServlet(resolver, pathIterator, baseName);
         }
 
-        // last resort, use the core bundle default servlet
+        // (4) GET/HEAD and default servlet name and selectors
+        if (servlet == null && !baseName.equals(request.getMethod())) {
+            pathIterator = PathSupport.getPathIterator(DEFAULT_SERVLET_NAME, path);
+            servlet = getServlet(resolver, pathIterator, request.getMethod());
+        }
+
+        // (5) last resort, use the core bundle default servlet
         if (servlet == null) {
             servlet = getCoreDefaultServlet();
         }
@@ -232,17 +242,7 @@
         // search the servlet by absolute path
         Iterator<String> pathIterator = PathSupport.getPathIterator(
             ServletResolverConstants.ERROR_HANDLER_PATH, path);
-        Servlet servlet = null;
-        while (servlet == null && pathIterator.hasNext()) {
-            String location = pathIterator.next();
-            try {
-                servlet = getServletAt(resolver, location, baseName);
-            } catch (SlingException se) {
-                log.warn("handleError: Problem resolving servlet at "
-                    + location + "/" + baseName, se);
-            }
-        }
-
+        Servlet servlet = getServlet(resolver, pathIterator, baseName);
         if (servlet == null) {
             servlet = getDefaultErrorServlet();
         }
@@ -280,18 +280,9 @@
         Class<?> tClass = throwable.getClass();
         while (servlet == null && tClass != Object.class) {
             String baseName = tClass.getSimpleName();
-
             Iterator<String> pathIterator = PathSupport.getPathIterator(
                 ServletResolverConstants.ERROR_HANDLER_PATH, path);
-            while (servlet == null && pathIterator.hasNext()) {
-                String location = pathIterator.next();
-                try {
-                    servlet = getServletAt(resolver, location, baseName);
-                } catch (SlingException se) {
-                    log.warn("handleError: Problem resolving servlet at "
-                        + location + "/" + baseName, se);
-                }
-            }
+            servlet = getServlet(resolver, pathIterator, baseName);
 
             // go to the base class
             tClass = tClass.getSuperclass();
@@ -313,6 +304,24 @@
 
     // ---------- internal helper ---------------------------------------------
 
+    private Servlet getServlet(ResourceResolver resolver, Iterator<String> paths, String
baseName) {
+        while (paths.hasNext()) {
+            String location = paths.next();
+            try {
+                Servlet result = getServletAt(resolver, location, baseName);
+                if (result != null) {
+                    return result;
+                }
+            } catch (SlingException se) {
+                log.warn("getServlet: Problem resolving servlet at "
+                    + location + "/" + baseName, se);
+            }
+        }
+        
+        // exhausted all
+        return null;
+    }
+    
     private Servlet getServletAt(ResourceResolver resolver, String location,
             String baseName) throws SlingException {
         Servlet result = null;



Mime
View raw message