incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r587134 - in /incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling: api/ request/ resource/ scripting/ scripting/engines/ servlet/
Date Mon, 22 Oct 2007 16:02:05 GMT
Author: bdelacretaz
Date: Mon Oct 22 09:02:04 2007
New Revision: 587134

URL: http://svn.apache.org/viewvc?rev=587134&view=rev
Log:
SLING-75 - use SlingException instead of Exception in the API

Modified:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceResolver.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestContext.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/MicroslingRequestContext.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/engines/VelocityTemplatesScriptEngine.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceResolver.java?rev=587134&r1=587133&r2=587134&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceResolver.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceResolver.java
Mon Oct 22 09:02:04 2007
@@ -16,8 +16,11 @@
  */
 package org.apache.sling.microsling.api;
 
+import javax.jcr.RepositoryException;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.sling.microsling.api.exceptions.SlingException;
+
 /** Locates the Resource that the current request must process */
 public interface ResourceResolver {
     
@@ -26,5 +29,5 @@
      *  (which is by default the Resource node's JCR path) that
      *  was used to load the Resource
      */
-    Resource getResource(HttpServletRequest request) throws Exception;
+    Resource getResource(HttpServletRequest request) throws SlingException;
 }

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestContext.java?rev=587134&r1=587133&r2=587134&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestContext.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestContext.java
Mon Oct 22 09:02:04 2007
@@ -20,6 +20,7 @@
 import javax.jcr.Session;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.sling.microsling.api.exceptions.SlingException;
 import org.apache.sling.microsling.api.requestparams.RequestParameterMap;
 import org.apache.sling.microsling.helpers.exceptions.MissingRequestAttributeException;
 
@@ -46,10 +47,10 @@
     ServiceLocator getServiceLocator();
 
     /** Acquire a JCR Session if not done yet, and return it */
-    Session getSession() throws RepositoryException;
+    Session getSession() throws SlingException;
 
     /** Get the Resource that the current Request processes, null if not found */
-    Resource getResource() throws Exception;
+    Resource getResource() throws SlingException;
 
     /** TODO does this really belong here? */
     void setResponseContentType(String responseContentType);
@@ -58,7 +59,7 @@
     String getResponseContentType();
 
     /** Return the SlingRequestPathInfo for this request: selectors, extension, suffix, etc.
*/
-    SlingRequestPathInfo getRequestPathInfo();
+    SlingRequestPathInfo getRequestPathInfo() throws SlingException;
 
     /** Return the map of request parameters */
     RequestParameterMap getRequestParameterMap();

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/MicroslingRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/MicroslingRequestContext.java?rev=587134&r1=587133&r2=587134&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/MicroslingRequestContext.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/MicroslingRequestContext.java
Mon Oct 22 09:02:04 2007
@@ -32,8 +32,8 @@
 import org.apache.sling.microsling.api.SlingRequestPathInfo;
 import org.apache.sling.microsling.api.exceptions.SlingException;
 import org.apache.sling.microsling.api.requestparams.RequestParameterMap;
-import org.apache.sling.microsling.request.helpers.SlingRequestParameterMap;
 import org.apache.sling.microsling.request.helpers.MicroslingRequestPathInfo;
+import org.apache.sling.microsling.request.helpers.SlingRequestParameterMap;
 
 /** Additional Request-based info used by for SlingServlets */
 public class MicroslingRequestContext implements SlingRequestContext {
@@ -75,14 +75,18 @@
     }
 
     /** Acquire a JCR Session if not done yet, and return it */
-    public Session getSession() throws RepositoryException {
+    public Session getSession() throws SlingException {
         if(session==null) {
-            session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
+            try {
+                session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
+            } catch(RepositoryException re) {
+                throw new SlingException("Repository.login() failed: " + re.getMessage(),re);
+            }
         }
         return session;
     }
 
-    public Resource getResource() throws Exception {
+    public Resource getResource() throws SlingException {
         if(resource==null) {
             final ResourceResolver rr = (ResourceResolver)serviceLocator.getRequiredService(ResourceResolver.class.getName());
             resource = rr.getResource(request);
@@ -103,15 +107,10 @@
         return servletContext.getMimeType(filename);
     }
 
-    public SlingRequestPathInfo getRequestPathInfo() {
+    public SlingRequestPathInfo getRequestPathInfo() throws SlingException {
         if(requestPathInfo == null) {
             // make sure Resource is resolved, as we need it to compute the path info
-            try {
-                getResource();
-            } catch(Exception e) {
-                // TODO bitten by my own "throws Exception" stuff here ;-)
-                // To fix this, using more specific Exceptions should help
-            }
+            getResource();
             requestPathInfo = new MicroslingRequestPathInfo(resource,request.getPathInfo());
         }
         return requestPathInfo;

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java?rev=587134&r1=587133&r2=587134&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
Mon Oct 22 09:02:04 2007
@@ -16,12 +16,14 @@
  */
 package org.apache.sling.microsling.resource;
 
+import javax.jcr.RepositoryException;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.sling.microsling.api.Resource;
 import org.apache.sling.microsling.api.ResourceMetadata;
 import org.apache.sling.microsling.api.ResourceResolver;
 import org.apache.sling.microsling.api.SlingRequestContext;
+import org.apache.sling.microsling.api.exceptions.SlingException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -33,23 +35,28 @@
 
     private static final Logger log = LoggerFactory.getLogger(MicroslingResourceResolver.class);
   
             
-    public Resource getResource(HttpServletRequest request) throws Exception {
+    public Resource getResource(HttpServletRequest request) throws SlingException {
         final SlingRequestContext ctx = SlingRequestContext.Accessor.getSlingRequestContext(request);
         Resource result = null;
-        
-        final ResourcePathIterator it = new ResourcePathIterator(request.getPathInfo());
-        while(it.hasNext() && result == null) {
-            final String path = it.next();
-            if(log.isDebugEnabled()) {
-                log.debug("Trying to locate Resource at path '" + path + "'");
-            }
-            if (ctx.getSession().itemExists(path)) {
-                result = new JcrNodeResource(ctx.getSession(),path);
-                result.getMetadata().put(ResourceMetadata.RESOLUTION_PATH, path);
-                if(log.isInfoEnabled()) {
-                    log.info("Found Resource at path '" + path + "'");
+        String path = null;
+
+        try {
+            final ResourcePathIterator it = new ResourcePathIterator(request.getPathInfo());
+            while(it.hasNext() && result == null) {
+                path = it.next();
+                if(log.isDebugEnabled()) {
+                    log.debug("Trying to locate Resource at path '" + path + "'");
+                }
+                if (ctx.getSession().itemExists(path)) {
+                    result = new JcrNodeResource(ctx.getSession(),path);
+                    result.getMetadata().put(ResourceMetadata.RESOLUTION_PATH, path);
+                    if(log.isInfoEnabled()) {
+                        log.info("Found Resource at path '" + path + "'");
+                    }
                 }
             }
+        } catch(RepositoryException re) {
+            throw new SlingException("RepositoryException for path=" + path,re);
         }
         
         return result;

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java?rev=587134&r1=587133&r2=587134&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
Mon Oct 22 09:02:04 2007
@@ -70,7 +70,7 @@
 
     private Map<String, ScriptEngine> scriptEngines;
 
-    public SlingScriptResolver() throws Exception {
+    public SlingScriptResolver() throws SlingException {
         scriptEngines = new HashMap<String, ScriptEngine>();
         addScriptEngine(new RhinoJavasSriptEngine());
         addScriptEngine(new VelocityTemplatesScriptEngine());

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/engines/VelocityTemplatesScriptEngine.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/engines/VelocityTemplatesScriptEngine.java?rev=587134&r1=587133&r2=587134&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/engines/VelocityTemplatesScriptEngine.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/engines/VelocityTemplatesScriptEngine.java
Mon Oct 22 09:02:04 2007
@@ -40,9 +40,13 @@
 
     private final VelocityEngine velocity;
 
-    public VelocityTemplatesScriptEngine() throws Exception {
+    public VelocityTemplatesScriptEngine() throws SlingException {
         velocity = new VelocityEngine();
-        velocity.init();
+        try {
+            velocity.init();
+        } catch (Exception e) {
+            throw new SlingException("Exception in Velocity.init() " + e.getMessage(),e);
+        }
     }
 
     public String[] getExtensions() {

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java?rev=587134&r1=587133&r2=587134&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
Mon Oct 22 09:02:04 2007
@@ -38,6 +38,7 @@
 import org.apache.sling.microsling.api.ServiceLocator;
 import org.apache.sling.microsling.api.SlingRequestContext;
 import org.apache.sling.microsling.api.exceptions.HttpStatusCodeException;
+import org.apache.sling.microsling.api.exceptions.SlingException;
 import org.apache.sling.microsling.contenttype.ResponseContentTypeResolverFilter;
 import org.apache.sling.microsling.request.MicroslingRequestContext;
 import org.apache.sling.microsling.scripting.SlingScriptResolver;
@@ -160,7 +161,7 @@
 
     /** Select a SlingServlet to process the given request */
     protected Servlet selectSlingServlet(HttpServletRequest req)
-            throws Exception {
+            throws SlingException {
 
         // use the resource type to select a servlet
         final Resource r = SlingRequestContext.Accessor.getSlingRequestContext(req).getResource();




Mime
View raw message