incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r727486 - in /incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal: JcrResourceResolver2.java helper/MapEntry.java
Date Wed, 17 Dec 2008 19:37:00 GMT
Author: fmeschbe
Date: Wed Dec 17 11:37:00 2008
New Revision: 727486

URL: http://svn.apache.org/viewvc?rev=727486&view=rev
Log:
SLING-785 Fix reverse mapping by omitting default port numbers and add
some more logging to the resolution process

Modified:
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java?rev=727486&r1=727485&r2=727486&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
Wed Dec 17 11:37:00 2008
@@ -20,29 +20,21 @@
 
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.Stack;
 import java.util.StringTokenizer;
-import java.util.Map.Entry;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
-import javax.jcr.query.Query;
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.RowIterator;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 import org.apache.sling.adapter.SlingAdaptable;
 import org.apache.sling.api.SlingException;
@@ -56,7 +48,6 @@
 import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.apache.sling.jcr.resource.internal.helper.MapEntries;
 import org.apache.sling.jcr.resource.internal.helper.MapEntry;
-import org.apache.sling.jcr.resource.internal.helper.Mapping;
 import org.apache.sling.jcr.resource.internal.helper.RedirectResource;
 import org.apache.sling.jcr.resource.internal.helper.ResourcePathIterator;
 import org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator;
@@ -150,14 +141,8 @@
         // cut off scheme and host, if the same as requested
         String schemehostport;
         if (request != null) {
-            StringBuilder sb = new StringBuilder();
-            sb.append(request.getScheme()).append("://");
-            sb.append(request.getServerName());
-            if (request.getServerPort() > 0) {
-                sb.append(':').append(request.getServerPort());
-            }
-            sb.append("/");
-            schemehostport = sb.toString();
+            schemehostport = MapEntry.getURI(request.getScheme(),
+                request.getServerName(), request.getServerPort(), "/");
 
             log.debug("map: Mapping path {} for {}", resourcePath,
                 schemehostport);
@@ -496,7 +481,7 @@
             if (realPath.startsWith("/")) {
 
                 // let's check it with a direct access first
-                log.debug("resolve: Try absolute mapped path");
+                log.debug("resolve: Try absolute mapped path {}", realPath);
                 res = resolveInternal(realPath);
 
             } else {
@@ -540,13 +525,13 @@
      *            is 80 unless the scheme is "https" in which case the default
      *            value is 443.
      * @param path The (absolute) path
-     * @return The request path string {scheme}/{host}.{port}/{path}.
+     * @return The request path string {scheme}/{host}.{port}{path}.
      */
-    private String getMapPath(String scheme, String host, int port, String path) {
+    public static String getMapPath(String scheme, String host, int port, String path) {
         if (port < 0) {
             port = ("https".equals(scheme)) ? 443 : 80;
         }
-
+        
         return scheme + "/" + host + "." + port + path;
     }
 
@@ -597,6 +582,10 @@
 
             String rpi = absPath.substring(curPath.length());
             resource.getResourceMetadata().setResolutionPathInfo(rpi);
+            
+            log.debug(
+                "resolveInternal: Found resource {} with path info {} for {}",
+                new Object[] { resource, rpi, absPath });
 
         } else {
 
@@ -651,6 +640,9 @@
             String alias = getProperty(child, PROP_REDIRECT_INTERNAL);
             if (alias != null) {
                 // TODO: might be a redirect ??
+                log.warn(
+                    "getChildInternal: Internal redirect to {} for Resource {} is not supported
yet, ignoring",
+                    alias, child);
             }
 
             // we have the resource name, continue with the next level
@@ -664,11 +656,16 @@
             child = children.next();
             String alias = getProperty(child, PROP_ALIAS);
             if (childName.equals(alias)) {
+                log.debug(
+                    "getChildInternal: Found Resource {} with alias {} to use",
+                    child, childName);
                 return child;
             }
         }
 
         // no match for the childName found
+        log.debug("getChildInternal: Resource {} has no child {}", parent,
+            childName);
         return null;
     }
 
@@ -694,6 +691,8 @@
         if (props != null) {
             String prop = props.get(propName, String.class);
             if (prop != null) {
+                log.debug("getProperty: Resource {} has property {}={}",
+                    new Object[] { res, propName, prop });
                 return prop;
             }
         }

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java?rev=727486&r1=727485&r2=727486&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java
Wed Dec 17 11:37:00 2008
@@ -22,7 +22,6 @@
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Comparator;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -61,6 +60,31 @@
         return path;
     }
     
+    /**
+     * Returns a string used for matching map entries against the given request
+     * or URI parts.
+     * 
+     * @param scheme The URI scheme
+     * @param host The host name
+     * @param port The port number. If this is negative, the default value used
+     *            is 80 unless the scheme is "https" in which case the default
+     *            value is 443.
+     * @param path The (absolute) path
+     * @return The request path string {scheme}://{host}:{port}{path}.
+     */
+    public static String getURI(String scheme, String host, int port, String path) {
+        
+        StringBuilder sb = new StringBuilder();
+        sb.append(scheme).append("://").append(host);
+        if (port > 0 && !(port == 80 && "http".equals(scheme))
+            && !(port == 443 && "https".equals(scheme))) {
+            sb.append(':').append(port);
+        }
+        sb.append(path);
+        
+        return sb.toString();
+    }
+
     public static URI toURI(String uriPath) {
         for (int i = 0; i < PATH_TO_URL_MATCH.length; i++) {
             Matcher m = PATH_TO_URL_MATCH[i].matcher(uriPath);
@@ -115,7 +139,9 @@
                 int status = -1;
                 URI extPathPrefix = toURI(url);
                 if (extPathPrefix != null) {
-                    url = extPathPrefix.toString();
+                    url = getURI(extPathPrefix.getScheme(),
+                        extPathPrefix.getHost(), extPathPrefix.getPort(),
+                        extPathPrefix.getPath());
                     status = 302;
                 }
 



Mime
View raw message