cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r634986 - in /cocoon/whiteboard/micro/core: cocoon-core/src/main/java/org/apache/cocoon/servlet/ cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/ cocoon-core/src/main/java/org/apache/cocoon/sitemap/ cocoon-pipeline/cocoon-pipe...
Date Sat, 08 Mar 2008 15:16:23 GMT
Author: gkossakowski
Date: Sat Mar  8 07:16:21 2008
New Revision: 634986

URL: http://svn.apache.org/viewvc?rev=634986&view=rev
Log:
Simplified dependencies between classes:
  * SitemapServlet does not depend on RequestUtil anymore
  * HttpEnvironment is more self-contained (calculates URI for its own)

Cleaned up RequestUtil:
  * removed getCompleteBlockUri() method which duplicated functionality from SSF
  * removed support for special redirections (handled by SSF as well)
  * removed uri parameter from other methods, RequestUtil can calculate this on its own

Modified:
    cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
    cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
    cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java
    cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
    cocoon/whiteboard/micro/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/environment/http/HttpEnvironment.java

Modified: cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java?rev=634986&r1=634985&r2=634986&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
(original)
+++ cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
Sat Mar  8 07:16:21 2008
@@ -137,17 +137,9 @@
             res.addHeader("X-Cocoon-Version", Constants.VERSION);
         }
 
-        // We got it... Process the request
-        final String uri = getURI(request, res);
-        if (uri == null) {
-            // a redirect occured, so we are finished
-            return;
-        }
-
         Environment env;
         try{
-            // Pass uri into environment without URLDecoding, as it is already decoded.
-            env = getEnvironment(uri, request, res);
+            env = getEnvironment(request, res);
         } catch (Exception e) {
             if (getLogger().isErrorEnabled()) {
                 getLogger().error("Problem with Cocoon servlet", e);
@@ -157,10 +149,10 @@
                 throw new ServletException(e);
             }
 
-            RequestUtil.manageException(request, res, null, uri,
-                                        HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
-                                        "Problem in creating the Environment", null, null,
e,
-                                        this.servletSettings, getLogger(), this);
+            RequestUtil.manageException(request, res, null, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                                        "Problem in creating the Environment",
+                                        null, null, e, this.servletSettings,
+                                        getLogger(), this);
             return;
         }
 
@@ -177,13 +169,13 @@
                     throw new ServletException("The Cocoon engine failed to process the request.");
                 }
 
-                RequestUtil.manageException(request, res, env, uri,
-                                            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                RequestUtil.manageException(request, res, env, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                                             "Request Processing Failed",
                                             "Cocoon engine failed in processing the request",
                                             "The processing engine failed to process the
request. This could be due to lack of matching or bugs in the pipeline engine.",
                                             null,
-                                            this.servletSettings, getLogger(), this);
+                                            this.servletSettings,
+                                            getLogger(), this);
                 return;
             }
         } catch (ResourceNotFoundException e) {
@@ -197,13 +189,13 @@
                 throw new ServletException(e);
             }
 
-            RequestUtil.manageException(request, res, env, uri,
-                                        HttpServletResponse.SC_NOT_FOUND,
+            RequestUtil.manageException(request, res, env, HttpServletResponse.SC_NOT_FOUND,
                                         "Resource Not Found",
                                         "Resource Not Found",
                                         "The requested resource \"" + request.getRequestURI()
+ "\" could not be found",
                                         e,
-                                        this.servletSettings, getLogger(), this);
+                                        this.servletSettings,
+                                        getLogger(), this);
             return;
 
         } catch (ConnectionResetException e) {
@@ -230,10 +222,10 @@
                 throw new ServletException(e);
             }
 
-            RequestUtil.manageException(request, res, env, uri,
-                                        HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
-                                        "Internal Server Error", null, null, e,
-                                        this.servletSettings, getLogger(), this);
+            RequestUtil.manageException(request, res, env, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                                        "Internal Server Error",
+                                        null, null, e, this.servletSettings,
+                                        getLogger(), this);
             return;
         }
 
@@ -241,7 +233,7 @@
         String timeString = null;
         if (getLogger().isInfoEnabled()) {
             timeString = processTime(stopWatch.getTime());
-            getLogger().info("'" + uri + "' " + timeString);
+            getLogger().info("'" + env.getURI() + "' " + timeString);
         }
 
         if (contentType != null && contentType.equals("text/html")) {
@@ -291,8 +283,7 @@
     /**
      * Create the environment for the request
      */
-    protected Environment getEnvironment(String uri,
-                                         HttpServletRequest req,
+    protected Environment getEnvironment(HttpServletRequest req,
                                          HttpServletResponse res)
     throws Exception {
 
@@ -302,8 +293,7 @@
         }
 
         HttpEnvironment env;
-        env = new HttpEnvironment(uri,
-                                  req,
+        env = new HttpEnvironment(req,
                                   res,
                                   this.servletContext,
                                   this.environmentContext,

Modified: cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java?rev=634986&r1=634985&r2=634986&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
(original)
+++ cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
Sat Mar  8 07:16:21 2008
@@ -60,76 +60,12 @@
             uri += pathInfo;
         }
 
-        if (uri.length() == 0) {
-            /*
-             * Empty relative URI. Issue HTTP redirect from '/block' to '/block/' to
-             * avoid breaking relative URIs in the response generated by the sitemap
-             * which expects to be mounted at '.../'.
-             */
-            String serverAbsoluteUri = request.getRequestURI();
-            if (serverAbsoluteUri == null) {
-                serverAbsoluteUri = "/";
-            } else {
-                serverAbsoluteUri += "/";
-            }
-
-            response.sendRedirect(response.encodeRedirectURL(serverAbsoluteUri));
-            return null;
-        }
-
         if (uri.charAt(0) == '/') {
             uri = uri.substring(1);
         }
         return uri;
     }
 
-    /**
-     * Same as {@link #getCompleteUri(HttpServletRequest, HttpServletResponse)} but
-     * disregards {@link HttpServletRequest#getServletPath()}.
-     *
-     * <br>Used by {@link SitemapServlet}.
-     */
-    public static String getCompleteBlockUri(HttpServletRequest request,
-                                             HttpServletResponse response)
-    throws IOException {
-        // The original implementation prepend the servlet context path which doesn't work
-        // in the tree processor if there actually is a servlet context path
-        // VG: ...but still need to know if servlet path had a '/' at the end
-        //     (in case if path info is empty, need to know whether to issue a redirect or
not)
-        String servletPath = request.getServletPath();
-        if (servletPath == null) {
-            servletPath = "";
-        }
-
-        String uri = request.getPathInfo();
-        if (uri == null) {
-            uri = "";
-        }
-
-        if (uri.length() == 0 && !servletPath.endsWith("/")) {
-            /*
-             * Empty relative URI. Issue HTTP redirect from '/block' to '/block/' to
-             * avoid breaking relative URIs in the response generated by the sitemap
-             * which expects to be mounted at '.../'.
-             */
-            String serverAbsoluteUri = request.getRequestURI();
-            if (serverAbsoluteUri == null) {
-                serverAbsoluteUri = "/";
-            } else {
-                serverAbsoluteUri += "/";
-            }
-
-            response.sendRedirect(response.encodeRedirectURL(serverAbsoluteUri));
-            return null;
-        }
-
-        if (uri.length() > 0 && uri.charAt(0) == '/') {
-            return uri.substring(1);
-        }
-
-        return uri;
-    }
-
     public static HttpServletRequest createRequestForUri(HttpServletRequest request, String
servletPath, String pathInfo) {
         return new UriHttpServletRequestWrapper(request, servletPath, pathInfo);
     }
@@ -152,7 +88,6 @@
     public static void manageException(HttpServletRequest  req,
                                        HttpServletResponse res,
                                        Environment         env,
-                                       String              uri,
                                        int                 errorStatus,
                                        String              title,
                                        String              message,
@@ -162,13 +97,12 @@
                                        Log                 logger,
                                        Object              sender)
     throws IOException {
-        manageException(req, res, env, uri, errorStatus, title, message, description, e,
settings, logger.isInfoEnabled(), sender);
+        manageException(req, res, env, errorStatus, title, message, description, e, settings,
logger.isInfoEnabled(), sender);
     }
 
     private static void manageException(HttpServletRequest  req,
                                         HttpServletResponse res,
                                         Environment         env,
-                                        String              uri,
                                         int                 errorStatus,
                                         String              title,
                                         String              message,
@@ -179,6 +113,7 @@
                                         Object              sender)
     throws IOException {
         if (settings.isManageExceptions()) {
+            String uri = getCompleteUri(req, res);
             if (env != null) {
                 env.tryResetResponse();
             } else {

Modified: cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java?rev=634986&r1=634985&r2=634986&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java
(original)
+++ cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java
Sat Mar  8 07:16:21 2008
@@ -122,10 +122,10 @@
                     getLogger().error("Problem in multipart filter. Unable to create request.",
e);
                 }
 
-                RequestUtil.manageException(request, response, null, null,
-                                            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                RequestUtil.manageException(request, response, null, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                                             "Problem in creating the Request",
-                                            null, null, e, this.servletSettings, getLogger(),
this);
+                                            null,
+                                            null, e, this.servletSettings, getLogger(), this);
             }
 
             filterChain.doFilter(request, response);

Modified: cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java?rev=634986&r1=634985&r2=634986&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
(original)
+++ cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
Sat Mar  8 07:16:21 2008
@@ -26,7 +26,6 @@
 
 import org.apache.cocoon.Processor;
 import org.apache.cocoon.components.treeprocessor.TreeProcessor;
-import org.apache.cocoon.servlet.RequestUtil;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.beans.factory.BeanFactoryAware;
@@ -76,14 +75,6 @@
         protected Processor getProcessor() {
             return (Processor) SitemapServlet.this.beanFactory.getBean(Processor.ROLE);
         }
-
-        /**
-         * @see org.apache.cocoon.servlet.RequestProcessor#getURI(HttpServletRequest, HttpServletResponse)
-         */
-        protected String getURI(HttpServletRequest request, HttpServletResponse response)
throws IOException {
-            return RequestUtil.getCompleteBlockUri(request, response);
-        }
-
 
     }
 

Modified: cocoon/whiteboard/micro/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/environment/http/HttpEnvironment.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/environment/http/HttpEnvironment.java?rev=634986&r1=634985&r2=634986&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/environment/http/HttpEnvironment.java
(original)
+++ cocoon/whiteboard/micro/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/environment/http/HttpEnvironment.java
Sat Mar  8 07:16:21 2008
@@ -23,6 +23,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.cocoon.configuration.Settings;
 import org.apache.cocoon.environment.AbstractEnvironment;
 import org.apache.cocoon.environment.Context;
 import org.apache.cocoon.environment.ObjectModelHelper;
@@ -38,29 +39,38 @@
     public static final String HTTP_REQUEST_OBJECT = "httprequest";
     public static final String HTTP_RESPONSE_OBJECT= "httpresponse";
     public static final String HTTP_SERVLET_CONTEXT= "httpservletcontext";
+    
+    /** The HttpServletRequest */
+    private HttpServletRequest rawRequest;
+    
+    /** The HttpServletResponse */
+    private HttpServletResponse rawResponse;
 
-    /** The HttpRequest */
+    /** The (Cocoon) HttpRequest */
     private HttpRequest request;
 
-    /** The HttpResponse */
+    /** The (Cocoon) HttpResponse */
     private HttpResponse response;
 
     /** Cache content type as there is no getContentType() in reponse object */
     private String contentType;
+    
+    private Settings settings;
+    
+    private ServletContext servletContext;
 
     /**
      * Constructs a HttpEnvironment object from a HttpServletRequest
      * and HttpServletResponse objects
      */
-    public HttpEnvironment(String uri,
-                           HttpServletRequest req,
+    public HttpEnvironment(HttpServletRequest req,
                            HttpServletResponse res,
                            ServletContext servletContext,
                            Context context,
                            String containerEncoding,
                            String defaultFormEncoding)
     throws IOException {
-        super(uri, null, null);
+        super(getCompleteUri(req, res), null, null);
 
         this.request = new HttpRequest(req, this);
         this.request.setCharacterEncoding(defaultFormEncoding);
@@ -81,6 +91,43 @@
         this.objectModel.put(HTTP_RESPONSE_OBJECT, res);
         this.objectModel.put(HTTP_SERVLET_CONTEXT, servletContext);
     }
+    
+    public HttpEnvironment() { 
+        super(null, null);
+    };
+    
+    public void init() throws Exception {
+        this.uri = getCompleteUri(rawRequest, rawResponse);
+        
+        this.request = new HttpRequest(rawRequest, this);
+        this.response = new HttpResponse(rawResponse);
+        
+        String formEncoding = request.getParameter("cocoon-form-encoding");
+        if (formEncoding == null) {
+            formEncoding = this.settings.getFormEncoding();
+        }
+        this.request.setCharacterEncoding(formEncoding);
+        
+        String containerEncoding = this.settings.getContainerEncoding();
+        if (containerEncoding == null) {
+            containerEncoding = "ISO-8859-1";
+        }
+        this.request.setContainerEncoding(containerEncoding);
+        
+        setView(extractView(this.request));
+        setAction(extractAction(this.request));
+        
+        this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT, this.request);
+        this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT, this.response);
+        this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT, new HttpContext(this.servletContext));
+        
+        // This is a kind of a hack for the components that need
+        // the real servlet objects to pass them along to other
+        // libraries.
+        this.objectModel.put(HTTP_REQUEST_OBJECT, this.rawRequest);
+        this.objectModel.put(HTTP_RESPONSE_OBJECT, this.rawResponse);
+        this.objectModel.put(HTTP_SERVLET_CONTEXT, this.servletContext);
+    }
 
     /**
      *  Redirect the client to new URL
@@ -218,5 +265,53 @@
      */
     public boolean isExternal() {
         return true;
+    }
+    
+    
+    //FIXME: Move this method somewhere else, it's been moved from RequestUtil class
+    protected static String getCompleteUri(HttpServletRequest request,
+            HttpServletResponse response)
+    throws IOException {
+//      Start with servlet path
+        String uri = request.getServletPath();
+//      uri should never be null, but we check it anyway
+        if (uri == null) {
+            uri = "";
+        }
+
+        String pathInfo = request.getPathInfo();
+        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);
+            }
+            uri += pathInfo;
+        }
+
+        if (uri.length() == 0) {
+            /*
+             * Empty relative URI. Issue HTTP redirect from '/block' to '/block/' to
+             * avoid breaking relative URIs in the response generated by the sitemap
+             * which expects to be mounted at '.../'.
+             */
+            String serverAbsoluteUri = request.getRequestURI();
+            if (serverAbsoluteUri == null) {
+                serverAbsoluteUri = "/";
+            } else {
+                serverAbsoluteUri += "/";
+            }
+
+            response.sendRedirect(response.encodeRedirectURL(serverAbsoluteUri));
+            return null;
+        }
+
+        if (uri.charAt(0) == '/') {
+            uri = uri.substring(1);
+        }
+        return uri;
     }
 }



Mime
View raw message