Author: fmeschbe
Date: Thu Jan 17 11:50:01 2008
New Revision: 612952
URL: http://svn.apache.org/viewvc?rev=612952&view=rev
Log:
Drop HttpStatusCodeException and add ResourceNotFoundException
Added:
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/ResourceNotFoundException.java
- copied, changed from r607540,
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/HttpStatusCodeException.java
Removed:
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/HttpStatusCodeException.java
Modified:
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/scripting/SlingScript.java
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/servlets/SlingAllMethodsServlet.java
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/servlets/SlingSafeMethodsServlet.java
Copied:
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/ResourceNotFoundException.java
(from r607540,
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/HttpStatusCodeException.java)
URL:
http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/ResourceNotFoundException.java?p2=incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/ResourceNotFoundException.java&p1=incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/HttpStatusCodeException.java&r1=607540&r2=612952&rev=612952&view=diff
==============================================================================
---
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/HttpStatusCodeException.java
(original)
+++
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/ResourceNotFoundException.java
Thu Jan 17 11:50:01 2008
@@ -19,7 +19,7 @@
import javax.servlet.http.HttpServletResponse;
/**
- * An Exception that causes Sling to return the specified HTTP status code.
This
+ * An Exception that causes Sling to return a 404 (NOT FOUND) status code. This
* exception should not be caught but rather let be handed up the call stack up
* to the Sling error and exception handling.
* <p>
@@ -29,22 +29,22 @@
* to the status code and an optional message a <code>Throwable</code> may be
* supplied providing more information.
*/
-public class HttpStatusCodeException extends SlingException {
+public class ResourceNotFoundException extends SlingException {
private final int statusCode;
- public HttpStatusCodeException(int statusCode, String message) {
+ public ResourceNotFoundException(int statusCode, String message) {
super(message);
this.statusCode = statusCode;
}
- public HttpStatusCodeException(int statusCode, String message,
+ public ResourceNotFoundException(int statusCode, String message,
Throwable cause) {
super(message, cause);
this.statusCode = statusCode;
}
- public HttpStatusCodeException(String message, Throwable cause) {
+ public ResourceNotFoundException(String message, Throwable cause) {
super(message, cause);
this.statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
}
Modified:
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
URL:
http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java?rev=612952&r1=612951&r2=612952&view=diff
==============================================================================
---
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
(original)
+++
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
Thu Jan 17 11:50:01 2008
@@ -68,7 +68,7 @@
* (current location) and <code>..</code> (parent location),
* which are resolved by this method. If the path is relative,
* that is the first character is not a slash, a
- * <code>ResourceNotFoundException</code> is thrown.
+ * <code>SlingException</code> is thrown.
* @return The <code>Resource</code> object loaded from the path or
* <code>null</code> if the path does not resolve to a resource.
* @throws AccessControlException if an item exists at the
<code>path</code>
Modified:
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/scripting/SlingScript.java
URL:
http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/scripting/SlingScript.java?rev=612952&r1=612951&r2=612952&view=diff
==============================================================================
---
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/scripting/SlingScript.java
(original)
+++
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/scripting/SlingScript.java
Thu Jan 17 11:50:01 2008
@@ -48,9 +48,6 @@
* evaluating the script. Any bound variables must conform to
the
* requirements of the [EMAIL PROTECTED] SlingBindings}
predefined variables
* set.
- * @throws HttpStatusCodeException May be thrown if an error or status
- * condition should be purveyed to the client and the request
be
- * aborted.
* @throws ScriptEvaluationException If an error occurrs executing the
* script or preparing the script execution. The cause of the
* evaluation execption is available as the exception cause.
Modified:
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
URL:
http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java?rev=612952&r1=612951&r2=612952&view=diff
==============================================================================
---
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
(original)
+++
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
Thu Jan 17 11:50:01 2008
@@ -52,9 +52,6 @@
* Same as [EMAIL PROTECTED] #include(String,RequestDispatcherOptions)},
but using
* empty options.
*
- * @throws HttpStatusCodeException May be thrown if an error or status
- * condition should be purveyed to the client and the request
be
- * aborted.
* @throws SlingException If another error occurrs.
*/
void include(String path);
@@ -73,9 +70,6 @@
*
* @param path The path to the resource to include.
* @param options influence the rendering of the included Resource
- * @throws HttpStatusCodeException May be thrown if an error or status
- * condition should be purveyed to the client and the request
be
- * aborted.
* @throws SlingException If another error occurrs.
*/
void include(String path, RequestDispatcherOptions options);
Modified:
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/servlets/SlingAllMethodsServlet.java
URL:
http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/servlets/SlingAllMethodsServlet.java?rev=612952&r1=612951&r2=612952&view=diff
==============================================================================
---
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/servlets/SlingAllMethodsServlet.java
(original)
+++
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/servlets/SlingAllMethodsServlet.java
Thu Jan 17 11:50:01 2008
@@ -29,7 +29,7 @@
* Helper base class for data modifying Servlets used in Sling. This class
* extends the [EMAIL PROTECTED] SlingSafeMethodsServlet} by support for the
<em>POST</em>,
* <em>PUT</em> and <em>DELETE</em> methods.
- *
+ *
* @see SlingSafeMethodsServlet for more information on supporting more HTTP
* methods
*/
@@ -45,18 +45,17 @@
* <p>
* Implementations of this class should overwrite this method with their
* implementation for the HTTP <em>POST</em> method support.
- *
+ *
* @param request The HTTP request
* @param response The HTTP response
* @throws ServletException Not thrown by this implementation.
- * @throws IOException This implementation throws a
- * [EMAIL PROTECTED] HttpStatusCodeException} exception with
the
- * appropriate status code and message.
+ * @throws IOException If the error status cannot be reported back to the
+ * client.
*/
protected void doPost(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
- handleMethodNotImplemented(request);
+ handleMethodNotImplemented(request, response);
}
/**
@@ -69,18 +68,17 @@
* <p>
* Implementations of this class should overwrite this method with their
* implementation for the HTTP <em>PUT</em> method support.
- *
+ *
* @param request The HTTP request
* @param response The HTTP response
* @throws ServletException Not thrown by this implementation.
- * @throws IOException This implementation throws a
- * [EMAIL PROTECTED] HttpStatusCodeException} exception with
the
- * appropriate status code and message.
+ * @throws IOException If the error status cannot be reported back to the
+ * client.
*/
protected void doPut(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
- handleMethodNotImplemented(request);
+ handleMethodNotImplemented(request, response);
}
/**
@@ -93,18 +91,17 @@
* <p>
* Implementations of this class should overwrite this method with their
* implementation for the HTTP <em>DELETE</em> method support.
- *
+ *
* @param request The HTTP request
* @param response The HTTP response
* @throws ServletException Not thrown by this implementation.
- * @throws IOException This implementation throws a
- * [EMAIL PROTECTED] HttpStatusCodeException} exception with
the
- * appropriate status code and message.
+ * @throws IOException If the error status cannot be reported back to the
+ * client.
*/
protected void doDelete(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
- handleMethodNotImplemented(request);
+ handleMethodNotImplemented(request, response);
}
/**
@@ -116,7 +113,7 @@
* <em>POST</em>, <em>PUT</em> and <em>DELETE</em> and returns
* <code>true</code> if any of these methods is requested. Otherwise
* <code>false</code> is just returned.
- *
+ *
* @param request The HTTP request
* @param response The HTTP response
* @return <code>true</code> if the requested method
(<code>request.getMethod()</code>)
@@ -162,7 +159,7 @@
* support for the <em>POST</em>, <em>PUT</em> and <em>DELETE</em>
* methods in addition to the methods returned by the base class
* implementation.
- *
+ *
* @param declaredMethods The public and protected methods declared in the
* extension of this class.
* @return A <code>StringBuffer</code> containing the list of HTTP methods
@@ -194,7 +191,7 @@
* <p>
* This method may be used to make sure a method is actually overwritten
and
* not just the default implementation.
- *
+ *
* @param method The Method to check
* @param className The name of class assumed to contained the initial
* declaration of the method.
Modified:
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/servlets/SlingSafeMethodsServlet.java
URL:
http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/servlets/SlingSafeMethodsServlet.java?rev=612952&r1=612951&r2=612952&view=diff
==============================================================================
---
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/servlets/SlingSafeMethodsServlet.java
(original)
+++
incubator/sling/whiteboard/fmeschbe/effective_exceptions/api/src/main/java/org/apache/sling/api/servlets/SlingSafeMethodsServlet.java
Thu Jan 17 11:50:01 2008
@@ -33,7 +33,6 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
-import org.apache.sling.api.HttpStatusCodeException;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
@@ -47,8 +46,8 @@
* If any of the default HTTP methods is to be implemented just overwrite the
* respective doXXX method. If additional methods should be supported implement
* appropriate doXXX methods and overwrite the
- * [EMAIL PROTECTED] #mayService(SlingHttpServletRequest,
SlingHttpServletResponse)} method to
- * dispatch to the doXXX methods as appropriate and overwrite the
+ * [EMAIL PROTECTED] #mayService(SlingHttpServletRequest,
SlingHttpServletResponse)} method
+ * to dispatch to the doXXX methods as appropriate and overwrite the
* [EMAIL PROTECTED] #getAllowedRequestMethods(Map)} to add the new method
names.
* <p>
* Please note, that this base class is intended for applications where data is
@@ -60,7 +59,7 @@
* which also contains support for the <em>POST</em>, <em>PUT</em> and
* <em>DELETE</em> methods. This latter class should also be overwritten to
* add support for HTTP methods modifying data.
- *
+ *
* @see SlingAllMethodsServlet
*/
public class SlingSafeMethodsServlet extends GenericServlet {
@@ -73,7 +72,7 @@
* the output. Implementations of this class may overwrite this method if
* they have a more performing implementation. Otherwise, they may just
keep
* this base implementation.
- *
+ *
* @param request The HTTP request
* @param response The HTTP response which only gets the headers set
* @throws ServletException Forwarded from the
@@ -107,18 +106,17 @@
* <p>
* Implementations of this class should overwrite this method with their
* implementation for the HTTP <em>GET</em> method support.
- *
+ *
* @param request The HTTP request
* @param response The HTTP response
* @throws ServletException Not thrown by this implementation.
- * @throws IOException This implementation throws a
- * [EMAIL PROTECTED] HttpStatusCodeException} exception with
the
- * appropriate status code and message.
+ * @throws IOException If the error status cannot be reported back to the
+ * client.
*/
protected void doGet(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
- handleMethodNotImplemented(request);
+ handleMethodNotImplemented(request, response);
}
/**
@@ -133,7 +131,7 @@
* [EMAIL PROTECTED] #getAllowedRequestMethods(Map)} method with the
methods gathered.
* The returned value is then used as the value of the <code>Allow</code>
* header set.
- *
+ *
* @param request The HTTP request object. Not used.
* @param response The HTTP response object on which the header is set.
* @throws ServletException Not thrown by this implementation.
@@ -153,7 +151,7 @@
* <p>
* Extensions of this class do not generally need to overwrite this method
* as it contains all there is to be done to the <em>TRACE</em> method.
- *
+ *
* @param request The HTTP request whose headers are returned.
* @param response The HTTP response into which the request headers are
* written.
@@ -210,18 +208,17 @@
* [EMAIL PROTECTED] #mayService(HttpServletRequest, HttpServletResponse)}
method and
* add support for any extension HTTP methods through an additional doXXX
* method.
- *
+ *
* @param request The HTTP request
* @param response The HTTP response
* @throws ServletException Not thrown by this implementation.
- * @throws IOException This implementation throws a
- * [EMAIL PROTECTED] HttpStatusCodeException} exception with
the
- * appropriate status code and message.
+ * @throws IOException If the error status cannot be reported back to the
+ * client.
*/
protected void doGeneric(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
- handleMethodNotImplemented(request);
+ handleMethodNotImplemented(request, response);
}
/**
@@ -238,7 +235,7 @@
* call this base implementation and in case <code>false</code> is
* returned add handling for any other method and of course return whether
* the requested method was known or not.
- *
+ *
* @param request The HTTP request
* @param response The HTTP response
* @return <code>true</code> if the requested method
(<code>request.getMethod()</code>)
@@ -276,26 +273,28 @@
* unhandled HTTP request method. In case of HTTP/1.1 a 405 status code
* (Method Not Allowed) is returned, otherwise a 400 status (Bad Request)
is
* returned.
- *
+ *
* @param request The HTTP request from which the method and protocol
values
* are extracted to build the appropriate message.
- * @throws HttpStatusCodeException Always thrown by this method containing
- * the appropriate status code and message.
+ * @param response The HTTP response to which the error status is sent.
+ * @throws IOException Thrown if the status cannot be sent to the client.
*/
- protected void handleMethodNotImplemented(SlingHttpServletRequest request)
- throws HttpStatusCodeException {
+ protected void handleMethodNotImplemented(SlingHttpServletRequest request,
+ SlingHttpServletResponse response) throws IOException {
String protocol = request.getProtocol();
String msg = "Method " + request.getMethod() + " not supported";
- // for HTTP/1.1 use 405 Method Not Allowed
if (protocol.endsWith("1.1")) {
- throw new HttpStatusCodeException(
- HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
- }
- // otherwise use 400 Bad Request
- throw new HttpStatusCodeException(HttpServletResponse.SC_BAD_REQUEST,
- msg);
+ // for HTTP/1.1 use 405 Method Not Allowed
+ response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
+
+ } else {
+
+ // otherwise use 400 Bad Request
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
+
+ }
}
/**
@@ -312,7 +311,7 @@
* Implementations of this class should not generally overwrite this
method.
* Rather the [EMAIL PROTECTED] #mayService(HttpServletRequest,
HttpServletResponse)}
* method should be overwritten to add support for more HTTP methods.
- *
+ *
* @param request The HTTP request
* @param response The HTTP response
* @throws ServletException Forwarded from the
@@ -345,7 +344,7 @@
* method if the request is a HTTP request.
* <p>
* Implementations of this class will not generally overwrite this method.
- *
+ *
* @param req The Servlet request
* @param res The Servlet response
* @throws ServletException If the request is not a HTTP request or
@@ -387,7 +386,7 @@
* the [EMAIL PROTECTED] #mayService(HttpServletRequest,
HttpServletResponse)} method).
* This base class implementation should always be called to make sure the
* default HTTP methods are included in the list.
- *
+ *
* @param declaredMethods The public and protected methods declared in the
* extension of this class.
* @return A <code>StringBuffer</code> containing the list of HTTP methods
@@ -423,7 +422,7 @@
* [EMAIL PROTECTED] #getAllowedRequestMethods(Map)} method. Note, that
only extension
* classes of this class are considered to be sure to not account for the
* default implementations of the doXXX methods in this class.
- *
+ *
* @param c The <code>Class</code> to get the declared methods from
* @return The Map of methods considered for support checking.
*/