incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1588174 - /sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java
Date Thu, 17 Apr 2014 09:00:18 GMT
Author: cziegeler
Date: Thu Apr 17 09:00:18 2014
New Revision: 1588174

URL: http://svn.apache.org/r1588174
Log:
SLING-3504 : SlingHttpServletResponseImpl.encodeXXX methods always add context path

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java?rev=1588174&r1=1588173&r2=1588174&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java
Thu Apr 17 09:00:18 2014
@@ -58,38 +58,44 @@ public class SlingHttpServletResponseImp
     // ---------- Redirection support through PathResolver --------------------
 
     @Override
-    public String encodeURL(String url) {
+    public String encodeURL(final String url) {
+        // remove context path
+        String path = removeContextPath(url);
+
         // make the path absolute
-        url = makeAbsolutePath(url);
+        path = makeAbsolutePath(path);
 
         // resolve the url to as if it would be a resource path
-        url = map(url);
+        path = map(path);
 
         // have the servlet container to further encodings
-        return super.encodeURL(url);
+        return super.encodeURL(path);
     }
 
     @Override
-    public String encodeRedirectURL(String url) {
+    public String encodeRedirectURL(final String url) {
+        // remove context path
+        String path = removeContextPath(url);
+
         // make the path absolute
-        url = makeAbsolutePath(url);
+        path = makeAbsolutePath(path);
 
         // resolve the url to as if it would be a resource path
-        url = map(url);
+        path = map(path);
 
         // have the servlet container to further encodings
-        return super.encodeRedirectURL(url);
+        return super.encodeRedirectURL(path);
     }
 
     @Override
     @Deprecated
-    public String encodeUrl(String url) {
+    public String encodeUrl(final String url) {
         return encodeURL(url);
     }
 
     @Override
     @Deprecated
-    public String encodeRedirectUrl(String url) {
+    public String encodeRedirectUrl(final String url) {
         return encodeRedirectURL(url);
     }
 
@@ -364,4 +370,12 @@ public class SlingHttpServletResponseImp
     private String map(String url) {
         return getRequestData().getResourceResolver().map(getRequestData().getServletRequest(),
url);
     }
+
+    private String removeContextPath(final String path) {
+        final String contextPath = this.getRequestData().getSlingRequest().getContextPath().concat("/");
+        if ( contextPath.length() > 1 && path.startsWith(contextPath) ) {
+            return path.substring(contextPath.length() - 1);
+        }
+        return path;
+    }
 }



Mime
View raw message