You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2007/10/24 02:50:15 UTC

svn commit: r587721 - in /cocoon/trunk/core/cocoon-core/src: main/java/org/apache/cocoon/servlet/ main/java/org/apache/cocoon/servlet/multipart/ main/java/org/apache/cocoon/sitemap/ test/java/org/apache/cocoon/core/container/

Author: vgritsenko
Date: Tue Oct 23 17:50:13 2007
New Revision: 587721

URL: http://svn.apache.org/viewvc?rev=587721&view=rev
Log:
AvalonUtils.LOGGER_ROLE is gone.
Cleanup.
Access log.

Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/ServletSettings.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/SitemapServlet.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
    cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java?rev=587721&r1=587720&r2=587721&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java Tue Oct 23 17:50:13 2007
@@ -17,36 +17,36 @@
 package org.apache.cocoon.servlet;
 
 import java.io.IOException;
-
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.avalon.framework.logger.Logger;
+import org.apache.commons.lang.time.StopWatch;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
 import org.apache.cocoon.ConnectionResetException;
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.Processor;
 import org.apache.cocoon.RequestListener;
 import org.apache.cocoon.ResourceNotFoundException;
 import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
+import org.apache.cocoon.core.container.spring.logger.LoggerUtils;
 import org.apache.cocoon.environment.Context;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.http.HttpContext;
 import org.apache.cocoon.environment.http.HttpEnvironment;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
-import org.apache.commons.lang.time.StopWatch;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.web.context.support.WebApplicationContextUtils;
+import org.apache.cocoon.util.AbstractLogEnabled;
 
 /**
  * This is the entry point for Cocoon execution as an HTTP Servlet.
  *
  * @version $Id$
  */
-public class RequestProcessor {
+public class RequestProcessor extends AbstractLogEnabled {
 
     // Processing time message
     protected static final String PROCESSED_BY = "Processed by Apache Cocoon in ";
@@ -65,9 +65,6 @@
     /** Configured servlet container encoding. Defaults to ISO-8859-1. */
     protected final String containerEncoding;
 
-    /** The access logger. */
-    protected final Logger log;
-
     /** Root Cocoon Bean Factory. */
     protected final BeanFactory cocoonBeanFactory;
 
@@ -90,6 +87,7 @@
     public RequestProcessor(ServletContext servletContext) {
         this.servletContext = servletContext;
         this.cocoonBeanFactory = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
+
         this.settings = (Settings) this.cocoonBeanFactory.getBean(Settings.ROLE);
         this.servletSettings = new ServletSettings(this.settings);
 
@@ -101,8 +99,11 @@
         }
 
         // Obtain access logger
-        // FIXME This used to be configurable via "servlet-logger" parameter in web.xml
-        this.log = ((Logger) this.cocoonBeanFactory.getBean(AvalonUtils.LOGGER_ROLE)).getChildLogger("access");
+        String category = servletContext.getInitParameter("org.apache.cocoon.servlet.logger.access");
+        if (category == null || category.length() == 0) {
+            category = "access";
+        }
+        setLogger(LoggerUtils.getChildLogger(this.cocoonBeanFactory, category));
 
         this.processor = getProcessor();
         this.environmentContext = new HttpContext(this.servletContext);
@@ -173,19 +174,19 @@
             } else {
                 // We reach this when there is nothing in the processing change that matches
                 // the request. For example, no matcher matches.
-                getLogger().fatalError("The Cocoon engine failed to process the request.");
+                getLogger().fatal("The Cocoon engine failed to process the request.");
 
                 if (rethrowExceptions()) {
                     throw new ServletException("The Cocoon engine failed to process the request.");
                 }
 
                 RequestUtil.manageException(request, res, env, uri,
-                                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, this.getLogger(), this);
+                                            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);
                 return;
             }
         } catch (ResourceNotFoundException e) {
@@ -200,12 +201,12 @@
             }
 
             RequestUtil.manageException(request, res, env, uri,
-                            HttpServletResponse.SC_NOT_FOUND,
-                            "Resource Not Found",
-                            "Resource Not Found",
-                            "The requested resource \"" + request.getRequestURI() + "\" could not be found",
-                            e,
-                            this.servletSettings, this.getLogger(), this);
+                                        HttpServletResponse.SC_NOT_FOUND,
+                                        "Resource Not Found",
+                                        "Resource Not Found",
+                                        "The requested resource \"" + request.getRequestURI() + "\" could not be found",
+                                        e,
+                                        this.servletSettings, getLogger(), this);
             return;
 
         } catch (ConnectionResetException e) {
@@ -233,9 +234,9 @@
             }
 
             RequestUtil.manageException(request, res, env, uri,
-                            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
-                            "Internal Server Error", null, null, e,
-                            this.servletSettings, this.getLogger(), this);
+                                        HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                                        "Internal Server Error", null, null, e,
+                                        this.servletSettings, getLogger(), this);
             return;
         }
 
@@ -330,10 +331,6 @@
             out.append(" hours.");
         }
         return out.toString();
-    }
-
-    protected Logger getLogger() {
-        return this.log;
     }
 
     /**

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=587721&r1=587720&r2=587721&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 Tue Oct 23 17:50:13 2007
@@ -19,11 +19,11 @@
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
-
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.avalon.framework.logger.Logger;
+import org.apache.commons.logging.Log;
+
 import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
 import org.apache.cocoon.components.notification.Notifier;
 import org.apache.cocoon.components.notification.Notifying;
@@ -112,24 +112,24 @@
                                        String              description,
                                        Exception           e,
                                        ServletSettings     settings,
-                                       Logger              logger,
+                                       Log                 logger,
                                        Object              sender)
     throws IOException {
         manageException(req, res, env, uri, errorStatus, title, message, description, e, settings, logger.isInfoEnabled(), sender);
     }
 
-    public static void manageException(HttpServletRequest  req,
-                                       HttpServletResponse res,
-                                       Environment         env,
-                                       String              uri,
-                                       int                 errorStatus,
-                                       String              title,
-                                       String              message,
-                                       String              description,
-                                       Exception           e,
-                                       ServletSettings     settings,
-                                       boolean             verbose,
-                                       Object              sender)
+    private static void manageException(HttpServletRequest  req,
+                                        HttpServletResponse res,
+                                        Environment         env,
+                                        String              uri,
+                                        int                 errorStatus,
+                                        String              title,
+                                        String              message,
+                                        String              description,
+                                        Exception           e,
+                                        ServletSettings     settings,
+                                        boolean             verbose,
+                                        Object              sender)
     throws IOException {
         if (settings.isManageExceptions()) {
             if (env != null) {

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/ServletSettings.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/ServletSettings.java?rev=587721&r1=587720&r2=587721&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/ServletSettings.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/ServletSettings.java Tue Oct 23 17:50:13 2007
@@ -21,8 +21,9 @@
 
 /**
  * Helper class for managing Cocoon servlet specific settings.
- * @version $Id$
+ * 
  * @since 2.2
+ * @version $Id$
  */
 public class ServletSettings {
 
@@ -47,17 +48,20 @@
      */
     public static String KEY_MANAGE_EXCEPTIONS = "org.apache.cocoon.manageexceptions";
 
-    /** Default value for {@link Settings#isManageExceptions()}. */
-    public static final boolean MANAGE_EXCEPTIONS = true;
 
+    /** Default value for {@link #KEY_SHOWTIME} parameter (false). */
     public static final boolean SHOW_TIME = false;
+
+    /** Default value for {@link #KEY_HIDE_SHOWTIME} parameter (false). */
     public static final boolean HIDE_SHOW_TIME = false;
 
-    /**
-     * Default value for {@link Settings#isShowVersion()} parameter (true).
-     */
+    /** Default value for {@link #KEY_SHOW_VERSION} parameter (true). */
     public static final boolean SHOW_COCOON_VERSION = true;
 
+    /** Default value for {@link #KEY_MANAGE_EXCEPTIONS} parameter (true). */
+    public static final boolean MANAGE_EXCEPTIONS = true;
+
+
     /**
      * Allow adding processing time to the response
      */
@@ -79,28 +83,30 @@
      */
     protected boolean manageExceptions;
 
+    
     public ServletSettings(Settings s) {
         // set defaults
         this.showTime = SHOW_TIME;
         this.hideShowTime = HIDE_SHOW_TIME;
         this.showCocoonVersion = SHOW_COCOON_VERSION;
         this.manageExceptions = MANAGE_EXCEPTIONS;
-        if ( s != null ) {
+
+        if (s != null) {
             String value;
             value = s.getProperty(KEY_SHOWTIME);
-            if ( value != null ) {
+            if (value != null) {
                 this.setShowTime(BooleanUtils.toBoolean(value));
             }
             value = s.getProperty(KEY_HIDE_SHOWTIME);
-            if ( value != null ) {
+            if (value != null) {
                 this.setHideShowTime(BooleanUtils.toBoolean(value));
             }
             value = s.getProperty(KEY_SHOW_VERSION);
-            if ( value != null ) {
+            if (value != null) {
                 this.setShowCocoonVersion(BooleanUtils.toBoolean(value));
             }
             value = s.getProperty(KEY_MANAGE_EXCEPTIONS);
-            if ( value != null ) {
+            if (value != null) {
                 this.setManageExceptions(BooleanUtils.toBoolean(value));
             }
         }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/SitemapServlet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/SitemapServlet.java?rev=587721&r1=587720&r2=587721&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/SitemapServlet.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/SitemapServlet.java Tue Oct 23 17:50:13 2007
@@ -36,6 +36,7 @@
     /** The Cocoon request processor. */
     protected RequestProcessor processor;
 
+
     public void service(HttpServletRequest req, HttpServletResponse res)
     throws ServletException, IOException {
         this.processor.service(req, res);
@@ -46,6 +47,6 @@
      */
     public void init() throws ServletException {
         super.init();
-        this.processor = new RequestProcessor(this.getServletContext());
+        this.processor = new RequestProcessor(getServletContext());
     }
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java?rev=587721&r1=587720&r2=587721&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java Tue Oct 23 17:50:13 2007
@@ -124,7 +124,7 @@
             RequestUtil.manageException(request, response, null, null,
                                         HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                                         "Problem in creating the Request",
-                                        null, null, e, this.servletSettings, getLogger().isInfoEnabled(), this);
+                                        null, null, e, this.servletSettings, getLogger(), this);
         } finally {
             try {
                 if (request instanceof MultipartHttpServletRequest) {
@@ -138,5 +138,4 @@
             }
         }
     }
-
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java?rev=587721&r1=587720&r2=587721&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java Tue Oct 23 17:50:13 2007
@@ -77,8 +77,6 @@
         private static final String DEFAULT_SITEMAP_PATH = "/sitemap.xmap";
         private static final String SITEMAP_PATH_PROPERTY = "sitemapPath";
 
-        private Configuration treeProcessorConfiguration;
-
         public RequestProcessor(ServletContext servletContext) {
             super(servletContext);
         }
@@ -88,17 +86,18 @@
         }
 
         protected Processor getProcessor() {
+            // read tree processor configuration
+            Configuration processorConfig;
             ServiceManager serviceManager =
                 (ServiceManager) this.cocoonBeanFactory.getBean(AvalonUtils.SERVICE_MANAGER_ROLE);
             try {
-                this.treeProcessorConfiguration =
-                    this.createTreeProcessorConfiguration(this.servletContext);
+                processorConfig = createTreeProcessorConfiguration(this.servletContext);
             } catch (IOException e) {
                 throw new BeanCreationException("Could not create configuration for TreeProcesoor", e);
             }
 
-            Processor processor;
             // create the tree processor
+            Processor processor;
             try {
                 TreeProcessor treeProcessor = new TreeProcessor();
                 // TODO (DF/RP) The treeProcessor doesn't need to be a managed component at all.
@@ -106,7 +105,7 @@
                                                                        getLogger(),
                                                                        null,
                                                                        serviceManager,
-                                                                       this.treeProcessorConfiguration);
+                                                                       processorConfig);
             } catch (Exception e) {
                 throw new BeanCreationException("Could not create TreeProcessor", e);
             }
@@ -128,12 +127,15 @@
         // in the tree processor if there actually is a servlet context path
         protected String getURI(HttpServletRequest request, HttpServletResponse res) throws IOException {
             String uri = request.getPathInfo();
-            if (uri == null)
+            if (uri == null) {
                 return "";
-            else if (uri.length() > 0 && uri.charAt(0) == '/')
+            }
+
+            if (uri.length() > 0 && uri.charAt(0) == '/') {
                 return uri.substring(1);
-            else
-                return uri;
+            }
+
+            return uri;
         }
 
         /**
@@ -147,13 +149,15 @@
             // just providing a relative uri relative to the current context is not enough
             // and doesn't work
             String sitemapPath = servletContext.getInitParameter(SITEMAP_PATH_PROPERTY);
-            if (sitemapPath== null)
-                sitemapPath= DEFAULT_SITEMAP_PATH;
+            if (sitemapPath == null) {
+                sitemapPath = DEFAULT_SITEMAP_PATH;
+            }
 
             String sitemapURI;
             URL uri = servletContext.getResource(sitemapPath);
-            if (uri == null)
+            if (uri == null) {
                 throw new IOException("Couldn't find the sitemap " + sitemapPath);
+            }
             sitemapURI = uri.toExternalForm();
 
             DefaultConfiguration treeProcessorConf = new DefaultConfiguration("treeProcessorConfiguration");

Modified: cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java?rev=587721&r1=587720&r2=587721&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java (original)
+++ cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java Tue Oct 23 17:50:13 2007
@@ -38,6 +38,11 @@
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.core.io.DefaultResourceLoader;
+
 import org.apache.cocoon.AbstractTestCase;
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.core.container.spring.avalon.AvalonBeanPostProcessor;
@@ -45,11 +50,10 @@
 import org.apache.cocoon.core.container.spring.avalon.BridgeElementParser;
 import org.apache.cocoon.core.container.spring.avalon.ConfigurationInfo;
 import org.apache.cocoon.core.container.spring.avalon.ConfigurationReader;
+import org.apache.cocoon.core.container.spring.logger.LoggerFactoryBean;
+import org.apache.cocoon.core.container.spring.logger.LoggerUtils;
 import org.apache.cocoon.environment.mock.MockContext;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.beans.factory.support.RootBeanDefinition;
-import org.springframework.core.io.DefaultResourceLoader;
+
 import org.w3c.dom.Element;
 
 /**
@@ -242,7 +246,7 @@
     /**
      * Disposes the <code>ComponentLocator</code>
      */
-    final private void done() {
+    private void done() {
         this.manager = null;
         this.context = null;
         this.logger = null;
@@ -255,7 +259,7 @@
      * A method addContext(DefaultContext context) is called here to enable subclasses
      * to put additional objects into the context programmatically.
      */
-    final private Map setupContext( final Configuration conf )
+    private Map setupContext( final Configuration conf )
     throws Exception {
         final Map defaultContext = new HashMap();
         final Configuration[] confs = conf.getChildren( "entry" );
@@ -309,8 +313,8 @@
         // subclasses can add components here
     }
 
-    final private void setupBeanFactory( final Configuration confCM,
-                                         final Configuration confRM)
+    private void setupBeanFactory( final Configuration confCM,
+                                   final Configuration confRM)
     throws Exception {
         // read roles and components
         ConfigurationInfo rolesInfo = ConfigurationReader.readConfiguration(confRM, confCM);
@@ -320,7 +324,6 @@
         aep.createComponents(null, rolesInfo, (BeanDefinitionRegistry) this.getBeanFactory(),  null, new DefaultResourceLoader());
 
         AvalonBeanPostProcessor postProcessor = new AvalonBeanPostProcessor();
-        postProcessor.setLogger(new ConsoleLogger());
         postProcessor.setContext(this.context);
         postProcessor.setConfigurationInfo(rolesInfo);
         postProcessor.setBeanFactory(this.getBeanFactory());
@@ -407,7 +410,7 @@
          * @see org.apache.cocoon.core.container.spring.avalon.BridgeElementParser#addLogger(org.springframework.beans.factory.support.BeanDefinitionRegistry, java.lang.String)
          */
         protected void addLogger(BeanDefinitionRegistry registry, String loggerCategory) {
-            this.addComponent(ConsoleLogger.class, AvalonUtils.LOGGER_ROLE, null, false, registry);
+            addComponent(LoggerFactoryBean.class, LoggerUtils.LOGGER_ROLE, null, false, registry);
         }
     }