cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r421911 - /cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
Date Fri, 14 Jul 2006 13:59:10 GMT
Author: cziegeler
Date: Fri Jul 14 06:59:09 2006
New Revision: 421911

URL: http://svn.apache.org/viewvc?rev=421911&view=rev
Log:
Update implementation of new request wrapper

Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java?rev=421911&r1=421910&r2=421911&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
Fri Jul 14 06:59:09 2006
@@ -33,6 +33,7 @@
     throws IOException {
         // We got it... Process the request
         String uri = request.getServletPath();
+        // uri should never be null, but we check it anyway
         if (uri == null) {
             uri = "";
         }
@@ -40,6 +41,9 @@
         if (pathInfo != null) {
             // VG: WebLogic fix: Both uri and pathInfo starts with '/'
             // This problem exists only in WL6.1sp2, not in WL6.0sp2 or WL7.0b.
+            // Comment: The servletPath always starts with '/', so it seems
+            //          that the above mentioned bug is only occuring if the servlet path
+            //          is just a "/".
             if (uri.length() > 0 && uri.charAt(0) == '/') {
                 uri = uri.substring(1);
             }
@@ -53,12 +57,14 @@
                     "".charAt(0)
                else process URI normally
             */
-            String prefix = request.getRequestURI();
-            if (prefix == null) {
-                prefix = "";
+            String serverAbsoluteUri = request.getRequestURI();
+            if (serverAbsoluteUri == null) {
+                serverAbsoluteUri = "/";
+            } else {
+                serverAbsoluteUri += "/";
             }
 
-            response.sendRedirect(response.encodeRedirectURL(prefix + "/"));
+            response.sendRedirect(response.encodeRedirectURL(serverAbsoluteUri));
             return null;
         }
 
@@ -68,35 +74,84 @@
         return uri;
     }
 
-    public static HttpServletRequest createRequestForUri(HttpServletRequest request, String
uri) {
-        return new HttpServletRequestImpl(request, uri);
+    public static HttpServletRequest createRequestForUri(HttpServletRequest request, String
servletPath, String pathInfo) {
+        return new HttpServletRequestImpl(request, servletPath, pathInfo);
     }
 
-    /** TODO - we have to check the return values with the servlet spec! */
     protected static final class HttpServletRequestImpl extends HttpServletRequestWrapper
{
 
+        final private String servletPath;
+
+        final private String pathInfo;
+
         final private String uri;
 
-        public HttpServletRequestImpl(HttpServletRequest request, String uri) {
+        public HttpServletRequestImpl(HttpServletRequest request, String servletPath, String
pathInfo) {
             super(request);
-            this.uri = uri;
+            this.servletPath = servletPath;
+            this.pathInfo = pathInfo;
+            final StringBuffer buffer = new StringBuffer();
+            if ( request.getContextPath() != null ) {
+                buffer.append(request.getContextPath());
+            }
+            if ( buffer.length() == 1 && buffer.charAt(0) == '/' ) {
+                buffer.deleteCharAt(0);
+            }
+            if ( servletPath != null ) {
+                buffer.append(servletPath);
+            }
+            if ( pathInfo != null ) {
+                buffer.append(pathInfo);
+            }
+            if ( buffer.charAt(0) != '/' ) {
+                buffer.insert(0, '/');
+            }
+            this.uri = buffer.toString();
+            
         }
 
+        /**
+         * @see javax.servlet.http.HttpServletRequestWrapper#getPathInfo()
+         */
         public String getPathInfo() {
-            return this.uri;
+            return this.pathInfo;
         }
 
+        /**
+         * @see javax.servlet.http.HttpServletRequestWrapper#getRequestURI()
+         */
         public String getRequestURI() {
             return this.uri;
         }
 
+        /**
+         * @see javax.servlet.http.HttpServletRequestWrapper#getRequestURL()
+         */
         public StringBuffer getRequestURL() {
-            return new StringBuffer(this.uri);
+            final StringBuffer buffer = new StringBuffer();
+            buffer.append(this.getProtocol());
+            buffer.append("://");
+            buffer.append(this.getServerName());
+            boolean appendPort = true;
+            if ( this.getScheme().equals("http") && this.getServerPort() == 80 )
{
+                appendPort = false;
+            }
+            if ( this.getScheme().equals("https") && this.getServerPort() == 443)
{
+                appendPort = false;
+            }
+            if ( appendPort ) {
+                buffer.append(':');
+                buffer.append(this.getServerPort());
+            }
+            buffer.append(this.uri);
+            return buffer;
         }
 
+        /**
+         * @see javax.servlet.http.HttpServletRequestWrapper#getServletPath()
+         */
         public String getServletPath() {
-            return null;
+            return this.servletPath;
         }
-
     }
 }



Mime
View raw message