FELIX-918 : Add utility method for making relative redirects absolute.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@741116 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
index 46784b2..135e8af 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
@@ -300,4 +300,31 @@
         // no valid string parameter, fail
         return null;
     }
+
+    /**
+     * Utility method to handle relative redirects.
+     * Some app servers like web sphere handle relative redirects differently
+     * therefore we should make an absolute url before invoking send redirect.
+     */
+    protected void sendRedirect(final HttpServletRequest request,
+                                final HttpServletResponse response,
+                                String redirectUrl) throws IOException {
+        // check for relative url
+        if ( !redirectUrl.startsWith("/") ) {
+            String base = request.getContextPath() + request.getServletPath() + request.getPathInfo();
+            int i = base.lastIndexOf('/');
+            if (i > -1) {
+                base = base.substring(0, i);
+            } else {
+                i = base.indexOf(':');
+                base = (i > -1) ? base.substring(i + 1, base.length()) : "";
+            }
+            if (!base.startsWith("/")) {
+                base = '/' + base;
+            }
+            redirectUrl = base + '/' + redirectUrl;
+
+        }
+        response.sendRedirect(redirectUrl);
+    }
 }
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ConfigManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ConfigManager.java
index 3e19140..8ba2c03 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ConfigManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ConfigManager.java
@@ -106,7 +106,7 @@
                     redirect += "?" + PID_FILTER + "=" + pidFilter;
                 }
 
-                response.sendRedirect( redirect );
+                this.sendRedirect(request, response, redirect);
             }
 
             return;