incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r726592 - in /incubator/sling/trunk/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
Date Mon, 15 Dec 2008 01:10:09 GMT
Author: fmeschbe
Date: Sun Dec 14 17:10:08 2008
New Revision: 726592

URL: http://svn.apache.org/viewvc?rev=726592&view=rev
Log:
SLING-777 Do not add scheme and host:port if they are the same as for
the original request.

Modified:
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.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=726592&r1=726591&r2=726592&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
Sun Dec 14 17:10:08 2008
@@ -205,28 +205,36 @@
         }
         
         if (mappedPathIsUrl) {
+            
+            // cut off scheme and host, if the same as requested
+            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("/");
+                
+                if (mappedPath.startsWith(sb.toString())) {
+                    mappedPath = mappedPath.substring(sb.length()-1);
+                }
+            }
+            
             // TODO: probably need to mangle name spaces
             return mappedPath;
         }
-        
-        StringBuilder sb = new StringBuilder();
 
-        if (request != null) {
-            sb.append(request.getScheme()).append("://");
-            sb.append(request.getServerName());
-            if (request.getServerPort() > 0) {
-                sb.append(':').append(request.getServerPort());
-            }
-            if (request.getContextPath() != null
-                && request.getContextPath().length() > 0) {
-                sb.append(request.getContextPath());
-            }
+        // mangle the namespaces
+        mappedPath = mangleNamespaces(mappedPath);
+
+        // prepend servlet context path if we have a request
+        if (request != null && request.getContextPath() != null
+            && request.getContextPath().length() > 0) {
+            mappedPath = request.getContextPath().concat(mappedPath);
         }
 
-        // mangle the namespaces
-        sb.append(mangleNamespaces(mappedPath));
-        
-        return sb.toString();
+        return mappedPath;
     }
 
     // ---------- search path for relative resoures

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java?rev=726592&r1=726591&r2=726592&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
Sun Dec 14 17:10:08 2008
@@ -394,11 +394,15 @@
         assertNotNull(res1);
         assertEquals("/content/virtual/playground/en.html", res1.getPath());
 
-        final String mapped0 = resResolver.map(request, res0.getPath());
-        assertEquals("http://virtual.host.com/playground.html", mapped0);
-
-        final String mapped1 = resResolver.map(request, res1.getPath());
-        assertEquals("http://virtual.host.com/playground/en.html", mapped1);
+        final String mapped00 = resResolver.map(res0.getPath());
+        assertEquals("http://virtual.host.com/playground.html", mapped00);
+        final String mapped01 = resResolver.map(request, res0.getPath());
+        assertEquals("/playground.html", mapped01);
+
+        final String mapped10 = resResolver.map(res1.getPath());
+        assertEquals("http://virtual.host.com/playground/en.html", mapped10);
+        final String mapped11 = resResolver.map(request, res1.getPath());
+        assertEquals("/playground/en.html", mapped11);
     }
 
     public void testResolveVirtualHostHttp8080() throws Exception {
@@ -436,11 +440,15 @@
         assertNotNull(res1);
         assertEquals("/content/virtual/playground/en.html", res1.getPath());
         
-        final String mapped0 = resResolver.map(request, res0.getPath());
-        assertEquals("http://virtual.host.com:8080/playground.html", mapped0);
-        
-        final String mapped1 = resResolver.map(request, res1.getPath());
-        assertEquals("http://virtual.host.com:8080/playground/en.html", mapped1);
+        final String mapped00 = resResolver.map(res0.getPath());
+        assertEquals("http://virtual.host.com:8080/playground.html", mapped00);
+        final String mapped01 = resResolver.map(request, res0.getPath());
+        assertEquals("/playground.html", mapped01);
+        
+        final String mapped10 = resResolver.map(res1.getPath());
+        assertEquals("http://virtual.host.com:8080/playground/en.html", mapped10);
+        final String mapped11 = resResolver.map(request, res1.getPath());
+        assertEquals("/playground/en.html", mapped11);
     }
     
     public void testResolveVirtualHostHttp8080Root() throws Exception {
@@ -478,11 +486,15 @@
         assertNotNull(res1);
         assertEquals("/playground/en.html", res1.getPath());
 
-        final String mapped0 = resResolver.map(request, res0.getPath());
-        assertEquals("http://virtual.host.com:8080/playground.html", mapped0);
-
-        final String mapped1 = resResolver.map(request, res1.getPath());
-        assertEquals("http://virtual.host.com:8080/playground/en.html", mapped1);
+        final String mapped00 = resResolver.map(res0.getPath());
+        assertEquals("http://virtual.host.com:8080/playground.html", mapped00);
+        final String mapped01 = resResolver.map(request, res0.getPath());
+        assertEquals("/playground.html", mapped01);
+        
+        final String mapped10 = resResolver.map(res1.getPath());
+        assertEquals("http://virtual.host.com:8080/playground/en.html", mapped10);
+        final String mapped11 = resResolver.map(request, res1.getPath());
+        assertEquals("/playground/en.html", mapped11);
     }
 
     public void testResolveVirtualHostHttps443() throws Exception {
@@ -520,11 +532,15 @@
         assertNotNull(res1);
         assertEquals("/content/virtual/playground/en.html", res1.getPath());
 
-        final String mapped0 = resResolver.map(request, res0.getPath());
-        assertEquals("https://virtual.host.com/playground.html", mapped0);
-
-        final String mapped1 = resResolver.map(request, res1.getPath());
-        assertEquals("https://virtual.host.com/playground/en.html", mapped1);
+        final String mapped00 = resResolver.map(res0.getPath());
+        assertEquals("https://virtual.host.com/playground.html", mapped00);
+        final String mapped01 = resResolver.map(request, res0.getPath());
+        assertEquals("/playground.html", mapped01);
+        
+        final String mapped10 = resResolver.map(res1.getPath());
+        assertEquals("https://virtual.host.com/playground/en.html", mapped10);
+        final String mapped11 = resResolver.map(request, res1.getPath());
+        assertEquals("/playground/en.html", mapped11);
     }
 
     public void testResolveVirtualHostHttps4443() throws Exception {
@@ -562,12 +578,15 @@
         assertNotNull(res1);
         assertEquals("/content/virtual/playground/en.html", res1.getPath());
 
-        final String mapped0 = resResolver.map(request, res0.getPath());
-        assertEquals("https://virtual.host.com:4443/playground.html", mapped0);
-
-        final String mapped1 = resResolver.map(request, res1.getPath());
-        assertEquals("https://virtual.host.com:4443/playground/en.html",
-            mapped1);
+        final String mapped00 = resResolver.map(res0.getPath());
+        assertEquals("https://virtual.host.com:4443/playground.html", mapped00);
+        final String mapped01 = resResolver.map(request, res0.getPath());
+        assertEquals("/playground.html", mapped01);
+        
+        final String mapped10 = resResolver.map(res1.getPath());
+        assertEquals("https://virtual.host.com:4443/playground/en.html", mapped10);
+        final String mapped11 = resResolver.map(request, res1.getPath());
+        assertEquals("/playground/en.html", mapped11);
     }
 
     public void testResolveResourceAlias() throws Exception {



Mime
View raw message