jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r691632 - /jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/
Date Wed, 03 Sep 2008 15:19:41 GMT
Author: jukka
Date: Wed Sep  3 08:19:40 2008
New Revision: 691632

URL: http://svn.apache.org/viewvc?rev=691632&view=rev
Log:
JCR-1598: Problematic exception handling in Jackrabbit WebApp 

Added a ServletExceptionWithCause utility class and used it to properly capture chained exceptions.

Minor improvements in exception and log messages.

Added:
    jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/ServletExceptionWithCause.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/AbstractConfig.java
    jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/JcrApiNotFoundException.java
    jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/LoggingServlet.java
    jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
    jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryStartupServlet.java

Modified: jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/AbstractConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/AbstractConfig.java?rev=691632&r1=691631&r2=691632&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/AbstractConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/AbstractConfig.java
Wed Sep  3 08:19:40 2008
@@ -43,8 +43,8 @@
     private BeanMap map = new BeanMap(this);
 
     /**
-     * Initializes the config with values from the given properties
-     * @param props the config properties
+     * Initializes the configuration with values from the given properties
+     * @param props the configuration properties
      */
     public void init(Properties props) throws ServletException {
         Iterator iter = props.keySet().iterator();
@@ -56,8 +56,8 @@
                     map.put(mapName, props.getProperty(name));
                 }
             } catch (Exception e) {
-                log.error("Error in configuration: {}", e.toString());
-                throw new ServletException("Error in configuration: " + e.toString());
+                throw new ServletExceptionWithCause(
+                        "Invalid configuration property: " + name, e);
             }
         }
     }
@@ -72,8 +72,8 @@
                     map.put(mapName, ctx.getInitParameter(name));
                 }
             } catch (Exception e) {
-                log.error("Error in configuration: {}", e.toString());
-                throw new ServletException("Error in configuration: " + e.toString());
+                throw new ServletExceptionWithCause(
+                        "Invalid servlet configuration option: " + name, e);
             }
         }
     }

Modified: jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/JcrApiNotFoundException.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/JcrApiNotFoundException.java?rev=691632&r1=691631&r2=691632&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/JcrApiNotFoundException.java
(original)
+++ jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/JcrApiNotFoundException.java
Wed Sep  3 08:19:40 2008
@@ -16,15 +16,23 @@
  */
 package org.apache.jackrabbit.j2ee;
 
-import javax.servlet.ServletException;
-
 /**
  * Exception for signaling that the JCR API is not available.
  */
-public class JcrApiNotFoundException extends ServletException {
+public class JcrApiNotFoundException extends ServletExceptionWithCause {
+
+    /**
+     * Serial version UID
+     */
+    private static final long serialVersionUID = -6439777923943394980L;
 
+    /**
+     * Creates an exception to signal that the JCR API is not available.
+     *
+     * @param e the specific exception that indicates the lack of the JCR API
+     */
     public JcrApiNotFoundException(ClassNotFoundException e) {
-        super(e);
+        super("JCR API (jcr-1.0.jar) not available in the classpath", e);
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/LoggingServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/LoggingServlet.java?rev=691632&r1=691631&r2=691632&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/LoggingServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/LoggingServlet.java
Wed Sep  3 08:19:40 2008
@@ -102,7 +102,8 @@
             try {
                 in = new FileInputStream(log4jConfig);
             } catch (FileNotFoundException e) {
-                throw new ServletException("Unable to initialize log4j: " + e.toString());
+                throw new ServletExceptionWithCause(
+                        "Log4j configuration not found: " + log4jConfig, e);
             }
         } else {
             // hack for entity resolver
@@ -117,7 +118,8 @@
                 configureProperties(in);
             }
         } catch (IOException e) {
-            throw new ServletException("Unable to initialize log4j: " + e.toString());
+            throw new ServletExceptionWithCause(
+                    "Log4j configuration failure: " + log4jConfig, e);
         } finally {
             try {
                 in.close();
@@ -147,11 +149,11 @@
             Element root =  document.getDocumentElement();
             DOMConfigurator.configure(root);
         } catch (ParserConfigurationException e) {
-            throw new ServletException(
-                    "Unable to create configuration XML parser", e);
+            throw new ServletExceptionWithCause(
+                    "Unable to create XML parser for the configuration", e);
         } catch (SAXException e) {
-            throw new ServletException(
-                    "Configuration file syntax error.", e);
+            throw new ServletExceptionWithCause(
+                    "Configuration file syntax error:" + in.getSystemId(), e);
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java?rev=691632&r1=691631&r2=691632&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
Wed Sep  3 08:19:40 2008
@@ -133,8 +133,8 @@
                         try {
                             in = new FileInputStream(file);
                         } catch (FileNotFoundException e) {
-                            log.error("Error while opening bootstrap properties: {}", e.toString());
-                            throw new ServletException("Error while opening bootstrap properties:
" + e.toString());
+                            throw new ServletExceptionWithCause(
+                                    "Bootstrap configuration not found: " + bstrp, e);
                         }
                     }
                 }
@@ -142,8 +142,8 @@
                     try {
                         bootstrapProps.load(in);
                     } catch (IOException e) {
-                        log.error("Error while loading bootstrap properties: {}", e.toString());
-                        throw new ServletException("Error while loading bootstrap properties:
" + e.toString());
+                        throw new ServletExceptionWithCause(
+                                "Bootstrap configuration failure: " + bstrp, e);
                     } finally {
                         try {
                             in.close();
@@ -160,8 +160,8 @@
             tmpConfig.init(bootstrapProps);
             tmpConfig.validate();
             if (!tmpConfig.isValid()) {
-                log.error("Repository acesss configuration is not valid.");
-                throw new ServletException("Repository access configuration is not valid.");
+                throw new ServletException(
+                        "Repository access configuration is not valid.");
             }
             tmpConfig.logInfos();
             config = tmpConfig;
@@ -207,7 +207,7 @@
             log.info("Acquired repository via JNDI.");
             return r;
         } catch (NamingException e) {
-            log.error("Error while retrieving repository using JNDI (name=" + repositoryName
+ "): " + e);
+            log.error("Error while retrieving repository using JNDI (name={})", repositoryName,
e);
             return null;
         }
     }
@@ -228,16 +228,13 @@
         if (rmiURI == null) {
             return null;
         }
-        log.info("  trying to retrieve repository using rmi. uri=" + rmiURI);
+        log.info("  trying to retrieve repository using rmi. uri={}", rmiURI);
         ClientFactoryDelegater cfd;
         try {
             Class clazz = Class.forName(getServerFactoryDelegaterClass());
             cfd = (ClientFactoryDelegater) clazz.newInstance();
-        } catch (NoClassDefFoundError e) {
-            log.error("Unable to locate RMI ClientRepositoryFactory. jcr-rmi.jar missing?
" + e.toString());
-            return null;
-        } catch (Exception e) {
-            log.error("Unable to locate RMI ClientRepositoryFactory. jcr-rmi.jar missing?"
+ e.toString());
+        } catch (Throwable e) {
+            log.error("Unable to locate RMI ClientRepositoryFactory. Is jcr-rmi.jar missing?",
e);
             return null;
         }
 
@@ -246,7 +243,7 @@
             log.info("Acquired repository via RMI.");
             return r;
         } catch (Exception e) {
-            log.error("Error while retrieving repository using RMI: " + e);
+            log.error("Error while retrieving repository using RMI: {}", rmiURI, e);
             return null;
         }
     }
@@ -261,9 +258,9 @@
 
             if(log.isDebugEnabled()) {
                 if(result!=null) {
-                    log.debug("Got Repository from ServletContext attribute '" + repositoryContextAttributeName
+ "'");
+                    log.debug("Got Repository from ServletContext attribute '{}'", repositoryContextAttributeName);
                 } else {
-                    log.debug("ServletContext attribute '" + repositoryContextAttributeName
+ "' does not provide a Repository");
+                    log.debug("ServletContext attribute '{}' does not provide a Repository",
repositoryContextAttributeName);
                 }
             }
         }

Modified: jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryStartupServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryStartupServlet.java?rev=691632&r1=691631&r2=691632&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryStartupServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryStartupServlet.java
Wed Sep  3 08:19:40 2008
@@ -330,8 +330,8 @@
                     try {
                         in = new FileInputStream(bootstrapConfigFile);
                     } catch (FileNotFoundException e) {
-                        log.error("Error while opening bootstrap properties: {}", e.toString());
-                        throw new ServletException("Error while opening bootstrap properties:
" + e.toString());
+                        throw new ServletExceptionWithCause(
+                                "Bootstrap configuration not found: " + bstrp, e);
                     }
                 }
             }
@@ -339,8 +339,8 @@
                 try {
                     bootstrapProps.load(in);
                 } catch (IOException e) {
-                    log.error("Error while loading bootstrap properties: {}", e.toString());
-                    throw new ServletException("Error while loading bootstrap properties:
" + e.toString());
+                    throw new ServletException(
+                            "Bootstrap configuration failure: " + bstrp, e);
                 } finally {
                     try {
                         in.close();
@@ -384,8 +384,8 @@
         try {
             repHome = new File(config.getRepositoryHome()).getCanonicalFile();
         } catch (IOException e) {
-            log.error("Repository startup configuration invalid: " + e.toString());
-            throw new ServletException("Repository startup configuration invalid: " + e.toString());
+            throw new ServletExceptionWithCause(
+                    "Repository configuration failure: " + config.getRepositoryHome(), e);
         }
         String repConfig = config.getRepositoryConfig();
         InputStream in = getServletContext().getResourceAsStream(repConfig);
@@ -397,8 +397,8 @@
                 try {
                     in = new FileInputStream(new File(repHome, repConfig));
                 } catch (FileNotFoundException e1) {
-                    log.error("Repository startup configuration invalid: " + e1.toString());
-                    throw new ServletException("Repository startup configuration invalid:
" + e.toString());
+                    throw new ServletExceptionWithCause(
+                            "Repository configuration not found: " + repConfig, e);
                 }
             }
         }
@@ -406,7 +406,7 @@
         try {
             repository = createRepository(new InputSource(in), repHome);
         } catch (RepositoryException e) {
-            throw new ServletException("Error while creating repository", e);
+            throw new ServletExceptionWithCause("Error while creating repository", e);
         }
     }
 
@@ -451,7 +451,8 @@
                 jndiContext.bind(jc.getJndiName(), repository);
                 log.info("Repository bound to JNDI with name: " + jc.getJndiName());
             } catch (NamingException e) {
-                throw new ServletException("Unable to bind repository using JNDI.", e);
+                throw new ServletExceptionWithCause(
+                        "Unable to bind repository using JNDI: " + jc.getJndiName(), e);
             }
         }
     }
@@ -490,12 +491,11 @@
             remote = rmf.createRemoteRepository(repository);
         } catch (RemoteException e) {
             log.error("Unable to create RMI repository.", e);
-            throw new ServletException("Unable to create remote repository.", e);
-        } catch (NoClassDefFoundError e) {
-            throw new ServletException("Unable to create RMI repository. jcr-rmi.jar might
be missing.", e);
-        } catch (Exception e) {
-            log.error("Unable to create RMI repository.", e);
-            throw new ServletException("Unable to create RMI repository. jcr-rmi.jar might
be missing.");
+            throw new ServletExceptionWithCause("Unable to create remote repository.", e);
+        } catch (Throwable t) {
+            log.error("Unable to create RMI repository.", t);
+            throw new ServletExceptionWithCause(
+                    "Unable to create RMI repository. jcr-rmi.jar might be missing.", t);
         }
 
         try {
@@ -565,9 +565,11 @@
             }
 
         } catch (RemoteException e) {
-            throw new ServletException("Unable to bind repository via RMI.", e);
+            throw new ServletExceptionWithCause(
+                    "Unable to bind repository via RMI: " + rc.getRmiUri(), e);
         } catch (AlreadyBoundException e) {
-            throw new ServletException("Unable to bind repository via RMI.", e);
+            throw new ServletExceptionWithCause(
+                    "Unable to bind repository via RMI: " + rc.getRmiUri(), e);
         }
     }
 

Added: jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/ServletExceptionWithCause.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/ServletExceptionWithCause.java?rev=691632&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/ServletExceptionWithCause.java
(added)
+++ jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/ServletExceptionWithCause.java
Wed Sep  3 08:19:40 2008
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.j2ee;
+
+import javax.servlet.ServletException;
+
+/**
+ * Utility class that links {@link ServletException} with support for
+ * the exception chaining mechanism in {@link Throwable}.
+ *
+ * @see https://issues.apache.org/jira/browse/JCR-1598
+ */
+public class ServletExceptionWithCause extends ServletException {
+
+    /**
+     * Serial version UID
+     */
+    private static final long serialVersionUID = -7201954529718775444L;
+
+    /**
+     * Creates a servlet exception with the given message and cause.
+     *
+     * @param message exception message
+     * @param cause cause of the exception
+     */
+    public ServletExceptionWithCause(String message, Throwable cause) {
+        super(message, cause);
+        if (getCause() == null) {
+            initCause(cause);
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/ServletExceptionWithCause.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message