incubator-deft-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmee...@apache.org
Subject svn commit: r1154336 [1/2] - in /incubator/deft/sandbox: ./ src/main/java/org/apache/deft/annotation/ src/main/java/org/apache/deft/example/client/ src/main/java/org/apache/deft/example/handler/ src/main/java/org/apache/deft/example/keyvalue/ src/main/...
Date Fri, 05 Aug 2011 18:24:48 GMT
Author: jmeehan
Date: Fri Aug  5 18:24:46 2011
New Revision: 1154336

URL: http://svn.apache.org/viewvc?rev=1154336&view=rev
Log:
DEFT-142: Proposed code for dynamic invocation of handlers (clone)

Added:
    incubator/deft/sandbox/src/main/java/org/apache/deft/annotation/Asynchronous.java
      - copied, changed from r1153986, incubator/deft/sandbox/src/main/java/org/apache/deft/web/Asynchronous.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/annotation/Authenticated.java
      - copied, changed from r1153986, incubator/deft/sandbox/src/main/java/org/apache/deft/web/Authenticated.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/example/handler/ClonedHandlerExample.java   (with props)
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/RequestHandlerFactory.java   (with props)
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/ContentType.java
      - copied, changed from r1153986, incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/ContentType.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/HttpStatus.java   (with props)
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/HttpVerb.java
      - copied, changed from r1153986, incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpVerb.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/handler/RequestHandlerFactoryTest.java   (with props)
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpExceptionTest.java   (with props)
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpRequestDispatcherTest.java   (with props)
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/ContentTypeTest.java
      - copied, changed from r1153986, incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/ContentTypeTest.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/HttpStatusTest.java   (with props)
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/HttpVerbTest.java   (with props)
Removed:
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/Asynchronous.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/Authenticated.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpVerb.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/ContentType.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/HttpVerbTest.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/ContentTypeTest.java
Modified:
    incubator/deft/sandbox/pom.xml
    incubator/deft/sandbox/src/main/java/org/apache/deft/example/client/AsynchronousHttpClientPostExample.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/example/keyvalue/KeyValueStoreHandler.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/util/HttpUtil.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/Application.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpServer.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/BadRequestRequestHandler.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/ForbiddenRequestHandler.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/NotFoundRequestHandler.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/RequestHandler.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/StaticContentHandler.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpException.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequest.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequestDispatcher.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequestImpl.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpResponse.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpResponseImpl.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/AsynchronousHttpClient.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/Request.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/configuration/AnnotationsScannerTest.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/ApplicationTest.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTest.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/handler/RequestHandlerTest.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/AsynchronousHttpClientTest.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/RequestTest.java

Modified: incubator/deft/sandbox/pom.xml
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/pom.xml?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/pom.xml (original)
+++ incubator/deft/sandbox/pom.xml Fri Aug  5 18:24:46 2011
@@ -42,6 +42,13 @@
 		</dependency>
 
 		<dependency>
+			<groupId>org.mockito</groupId>
+			<artifactId>mockito-core</artifactId>
+			<version>1.8.5</version>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
 			<groupId>ch.qos.logback</groupId>
 			<artifactId>logback-classic</artifactId>
 			<version>0.9.28</version>

Copied: incubator/deft/sandbox/src/main/java/org/apache/deft/annotation/Asynchronous.java (from r1153986, incubator/deft/sandbox/src/main/java/org/apache/deft/web/Asynchronous.java)
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/annotation/Asynchronous.java?p2=incubator/deft/sandbox/src/main/java/org/apache/deft/annotation/Asynchronous.java&p1=incubator/deft/sandbox/src/main/java/org/apache/deft/web/Asynchronous.java&r1=1153986&r2=1154336&rev=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/Asynchronous.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/annotation/Asynchronous.java Fri Aug  5 18:24:46 2011
@@ -17,7 +17,7 @@
  *  under the License. 
  *  
  */
-package org.apache.deft.web;
+package org.apache.deft.annotation;
 
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
@@ -30,9 +30,7 @@ import org.apache.deft.web.handler.Reque
  * Annotation used by implementation of {@link RequestHandler} to denote a
  * method as asynchronous (i.e don't close the Http connection until the client
  * invokes the finish method)
- * 
  */
-
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.METHOD)
 public @interface Asynchronous {

Copied: incubator/deft/sandbox/src/main/java/org/apache/deft/annotation/Authenticated.java (from r1153986, incubator/deft/sandbox/src/main/java/org/apache/deft/web/Authenticated.java)
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/annotation/Authenticated.java?p2=incubator/deft/sandbox/src/main/java/org/apache/deft/annotation/Authenticated.java&p1=incubator/deft/sandbox/src/main/java/org/apache/deft/web/Authenticated.java&r1=1153986&r2=1154336&rev=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/Authenticated.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/annotation/Authenticated.java Fri Aug  5 18:24:46 2011
@@ -17,7 +17,7 @@
  *  under the License. 
  *  
  */
-package org.apache.deft.web;
+package org.apache.deft.annotation;
 
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
@@ -31,9 +31,7 @@ import org.apache.deft.web.handler.Reque
  * method requires that the request (current user) is authenticated (i.e your
  * overridden method {@link RequestHandler#getCurrentUser} returns a non null
  * value)
- * 
  */
-
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.METHOD)
 public @interface Authenticated {

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/example/client/AsynchronousHttpClientPostExample.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/example/client/AsynchronousHttpClientPostExample.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/example/client/AsynchronousHttpClientPostExample.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/example/client/AsynchronousHttpClientPostExample.java Fri Aug  5 18:24:46 2011
@@ -23,11 +23,11 @@ import org.apache.deft.io.IOLoop;
 import org.apache.deft.io.timeout.Timeout;
 import org.apache.deft.web.AsyncCallback;
 import org.apache.deft.web.AsyncResult;
-import org.apache.deft.web.HttpVerb;
-import org.apache.deft.web.http.ContentType;
 import org.apache.deft.web.http.client.AsynchronousHttpClient;
 import org.apache.deft.web.http.client.Request;
 import org.apache.deft.web.http.client.Response;
+import org.apache.deft.web.http.protocol.ContentType;
+import org.apache.deft.web.http.protocol.HttpVerb;
 
 /**
  * Example class to demonstrate usage of <code>AsynchronousHttpClient</code>.
@@ -54,18 +54,21 @@ public class AsynchronousHttpClientPostE
      * <li>Start the instance.
      * </ol>
      * 
-     * @param args
-     *            the arguments to pass; unused.
+     * @param args the arguments to pass; unused.
      */
     public static void main(final String[] args) {
 
         final AsyncResult<Response> callback = new AsyncResult<Response>() {
 
             @Override
-            public void onSuccess(final Response response) { System.out.println("RESPONSE: " + response); }
+            public void onSuccess(final Response response) {
+                System.out.println("RESPONSE: " + response);
+            }
 
             @Override
-            public void onFailure(final Throwable caught) { System.out.println("EXCEPTION: " + caught); }
+            public void onFailure(final Throwable caught) {
+                System.out.println("EXCEPTION: " + caught);
+            }
         };
 
         Request request = new Request("http://incubator.apache.org/deft/", HttpVerb.POST);

Added: incubator/deft/sandbox/src/main/java/org/apache/deft/example/handler/ClonedHandlerExample.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/example/handler/ClonedHandlerExample.java?rev=1154336&view=auto
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/example/handler/ClonedHandlerExample.java (added)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/example/handler/ClonedHandlerExample.java Fri Aug  5 18:24:46 2011
@@ -0,0 +1,60 @@
+/*
+ *  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.deft.example.handler;
+
+import java.util.Date;
+
+import org.apache.deft.annotation.Path;
+import org.apache.deft.example.DeftServerExample;
+import org.apache.deft.web.handler.RequestHandler;
+import org.apache.deft.web.http.HttpRequest;
+import org.apache.deft.web.http.HttpResponse;
+
+/**
+ * All <code>RequestHandler</code> implementations are cloned. Where there are
+ * mutable fields, the {@link #clone()} method might be explicitly overridden.
+ * <p>
+ * In the example below, note that the <code>String</code> representation of
+ * each handler differs when written to the <code>HttpResponse</code>.
+ * </p>
+ * 
+ * @see Path
+ * @see DeftServerExample
+ */
+@Path("/clone")
+public class ClonedHandlerExample extends RequestHandler {
+
+    private Date mutableDate = new Date();
+
+    @Override
+    public void get(HttpRequest request, HttpResponse response) {
+
+        response.write("Cloned: " + toString());
+    }
+
+    @Override
+    public Object clone() throws CloneNotSupportedException {
+
+        ClonedHandlerExample handler = (ClonedHandlerExample) super.clone();
+        handler.mutableDate = new Date(mutableDate.getTime());
+
+        return handler;
+    }
+}

Propchange: incubator/deft/sandbox/src/main/java/org/apache/deft/example/handler/ClonedHandlerExample.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/example/keyvalue/KeyValueStoreHandler.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/example/keyvalue/KeyValueStoreHandler.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/example/keyvalue/KeyValueStoreHandler.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/example/keyvalue/KeyValueStoreHandler.java Fri Aug  5 18:24:46 2011
@@ -19,9 +19,9 @@
  */
 package org.apache.deft.example.keyvalue;
 
+import org.apache.deft.annotation.Asynchronous;
 import org.apache.deft.annotation.Path;
 import org.apache.deft.web.AsyncResult;
-import org.apache.deft.web.Asynchronous;
 import org.apache.deft.web.handler.RequestHandler;
 import org.apache.deft.web.http.HttpRequest;
 import org.apache.deft.web.http.HttpResponse;

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/util/HttpUtil.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/util/HttpUtil.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/util/HttpUtil.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/util/HttpUtil.java Fri Aug  5 18:24:46 2011
@@ -25,142 +25,15 @@ import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 
 import org.apache.deft.web.http.HttpRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class HttpUtil {
 
-    private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
-
     /*
      * MessageDigest are not thread-safe and are expensive to create. Do it
      * lazily for each thread that need access to one.
      */
     private static final ThreadLocal<MessageDigest> md = new ThreadLocal<MessageDigest>();
 
-    private static final String _200_OK = "HTTP/1.1 200 OK\r\n";
-    private static final String _201_CREATED = "HTTP/1.1 201 Created\r\n";
-    private static final String _202_ACCEPTED = "HTTP/1.1 202 Accepted\r\n";
-    private static final String _203_NON_AUTHORITATIVE_INFO = "HTTP/1.1 203 Non-Authoritative Information\r\n";
-    private static final String _204_NO_CONTENT = "HTTP/1.1 204 No Content\r\n";
-    private static final String _205_RESET_CONTENT = "HTTP/1.1 205 Reset Content\r\n";
-    private static final String _206_PARTIAL_CONTENT = "HTTP/1.1 206 Partial Content\r\n";
-    private static final String _300_MULTIPLE_CHOICES = "HTTP/1.1 300 Multiple Choices\r\n";
-    private static final String _301_MOVED_PERMANENTLY = "HTTP/1.1 301 Moved Permanently\r\n";
-    private static final String _302_NOT_FOUND = "HTTP/1.1 302 Found\r\n";
-    private static final String _303_SEE_OTHER = "HTTP/1.1 303 See Other\r\n";
-    private static final String _304_NOT_MODIFIED = "HTTP/1.1 304 Not Modified\r\n";
-    private static final String _305_USE_PROXY = "HTTP/1.1 305 Use Proxy\r\n";
-    private static final String _307_TEMPORARY_REDIRECT = "HTTP/1.1 307 Temporary Redirect\r\n";
-    private static final String _400_BAD_REQUEST = "HTTP/1.1 400 Bad Request\r\n";
-    private static final String _401_UNAUTHORIZED = "HTTP/1.1 401 Unauthorized\r\n";
-    private static final String _403_FORBIDDEN = "HTTP/1.1 403 Forbidden\r\n";
-    private static final String _404_NOT_FOUND = "HTTP/1.1 404 Not Found\r\n";
-    private static final String _405_METHOD_NOT_ALLOWED = "HTTP/1.1 405 Method Not Allowed\r\n";
-    private static final String _406_NOT_ACCEPTABLE = "HTTP/1.1 406 Not Acceptable\r\n";
-    private static final String _407_PROXY_AUTH_REQUIRED = "HTTP/1.1 407 Proxy Authentication Required\r\n";
-    private static final String _408_REQUEST_TIMEOUT = "HTTP/1.1 408 Request Timeout\r\n";
-    private static final String _409_CONFLICT = "HTTP/1.1 409 Conflict\r\n";
-    private static final String _410_GONE = "HTTP/1.1 410 Gone\r\n";
-    private static final String _411_LENGTH_REQUIRED = "HTTP/1.1 411 Length Required\r\n";
-    private static final String _412_PRECONDITION_FAILED = "HTTP/1.1 412 Precondition Failed\r\n";
-    private static final String _413_REQUEST_ENTITY_LARGE = "HTTP/1.1 413 Request Entity Too Large\r\n";
-    private static final String _414_REQUEST_URI_TOO_LONG = "HTTP/1.1 414 Request-URI Too Long\r\n";
-    private static final String _415_UNSUPPORTED_MEDIA_TYPE = "HTTP/1.1 415 Unsupported Media Type\r\n";
-    private static final String _416_REQUEST_RANGE_NOT_SAT = "HTTP/1.1 416 Requested Range Not Satisfiable\r\n";
-    private static final String _417_EXPECTATION_FAILED = "HTTP/1.1 417 Expectation Failed\r\n";
-    private static final String _500_INTERNAL_SERVER_ERROR = "HTTP/1.1 500 Internal Server Error\r\n";
-    private static final String _501_NOT_IMPLEMENTED = "HTTP/1.1 501 Not Implemented\r\n";
-    private static final String _502_BAD_GATEWAY = "HTTP/1.1 502 Bad Gateway\r\n";
-    private static final String _503_SERVICE_UNAVAILABLE = "HTTP/1.1 503 Service Unavailable\r\n";
-    private static final String _504_GATEWAY_TIMEOUT = "HTTP/1.1 504 Gateway Timeout\r\n";
-    private static final String _505_VERSION_NOT_SUPPORTED = "HTTP/1.1 505 HTTP Version Not Supported\r\n";
-
-    // e.g. HTTP/1.0 200 OK or HTTP/1.0 404 Not Found (HTTP version + response
-    // status code + reason phrase)
-    public static String createInitialLine(int statusCode) {
-
-        switch (statusCode) {
-        case 200:
-            return _200_OK;
-        case 201:
-            return _201_CREATED;
-        case 202:
-            return _202_ACCEPTED;
-        case 203:
-            return _203_NON_AUTHORITATIVE_INFO;
-        case 204:
-            return _204_NO_CONTENT;
-        case 205:
-            return _205_RESET_CONTENT;
-        case 206:
-            return _206_PARTIAL_CONTENT;
-        case 300:
-            return _300_MULTIPLE_CHOICES;
-        case 301:
-            return _301_MOVED_PERMANENTLY;
-        case 302:
-            return _302_NOT_FOUND;
-        case 303:
-            return _303_SEE_OTHER;
-        case 304:
-            return _304_NOT_MODIFIED;
-        case 305:
-            return _305_USE_PROXY;
-        case 307:
-            return _307_TEMPORARY_REDIRECT;
-        case 400:
-            return _400_BAD_REQUEST;
-        case 401:
-            return _401_UNAUTHORIZED;
-        case 403:
-            return _403_FORBIDDEN;
-        case 404:
-            return _404_NOT_FOUND;
-        case 405:
-            return _405_METHOD_NOT_ALLOWED;
-        case 406:
-            return _406_NOT_ACCEPTABLE;
-        case 407:
-            return _407_PROXY_AUTH_REQUIRED;
-        case 408:
-            return _408_REQUEST_TIMEOUT;
-        case 409:
-            return _409_CONFLICT;
-        case 410:
-            return _410_GONE;
-        case 411:
-            return _411_LENGTH_REQUIRED;
-        case 412:
-            return _412_PRECONDITION_FAILED;
-        case 413:
-            return _413_REQUEST_ENTITY_LARGE;
-        case 414:
-            return _414_REQUEST_URI_TOO_LONG;
-        case 415:
-            return _415_UNSUPPORTED_MEDIA_TYPE;
-        case 416:
-            return _416_REQUEST_RANGE_NOT_SAT;
-        case 417:
-            return _417_EXPECTATION_FAILED;
-        case 500:
-            return _500_INTERNAL_SERVER_ERROR;
-        case 501:
-            return _501_NOT_IMPLEMENTED;
-        case 502:
-            return _502_BAD_GATEWAY;
-        case 503:
-            return _503_SERVICE_UNAVAILABLE;
-        case 504:
-            return _504_GATEWAY_TIMEOUT;
-        case 505:
-            return _505_VERSION_NOT_SUPPORTED;
-        default:
-            logger.error("Uknonwn Http status code: " + statusCode);
-            throw new IllegalArgumentException("Unknow Http status code: " + statusCode);
-        }
-    }
-
     public static boolean verifyRequest(HttpRequest request) {
         String version = request.getVersion();
         boolean requestOk = true;

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/Application.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/Application.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/Application.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/Application.java Fri Aug  5 18:24:46 2011
@@ -27,6 +27,7 @@ import org.apache.deft.web.handler.BadRe
 import org.apache.deft.web.handler.ForbiddenRequestHandler;
 import org.apache.deft.web.handler.NotFoundRequestHandler;
 import org.apache.deft.web.handler.RequestHandler;
+import org.apache.deft.web.handler.RequestHandlerFactory;
 import org.apache.deft.web.handler.StaticContentHandler;
 import org.apache.deft.web.http.HttpRequest;
 
@@ -88,22 +89,27 @@ public class Application {
      *         returned.
      */
     private RequestHandler getHandler(String path) {
+
         RequestHandler rh = absoluteHandlers.get(path);
         if (rh == null) {
-            // path could contain capturing groups which we could have a handler
-            // associated with.
             rh = getCapturingHandler(path);
             if (rh == null) {
-                // path could be prefixed with the 'static content directory'
                 rh = getStaticContentHandler(path);
+                if (rh != null) {
+                    return rh;
+                }
+            } else {
+                return RequestHandlerFactory.cloneHandler(rh);
             }
+        } else {
+            return RequestHandlerFactory.cloneHandler(rh);
         }
 
-        // TODO RS store in a final field for improved performance?
-        return rh != null ? rh : NotFoundRequestHandler.getInstance();
+        return NotFoundRequestHandler.getInstance();
     }
 
     public RequestHandler getHandler(HttpRequest request) {
+
         if (!HttpUtil.verifyRequest(request)) {
             return BadRequestRequestHandler.getInstance();
         }
@@ -111,10 +117,10 @@ public class Application {
         // request/user is authenticated
         // (i.e RequestHandler.getCurrentUser() != null).
         RequestHandler rh = getHandler(request.getRequestedPath());
-        ;
         if (rh.isMethodAuthenticated(request.getMethod()) && rh.getCurrentUser(request) == null) {
             return ForbiddenRequestHandler.getInstance();
         }
+
         return rh;
     }
 
@@ -154,7 +160,7 @@ public class Application {
         }
     }
 
-    public void setStaticContentDir(String scd) {
+    void setStaticContentDir(String scd) {
         staticContentDir = scd;
     }
 }

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpServer.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpServer.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpServer.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpServer.java Fri Aug  5 18:24:46 2011
@@ -57,6 +57,7 @@ public class HttpServer {
         }
 
         application = createApplication(configuration.getHandlerPackage());
+        application.setStaticContentDir(configuration.getStaticDirectory());
     }
 
     protected Application createApplication(String packageName) {

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/BadRequestRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/BadRequestRequestHandler.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/BadRequestRequestHandler.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/BadRequestRequestHandler.java Fri Aug  5 18:24:46 2011
@@ -21,6 +21,7 @@ package org.apache.deft.web.handler;
 
 import org.apache.deft.web.http.HttpRequest;
 import org.apache.deft.web.http.HttpResponse;
+import org.apache.deft.web.http.protocol.HttpStatus;
 
 public class BadRequestRequestHandler extends RequestHandler {
 
@@ -35,7 +36,7 @@ public class BadRequestRequestHandler ex
 
     @Override
     public void get(HttpRequest request, HttpResponse response) {
-        response.setStatusCode(400);
+        response.setStatus(HttpStatus.CLIENT_ERROR_BAD_REQUEST);
         response.setHeader("Connection", "close");
         response.write("HTTP 1.1 requests must include the Host: header");
     }

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/ForbiddenRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/ForbiddenRequestHandler.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/ForbiddenRequestHandler.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/ForbiddenRequestHandler.java Fri Aug  5 18:24:46 2011
@@ -21,6 +21,7 @@ package org.apache.deft.web.handler;
 
 import org.apache.deft.web.http.HttpRequest;
 import org.apache.deft.web.http.HttpResponse;
+import org.apache.deft.web.http.protocol.HttpStatus;
 
 public class ForbiddenRequestHandler extends RequestHandler {
 
@@ -35,7 +36,7 @@ public class ForbiddenRequestHandler ext
 
     @Override
     public void get(HttpRequest request, HttpResponse response) {
-        response.setStatusCode(403);
+        response.setStatus(HttpStatus.CLIENT_ERROR_FORBIDDEN);
         response.setHeader("Connection", "close");
         response.write("Authentication failed");
     }

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/NotFoundRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/NotFoundRequestHandler.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/NotFoundRequestHandler.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/NotFoundRequestHandler.java Fri Aug  5 18:24:46 2011
@@ -21,6 +21,7 @@ package org.apache.deft.web.handler;
 
 import org.apache.deft.web.http.HttpRequest;
 import org.apache.deft.web.http.HttpResponse;
+import org.apache.deft.web.http.protocol.HttpStatus;
 
 public class NotFoundRequestHandler extends RequestHandler {
 
@@ -35,7 +36,7 @@ public class NotFoundRequestHandler exte
 
     @Override
     public void get(HttpRequest request, HttpResponse response) {
-        response.setStatusCode(404);
+        response.setStatus(HttpStatus.CLIENT_ERROR_NOT_FOUND);
         response.setHeader("Connection", "close");
         response.write("Requested URL: " + request.getRequestedPath() + " was not found");
     }

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/RequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/RequestHandler.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/RequestHandler.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/RequestHandler.java Fri Aug  5 18:24:46 2011
@@ -22,27 +22,30 @@ package org.apache.deft.web.handler;
 import java.lang.annotation.Annotation;
 import java.util.Map;
 
-import org.apache.deft.web.Asynchronous;
-import org.apache.deft.web.Authenticated;
-import org.apache.deft.web.HttpVerb;
+import org.apache.deft.annotation.Asynchronous;
+import org.apache.deft.annotation.Authenticated;
 import org.apache.deft.web.http.HttpRequest;
 import org.apache.deft.web.http.HttpResponse;
+import org.apache.deft.web.http.protocol.HttpStatus;
+import org.apache.deft.web.http.protocol.HttpVerb;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 
-public abstract class RequestHandler {
+public abstract class RequestHandler implements Cloneable {
 
     private final ImmutableMap<HttpVerb, Boolean> asynchVerbs;
     private final ImmutableMap<HttpVerb, Boolean> authVerbs;
 
     public RequestHandler() {
+
         Map<HttpVerb, Boolean> asyncV = Maps.newHashMap();
         Map<HttpVerb, Boolean> authV = Maps.newHashMap();
         for (HttpVerb verb : HttpVerb.values()) {
-            authV.put(verb, isMethodAnnotated(verb, Authenticated.class));
             asyncV.put(verb, isMethodAnnotated(verb, Asynchronous.class));
+            authV.put(verb, isMethodAnnotated(verb, Authenticated.class));
         }
+
         asynchVerbs = ImmutableMap.copyOf(asyncV);
         authVerbs = ImmutableMap.copyOf(authV);
     }
@@ -66,31 +69,37 @@ public abstract class RequestHandler {
 
     // Default implementation of HttpMethods return a 501 page
     public void get(HttpRequest request, HttpResponse response) {
-        response.setStatusCode(501);
+        response.setStatus(HttpStatus.SERVER_ERROR_NOT_IMPLEMENTED);
         response.write("");
     }
 
     public void post(HttpRequest request, HttpResponse response) {
-        response.setStatusCode(501);
+        response.setStatus(HttpStatus.SERVER_ERROR_NOT_IMPLEMENTED);
         response.write("");
     }
 
     public void put(HttpRequest request, HttpResponse response) {
-        response.setStatusCode(501);
+        response.setStatus(HttpStatus.SERVER_ERROR_NOT_IMPLEMENTED);
         response.write("");
     }
 
     public void delete(HttpRequest request, HttpResponse response) {
-        response.setStatusCode(501);
+        response.setStatus(HttpStatus.SERVER_ERROR_NOT_IMPLEMENTED);
         response.write("");
     }
 
     public void head(HttpRequest request, HttpResponse response) {
-        response.setStatusCode(501);
+        response.setStatus(HttpStatus.SERVER_ERROR_NOT_IMPLEMENTED);
         response.write("");
     }
 
     public String getCurrentUser(HttpRequest request) {
         return null;
     }
+
+    /** @{inheritDoc */
+    @Override
+    public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
 }

Added: incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/RequestHandlerFactory.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/RequestHandlerFactory.java?rev=1154336&view=auto
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/RequestHandlerFactory.java (added)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/RequestHandlerFactory.java Fri Aug  5 18:24:46 2011
@@ -0,0 +1,54 @@
+/*
+ *  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.deft.web.handler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Factory for the creation and retrieval of <code>RequestHandler</code> types.
+ */
+public class RequestHandlerFactory {
+
+    /**
+     * The <code>Logger</code>.
+     */
+    private final static Logger logger = LoggerFactory.getLogger(RequestHandlerFactory.class);
+
+    /**
+     * Clone the given instance of <code>RequestHandler</code>.
+     * 
+     * @param handler the <code>RequestHandler</code> to clone.
+     * @return a new instance, or <code>null</code> on any problem.
+     */
+    @SuppressWarnings("unchecked")
+    public static <T extends RequestHandler> T cloneHandler(T handler) {
+
+        if (handler != null) {
+            try {
+                return (T) handler.clone();
+            } catch (CloneNotSupportedException e) {
+                logger.error("Could not clone RequestHandler", e);
+            }
+        }
+
+        return null;
+    }
+}

Propchange: incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/RequestHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/StaticContentHandler.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/StaticContentHandler.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/StaticContentHandler.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/handler/StaticContentHandler.java Fri Aug  5 18:24:46 2011
@@ -27,6 +27,7 @@ import org.apache.deft.util.DateUtil;
 import org.apache.deft.web.http.HttpException;
 import org.apache.deft.web.http.HttpRequest;
 import org.apache.deft.web.http.HttpResponse;
+import org.apache.deft.web.http.protocol.HttpStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -73,9 +74,9 @@ public class StaticContentHandler extend
         final String path = request.getRequestedPath();
         final File file = new File(path.substring(1)); // remove the leading '/'
         if (!file.exists()) {
-            throw new HttpException(404);
+            throw new HttpException(HttpStatus.CLIENT_ERROR_NOT_FOUND);
         } else if (!file.isFile()) {
-            throw new HttpException(403, path + "is not a file");
+            throw new HttpException(HttpStatus.CLIENT_ERROR_FORBIDDEN, path + "is not a file");
         }
 
         final long lastModified = file.lastModified();
@@ -90,7 +91,7 @@ public class StaticContentHandler extend
         if (ifModifiedSince != null) {
             final long ims = DateUtil.parseToMilliseconds(ifModifiedSince);
             if (lastModified <= ims) {
-                response.setStatusCode(304); // Not Modified
+                response.setStatus(HttpStatus.REDIRECTION_NOT_MODIFIED);
                 logger.debug("not modified");
                 return;
             }

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpException.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpException.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpException.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpException.java Fri Aug  5 18:24:46 2011
@@ -19,23 +19,47 @@
  */
 package org.apache.deft.web.http;
 
+import org.apache.deft.web.http.protocol.HttpStatus;
+
+/**
+ * Representation of an exception thrown by the server through the HTTP
+ * protocol.
+ */
 public class HttpException extends RuntimeException {
 
+    /** Serial Version UID */
     private static final long serialVersionUID = 8066634515515557043L;
 
-    private final int statusCode;
+    /** The HTTP status for this exception. */
+    private final HttpStatus status;
 
-    public HttpException(int statusCode) {
-        this(statusCode, "");
+    /**
+     * Create an instance of this type, with the given <code>HttpStatus</code>
+     * and an empty message.
+     * 
+     * @param status the <code>HttpStatus</code> to apply.
+     */
+    public HttpException(HttpStatus status) {
+        this(status, "");
     }
 
-    public HttpException(int statusCode, String message) {
+    /**
+     * Create an instance of this type, with the given <code>HttpStatus</code>
+     * and message.
+     * 
+     * @param status the <code>HttpStatus</code> to apply.
+     */
+    public HttpException(HttpStatus status, String message) {
         super(message);
-        this.statusCode = statusCode;
+        this.status = status;
     }
 
-    public int getStatusCode() {
-        return statusCode;
+    /**
+     * Retrieve the <code>HttpStatus</code> represented by this exception.
+     * 
+     * @return the represented <code>HttpStatus</code>.
+     */
+    public HttpStatus getStatus() {
+        return status;
     }
-
 }

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequest.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequest.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequest.java Fri Aug  5 18:24:46 2011
@@ -23,7 +23,7 @@ import java.net.InetAddress;
 import java.util.Collection;
 import java.util.Map;
 
-import org.apache.deft.web.HttpVerb;
+import org.apache.deft.web.http.protocol.HttpVerb;
 
 /**
  * An HTTP request received from a client

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequestDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequestDispatcher.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequestDispatcher.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequestDispatcher.java Fri Aug  5 18:24:46 2011
@@ -19,11 +19,16 @@
  */
 package org.apache.deft.web.http;
 
-import org.apache.deft.web.HttpVerb;
 import org.apache.deft.web.handler.RequestHandler;
+import org.apache.deft.web.http.protocol.HttpVerb;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * The <code>RequestDispatcher</code> is responsible for invoking the
+ * appropriate <code>RequestHandler</code> method for the current
+ * <code>HttpRequest</code>.
+ */
 public class HttpRequestDispatcher {
 
     private static final Logger logger = LoggerFactory.getLogger(HttpRequestDispatcher.class);
@@ -56,7 +61,7 @@ public class HttpRequestDispatcher {
                     // TODO send "not supported page (501) back to client"
                 }
             } catch (HttpException he) {
-                response.setStatusCode(he.getStatusCode());
+                response.setStatus(he.getStatus());
                 response.write(he.getMessage());
                 if (rh.isMethodAsynchronous(request.getMethod())) {
                     response.finish();

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequestImpl.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequestImpl.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequestImpl.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpRequestImpl.java Fri Aug  5 18:24:46 2011
@@ -29,7 +29,7 @@ import java.util.regex.Pattern;
 
 import org.apache.deft.io.IOLoop;
 import org.apache.deft.util.ArrayUtil;
-import org.apache.deft.web.HttpVerb;
+import org.apache.deft.web.http.protocol.HttpVerb;
 
 import com.google.common.base.Charsets;
 import com.google.common.base.Strings;

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpResponse.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpResponse.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpResponse.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpResponse.java Fri Aug  5 18:24:46 2011
@@ -21,6 +21,8 @@ package org.apache.deft.web.http;
 
 import java.io.File;
 
+import org.apache.deft.web.http.protocol.HttpStatus;
+
 /**
  * An HTTP response build and sent to a client in response to a
  * {@link HttpRequest}
@@ -28,12 +30,11 @@ import java.io.File;
 public interface HttpResponse {
 
     /**
-     * Set this HTTP Response status (or alos called return code). 200 for OK,
-     * 404 for not found, etc..
+     * Set the HTTP Response status (return) code, such as 200 for success.
      * 
-     * @param sc the status code
+     * @param status the <code>HttpStatus</code> to apply.
      */
-    void setStatusCode(int sc);
+    void setStatus(HttpStatus status);
 
     /**
      * Set an HTTP header value. If the header doesn't exist, it will be added.

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpResponseImpl.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpResponseImpl.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpResponseImpl.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/HttpResponseImpl.java Fri Aug  5 18:24:46 2011
@@ -39,6 +39,7 @@ import org.apache.deft.util.Closeables;
 import org.apache.deft.util.CookieUtil;
 import org.apache.deft.util.DateUtil;
 import org.apache.deft.util.HttpUtil;
+import org.apache.deft.web.http.protocol.HttpStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,7 +55,7 @@ public class HttpResponseImpl implements
     private final HttpProtocol protocol;
     private final SelectionKey key;
 
-    private int statusCode = 200; // default response status code
+    private HttpStatus status = HttpStatus.SUCCESS_ACCEPTED;
 
     private final Map<String, String> headers = new HashMap<String, String>();
     private final Map<String, String> cookies = Maps.newHashMap();
@@ -70,8 +71,8 @@ public class HttpResponseImpl implements
     }
 
     @Override
-    public void setStatusCode(int sc) {
-        statusCode = sc;
+    public void setStatus(HttpStatus status) {
+        this.status = status;
     }
 
     @Override
@@ -246,7 +247,7 @@ public class HttpResponseImpl implements
     }
 
     private String createInitalLineAndHeaders() {
-        StringBuilder sb = new StringBuilder(HttpUtil.createInitialLine(statusCode));
+        StringBuilder sb = new StringBuilder(status.line());
         for (Map.Entry<String, String> header : headers.entrySet()) {
             sb.append(header.getKey());
             sb.append(": ");

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/AsynchronousHttpClient.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/AsynchronousHttpClient.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/AsynchronousHttpClient.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/AsynchronousHttpClient.java Fri Aug  5 18:24:46 2011
@@ -30,7 +30,7 @@ import org.apache.deft.util.NopAsyncResu
 import org.apache.deft.util.UrlUtil;
 import org.apache.deft.web.AsyncCallback;
 import org.apache.deft.web.AsyncResult;
-import org.apache.deft.web.HttpVerb;
+import org.apache.deft.web.http.protocol.HttpVerb;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/Request.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/Request.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/Request.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/Request.java Fri Aug  5 18:24:46 2011
@@ -22,8 +22,8 @@ package org.apache.deft.web.http.client;
 import java.net.MalformedURLException;
 import java.net.URL;
 
-import org.apache.deft.web.HttpVerb;
-import org.apache.deft.web.http.ContentType;
+import org.apache.deft.web.http.protocol.ContentType;
+import org.apache.deft.web.http.protocol.HttpVerb;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Copied: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/ContentType.java (from r1153986, incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/ContentType.java)
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/ContentType.java?p2=incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/ContentType.java&p1=incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/ContentType.java&r1=1153986&r2=1154336&rev=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/ContentType.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/ContentType.java Fri Aug  5 18:24:46 2011
@@ -17,7 +17,7 @@
  *  under the License. 
  *  
  */
-package org.apache.deft.web.http;
+package org.apache.deft.web.http.protocol;
 
 /**
  * A collection of known content types, for convenience.

Added: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/HttpStatus.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/HttpStatus.java?rev=1154336&view=auto
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/HttpStatus.java (added)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/HttpStatus.java Fri Aug  5 18:24:46 2011
@@ -0,0 +1,215 @@
+/*
+ *  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.deft.web.http.protocol;
+
+/**
+ * An <code>Enumeration</code> of all known HTTP status codes.
+ */
+public enum HttpStatus {
+
+    /**
+     * 200 - OK
+     */
+    SUCCESS_OK(200, "HTTP/1.1 200 OK"),
+    /**
+     * 201 - Created
+     */
+    SUCCESS_CREATED(201, "HTTP/1.1 201 Created"),
+    /**
+     * 202 - Accepted
+     */
+    SUCCESS_ACCEPTED(202, "HTTP/1.1 202 Accepted"),
+    /**
+     * 203 - Non-Authoritative Information
+     */
+    SUCCESS_NON_AUTHORATIVE_INFORMATION(203, "HTTP/1.1 203 Non-Authoritative Information"),
+    /**
+     * 204 - No Content
+     */
+    SUCCESS_NO_CONTENT(204, "HTTP/1.1 204 No Content"),
+    /**
+     * 205 - Reset Content
+     */
+    SUCCESS_RESET_CONTENT(205, "HTTP/1.1 205 Reset Content"),
+    /**
+     * 206 - Created
+     */
+    SUCCESS_PARTIAL_CONTENT(206, "HTTP/1.1 206 Partial Content"),
+
+    /**
+     * 300 - Multiple Choices
+     */
+    REDIRECTION_MULTIPLE_CHOICES(300, "HTTP/1.1 300 Multiple Choices"),
+    /**
+     * 301 - Moved Permanently
+     */
+    REDIRECTION_MOVED_PERMANENTLY(301, "HTTP/1.1 301 Moved Permanently"),
+    /**
+     * 302 - Found / Moved Temporarily
+     */
+    REDIRECTION_FOUND(302, "HTTP/1.1 302 Found"),
+    /**
+     * 303 - See Others
+     */
+    REDIRECTION_SEE_OTHER(303, "HTTP/1.1 303 See Other"),
+    /**
+     * 304 - Not Modified
+     */
+    REDIRECTION_NOT_MODIFIED(304, "HTTP/1.1 304 Not Modified"),
+    /**
+     * 305 - Use Proxy
+     */
+    REDIRECTION_USE_PROXY(305, "HTTP/1.1 305 Use Proxy"),
+    /**
+     * 307 - Temporary Redirect
+     */
+    REDIRECTION_TEMPORARILY_REDIRECT(307, "HTTP/1.1 307 Temporary Redirect"),
+
+    /**
+     * 400 - Bad Request
+     */
+    CLIENT_ERROR_BAD_REQUEST(400, "HTTP/1.1 400 Bad Request"),
+    /**
+     * 401 - Unauthorized
+     */
+    CLIENT_ERROR_UNAUTHORIZED(401, "HTTP/1.1 401 Unauthorized"),
+    /**
+     * 403 - Forbidden
+     */
+    CLIENT_ERROR_FORBIDDEN(403, "HTTP/1.1 403 Forbidden"),
+    /**
+     * 404 - Not Found
+     */
+    CLIENT_ERROR_NOT_FOUND(404, "HTTP/1.1 404 Not Found"),
+    /**
+     * 405 - Method Not Allowed
+     */
+    CLIENT_ERROR_METHOD_NOT_ALLOWED(405, "HTTP/1.1 405 Method Not Allowed"),
+    /**
+     * 406 - Not Acceptable
+     */
+    CLIENT_ERROR_NOT_ACCEPTABLE(406, "HTTP/1.1 406 Not Acceptable"),
+    /**
+     * 407 - Proxy Authentication Required
+     */
+    CLIENT_ERROR_PROXY_AUTHENTICATION_REQUIRED(407, "HTTP/1.1 407 Proxy Authentication Required"),
+    /**
+     * 408 - Request Timeout
+     */
+    CLIENT_ERROR_REQUEST_TIMEOUT(408, "HTTP/1.1 408 Request Timeout"),
+    /**
+     * 409 - Conflict
+     */
+    CLIENT_ERROR_CONFLICT(409, "HTTP/1.1 409 Conflict"),
+    /**
+     * 410 - Gone
+     */
+    CLIENT_ERROR_GONE(410, "HTTP/1.1 410 Gone"),
+    /**
+     * 411 - Length Required
+     */
+    CLIENT_ERROR_LENGTH_REQUIRED(411, "HTTP/1.1 411 Length Required"),
+    /**
+     * 412 - Precondition Failed
+     */
+    CLIENT_ERROR_PRECONDITION_FAILED(412, "HTTP/1.1 412 Precondition Failed"),
+    /**
+     * 413 - Request Entity Too Large
+     */
+    CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE(413, "HTTP/1.1 413 Request Entity Too Large"),
+    /**
+     * 414 - Bad Request
+     */
+    CLIENT_ERROR_REQUEST_URI_TOO_LONG(414, "HTTP/1.1 414 Request-URI Too Long"),
+    /**
+     * 415 - Unsupported Media Type
+     */
+    CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE(415, "HTTP/1.1 415 Unsupported Media Type"),
+    /**
+     * 416 - Requested Range Not Satisfiable
+     */
+    CLIENT_ERROR_REQUESTED_RANGE_NOT_SATISFIABLE(416, "HTTP/1.1 416 Requested Range Not Satisfiable"),
+    /**
+     * 417 - Expectation Failed
+     */
+    CLIENT_ERROR_EXPECTATION_FAILED(417, "HTTP/1.1 417 Expectation Failed"),
+
+    /**
+     * 500 - Internal Server Error
+     */
+    SERVER_ERROR_INTERNAL_SERVER_ERROR(500, "HTTP/1.1 500 Internal Server Error"),
+    /**
+     * 501 - Not Implemented
+     */
+    SERVER_ERROR_NOT_IMPLEMENTED(501, "HTTP/1.1 501 Not Implemented"),
+    /**
+     * 502 - Bad Gateway
+     */
+    SERVER_ERROR_BAD_GATEWAY(502, "HTTP/1.1 502 Bad Gateway"),
+    /**
+     * 503 - Service Unavailable
+     */
+    SERVER_ERROR_SERVICE_UNAVAILABLE(503, "HTTP/1.1 503 Service Unavailable"),
+    /**
+     * 504 - Gateway Timeout
+     */
+    SERVER_ERROR_GATEWAY_TIMEOUT(504, "HTTP/1.1 504 Gateway Timeout"),
+    /**
+     * 505 - HTTP Version Not Supported
+     */
+    SERVER_ERROR_HTTP_VERSION_NOT_SUPPORTED(505, "HTTP/1.1 505 HTTP Version Not Supported");
+
+    /** The code associated with this status, for example "404" for "Not Found". */
+    private int code;
+
+    /**
+     * The line associated with this status, "HTTP/1.1 501 Not Implemented".
+     */
+    private String line;
+
+    /**
+     * Create an instance of this type.
+     * 
+     * @param code the status code.
+     * @param phrase the associated phrase.
+     */
+    private HttpStatus(int code, String phrase) {
+        this.code = code;
+        line = phrase;
+    }
+
+    /**
+     * Retrieve the status code for this instance.
+     * 
+     * @return the status code.
+     */
+    public int code() {
+        return code;
+    }
+
+    /**
+     * Retrieve the status line for this instance.
+     * 
+     * @return the status line.
+     */
+    public String line() {
+        return line + "\r\n";
+    }
+}

Propchange: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/HttpStatus.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/HttpVerb.java (from r1153986, incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpVerb.java)
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/HttpVerb.java?p2=incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/HttpVerb.java&p1=incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpVerb.java&r1=1153986&r2=1154336&rev=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpVerb.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/protocol/HttpVerb.java Fri Aug  5 18:24:46 2011
@@ -17,14 +17,56 @@
  *  under the License. 
  *  
  */
-package org.apache.deft.web;
+package org.apache.deft.web.http.protocol;
 
 /**
- * <code>Enumeration</code> of all available HTTP verbs, as defined by <a
+ * An <code>Enumeration</code> of all available HTTP verbs, as defined by <a
  * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">Hypertext
  * Transfer Protocol -- HTTP/1.1 (RFC 2616)</a>.
  */
 public enum HttpVerb {
 
-    GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT;
+    /**
+     * &quot;The OPTIONS method represents a request for information about the
+     * communication options available on the request/response chain identified
+     * by the Request-URI.&quot; (RFC 2616, 9.2)
+     */
+    OPTIONS,
+    /**
+     * &quotThe GET method means retrieve whatever information (in the form of
+     * an entity) is identified by the Request-URI.&quot; (RFC 2616, 9.3)
+     */
+    GET,
+    /**
+     * &quot;The HEAD method is identical to GET except that the server MUST NOT
+     * return a message-body in the response.&quot; (RFC 2616, 9.4)
+     */
+    HEAD,
+    /**
+     * &quot;The POST method is used to request that the origin server accept
+     * the entity enclosed in the request as a new subordinate of the resource
+     * identified by the Request-URI in the Request-Line.&quot; (RFC 2616, 9.5)
+     */
+    POST,
+    /**
+     * &quot;The PUT method requests that the enclosed entity be stored under
+     * the supplied Request-URI.&quot; (RFC 2616, 9.6)
+     */
+    PUT,
+    /**
+     * &quot;The DELETE method requests that the origin server delete the
+     * resource identified by the Request-URI.&quot; (RFC 2616, 9.7)
+     */
+    DELETE,
+    /**
+     * &quot;The TRACE method is used to invoke a remote, application-layer
+     * loop- back of the request message.&quot; (RFC 2616, 9.8)
+     */
+    TRACE,
+    /**
+     * &quot;This specification reserves the method name CONNECT for use with a
+     * proxy that can dynamically switch to being a tunnel &quot; (RFC 2616,
+     * 9.9)
+     */
+    CONNECT;
 }

Modified: incubator/deft/sandbox/src/test/java/org/apache/deft/configuration/AnnotationsScannerTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/configuration/AnnotationsScannerTest.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/configuration/AnnotationsScannerTest.java (original)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/configuration/AnnotationsScannerTest.java Fri Aug  5 18:24:46 2011
@@ -37,7 +37,7 @@ public class AnnotationsScannerTest {
         AnnotationsScanner scanner = new AnnotationsScanner();
         Map<String, RequestHandler> handlers = scanner.findHandlers("org.apache.deft.example.handler");
 
-        assertEquals(3, handlers.size());
+        assertEquals(4, handlers.size());
     }
 
     @Test

Modified: incubator/deft/sandbox/src/test/java/org/apache/deft/web/ApplicationTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/ApplicationTest.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/ApplicationTest.java (original)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/ApplicationTest.java Fri Aug  5 18:24:46 2011
@@ -20,6 +20,7 @@
 package org.apache.deft.web;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
 import java.util.HashMap;
@@ -110,16 +111,20 @@ public class ApplicationTest {
         assertEquals(NotFoundRequestHandler.getInstance(), app.getHandler(request));
 
         request = new HttpRequestImpl("GET / HTTP/1.1", headers);
-        assertEquals(handler1, app.getHandler(request));
+        assertFalse(handler1.equals(app.getHandler(request)));
+        assertEquals(handler1.getClass(), app.getHandler(request).getClass());
 
         request = new HttpRequestImpl("GET /persons/1911 HTTP/1.1", headers);
-        assertEquals(handler2, app.getHandler(request));
+        assertFalse(handler2.equals(app.getHandler(request)));
+        assertEquals(handler2.getClass(), app.getHandler(request).getClass());
 
         request = new HttpRequestImpl("GET /persons/phone_numbers HTTP/1.1", headers);
-        assertEquals(handler3, app.getHandler(request));
+        assertFalse(handler3.equals(app.getHandler(request)));
+        assertEquals(handler3.getClass(), app.getHandler(request).getClass());
 
         request = new HttpRequestImpl("GET /pets/123 HTTP/1.1", headers);
-        assertEquals(handler4, app.getHandler(request));
+        assertFalse(handler4.equals(app.getHandler(request)));
+        assertEquals(handler4.getClass(), app.getHandler(request).getClass());
 
         // Verify that BadRequestRequestHandler is returned if request does not
         // include Host header

Modified: incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTest.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTest.java (original)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTest.java Fri Aug  5 18:24:46 2011
@@ -43,6 +43,8 @@ import java.util.concurrent.ExecutorServ
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.deft.annotation.Asynchronous;
+import org.apache.deft.annotation.Authenticated;
 import org.apache.deft.configuration.Configuration;
 import org.apache.deft.example.keyvalue.KeyValueStore;
 import org.apache.deft.example.keyvalue.KeyValueStoreClient;
@@ -52,6 +54,7 @@ import org.apache.deft.web.handler.Reque
 import org.apache.deft.web.http.HttpException;
 import org.apache.deft.web.http.HttpRequest;
 import org.apache.deft.web.http.client.AsynchronousHttpClient;
+import org.apache.deft.web.http.protocol.HttpStatus;
 import org.apache.http.Header;
 import org.apache.http.HttpResponse;
 import org.apache.http.ProtocolVersion;
@@ -179,7 +182,7 @@ public class DeftSystemTest {
     private static class ThrowingHttpExceptionRequestHandler extends RequestHandler {
         @Override
         public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            throw new HttpException(500, "exception message");
+            throw new HttpException(HttpStatus.SERVER_ERROR_INTERNAL_SERVER_ERROR, "exception message");
         }
     }
 
@@ -187,21 +190,21 @@ public class DeftSystemTest {
         @Asynchronous
         @Override
         public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            throw new HttpException(500, "exception message");
+            throw new HttpException(HttpStatus.SERVER_ERROR_INTERNAL_SERVER_ERROR, "exception message");
         }
     }
 
     public static class NoBodyRequestHandler extends RequestHandler {
         @Override
         public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.setStatusCode(200);
+            response.setStatus(HttpStatus.SUCCESS_ACCEPTED);
         }
     }
 
     public static class MovedPermanentlyRequestHandler extends RequestHandler {
         @Override
         public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.setStatusCode(301);
+            response.setStatus(HttpStatus.REDIRECTION_MOVED_PERMANENTLY);
             response.setHeader("Location", "/");
         }
     }

Added: incubator/deft/sandbox/src/test/java/org/apache/deft/web/handler/RequestHandlerFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/handler/RequestHandlerFactoryTest.java?rev=1154336&view=auto
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/handler/RequestHandlerFactoryTest.java (added)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/handler/RequestHandlerFactoryTest.java Fri Aug  5 18:24:46 2011
@@ -0,0 +1,51 @@
+/*
+ *  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.deft.web.handler;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+/**
+ * Test cases for {@link RequestHandlerFactory}.
+ */
+public class RequestHandlerFactoryTest {
+
+    private class TestRequestHandler extends RequestHandler {
+        // Do nothing.
+    }
+
+    @Test
+    public void testCloneHandler() {
+
+        TestRequestHandler handler = new TestRequestHandler();
+
+        RequestHandler created = RequestHandlerFactory.cloneHandler(handler);
+        assertEquals(handler.getClass(), created.getClass());
+    }
+
+    @Test
+    public void testCloneHandlerHandlesNull() {
+
+        RequestHandler created = RequestHandlerFactory.cloneHandler(null);
+        assertNull(created);
+    }
+}

Propchange: incubator/deft/sandbox/src/test/java/org/apache/deft/web/handler/RequestHandlerFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/deft/sandbox/src/test/java/org/apache/deft/web/handler/RequestHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/handler/RequestHandlerTest.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/handler/RequestHandlerTest.java (original)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/handler/RequestHandlerTest.java Fri Aug  5 18:24:46 2011
@@ -20,14 +20,18 @@
 package org.apache.deft.web.handler;
 
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 
-import org.apache.deft.web.Asynchronous;
-import org.apache.deft.web.Authenticated;
-import org.apache.deft.web.HttpVerb;
-import org.apache.deft.web.handler.RequestHandler;
+import org.apache.deft.annotation.Asynchronous;
+import org.apache.deft.annotation.Authenticated;
 import org.apache.deft.web.http.HttpRequest;
 import org.apache.deft.web.http.HttpResponse;
+import org.apache.deft.web.http.protocol.HttpStatus;
+import org.apache.deft.web.http.protocol.HttpVerb;
 import org.junit.Test;
 
 public class RequestHandlerTest {
@@ -55,8 +59,13 @@ public class RequestHandlerTest {
 
     }
 
+    private class TestRequestHandler extends RequestHandler {
+        // Do nothing.
+    }
+
     @Test
     public void testAsynchronousAnnotations() {
+
         RequestHandler rh1 = new RequestHandler1();
         RequestHandler rh2 = new RequestHandler2();
 
@@ -79,4 +88,66 @@ public class RequestHandlerTest {
         assertFalse(rh2.isMethodAuthenticated(HttpVerb.PUT));
         assertTrue(rh2.isMethodAuthenticated(HttpVerb.POST));
     }
+
+    @Test
+    public void testGet() {
+
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        new TestRequestHandler().get(request, response);
+        verify(response, times(1)).setStatus(HttpStatus.SERVER_ERROR_NOT_IMPLEMENTED);
+        verify(response, times(1)).write("");
+    }
+
+    @Test
+    public void testPost() {
+
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        new TestRequestHandler().post(request, response);
+        verify(response, times(1)).setStatus(HttpStatus.SERVER_ERROR_NOT_IMPLEMENTED);
+        verify(response, times(1)).write("");
+    }
+
+    @Test
+    public void testPut() {
+
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        new TestRequestHandler().put(request, response);
+        verify(response, times(1)).setStatus(HttpStatus.SERVER_ERROR_NOT_IMPLEMENTED);
+        verify(response, times(1)).write("");
+    }
+
+    @Test
+    public void testDelete() {
+
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        new TestRequestHandler().delete(request, response);
+        verify(response, times(1)).setStatus(HttpStatus.SERVER_ERROR_NOT_IMPLEMENTED);
+        verify(response, times(1)).write("");
+    }
+
+    @Test
+    public void testHead() {
+
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        new TestRequestHandler().head(request, response);
+        verify(response, times(1)).setStatus(HttpStatus.SERVER_ERROR_NOT_IMPLEMENTED);
+        verify(response, times(1)).write("");
+    }
+
+    @Test
+    public void testGetCurrentUser() {
+
+        HttpRequest request = mock(HttpRequest.class);
+        assertNull(new TestRequestHandler().getCurrentUser(request));
+    }
 }

Added: incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpExceptionTest.java?rev=1154336&view=auto
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpExceptionTest.java (added)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpExceptionTest.java Fri Aug  5 18:24:46 2011
@@ -0,0 +1,50 @@
+/*
+ *  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.deft.web.http;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.deft.web.http.protocol.HttpStatus;
+import org.junit.Test;
+
+/**
+ * Test cases for {@link HttpException}.
+ */
+public class HttpExceptionTest {
+
+    @Test
+    public void testHttpException() {
+
+        HttpException exception = new HttpException(HttpStatus.SERVER_ERROR_INTERNAL_SERVER_ERROR);
+
+        assertEquals(HttpStatus.SERVER_ERROR_INTERNAL_SERVER_ERROR, exception.getStatus());
+        assertTrue(exception.getMessage().isEmpty());
+    }
+
+    @Test
+    public void testHttpExceptionWithMessage() {
+
+        HttpException exception = new HttpException(HttpStatus.CLIENT_ERROR_NOT_FOUND, "testMessage");
+
+        assertEquals(HttpStatus.CLIENT_ERROR_NOT_FOUND, exception.getStatus());
+        assertEquals("testMessage", exception.getMessage());
+    }
+}

Propchange: incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpRequestDispatcherTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpRequestDispatcherTest.java?rev=1154336&view=auto
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpRequestDispatcherTest.java (added)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpRequestDispatcherTest.java Fri Aug  5 18:24:46 2011
@@ -0,0 +1,192 @@
+/*
+ *  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.deft.web.http;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.deft.annotation.Asynchronous;
+import org.apache.deft.web.handler.RequestHandler;
+import org.apache.deft.web.http.protocol.HttpStatus;
+import org.apache.deft.web.http.protocol.HttpVerb;
+import org.junit.Test;
+
+/**
+ * Test cases for {@link HttpRequestDispatcher}.
+ */
+public class HttpRequestDispatcherTest {
+
+    private class TestRequestHandler extends RequestHandler {
+
+        @Override
+        public void get(HttpRequest request, HttpResponse response) {
+            response.write("get");
+        }
+
+        @Override
+        public void post(HttpRequest request, HttpResponse response) {
+            response.write("post");
+        }
+
+        @Override
+        public void head(HttpRequest request, HttpResponse response) {
+            response.write("head");
+        }
+
+        @Override
+        public void put(HttpRequest request, HttpResponse response) {
+            response.write("put");
+        }
+
+        @Override
+        public void delete(HttpRequest request, HttpResponse response) {
+            response.write("delete");
+        }
+    }
+
+    @Test
+    public void testDispatchForGet() {
+
+        RequestHandler handler = new TestRequestHandler();
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        when(request.getMethod()).thenReturn(HttpVerb.GET);
+
+        HttpRequestDispatcher.dispatch(handler, request, response);
+        verify(response, times(1)).write("get");
+    }
+
+    @Test
+    public void testDispatchForPost() {
+
+        RequestHandler handler = new TestRequestHandler();
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        when(request.getMethod()).thenReturn(HttpVerb.POST);
+
+        HttpRequestDispatcher.dispatch(handler, request, response);
+        verify(response, times(1)).write("post");
+    }
+
+    @Test
+    public void testDispatchForHead() {
+
+        RequestHandler handler = new TestRequestHandler();
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        when(request.getMethod()).thenReturn(HttpVerb.HEAD);
+
+        HttpRequestDispatcher.dispatch(handler, request, response);
+        verify(response, times(1)).write("head");
+    }
+
+    @Test
+    public void testDispatchForPut() {
+
+        RequestHandler handler = new TestRequestHandler();
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        when(request.getMethod()).thenReturn(HttpVerb.PUT);
+
+        HttpRequestDispatcher.dispatch(handler, request, response);
+        verify(response, times(1)).write("put");
+    }
+
+    @Test
+    public void testDispatchForDelete() {
+
+        RequestHandler handler = new TestRequestHandler();
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        when(request.getMethod()).thenReturn(HttpVerb.DELETE);
+
+        HttpRequestDispatcher.dispatch(handler, request, response);
+        verify(response, times(1)).write("delete");
+    }
+
+    @Test
+    public void testDispatchForOptions() {
+
+        RequestHandler handler = new TestRequestHandler();
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        when(request.getMethod()).thenReturn(HttpVerb.OPTIONS);
+
+        HttpRequestDispatcher.dispatch(handler, request, response);
+        verify(response, times(0)).write(anyString());
+    }
+
+    @Test
+    public void testDispatchForTrace() {
+
+        RequestHandler handler = new TestRequestHandler();
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        when(request.getMethod()).thenReturn(HttpVerb.TRACE);
+
+        HttpRequestDispatcher.dispatch(handler, request, response);
+        verify(response, times(0)).write(anyString());
+    }
+
+    @Test
+    public void testDispatchForConnect() {
+
+        RequestHandler handler = new TestRequestHandler();
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        when(request.getMethod()).thenReturn(HttpVerb.CONNECT);
+
+        HttpRequestDispatcher.dispatch(handler, request, response);
+        verify(response, times(0)).write(anyString());
+    }
+
+    @Test
+    public void testDispatchForHttpException() {
+
+        RequestHandler handler = new TestRequestHandler() {
+            @Override
+            @Asynchronous
+            public void get(HttpRequest request, HttpResponse response) {
+                throw new HttpException(HttpStatus.CLIENT_ERROR_BAD_REQUEST, "testMessage");
+            }
+        };
+
+        HttpRequest request = mock(HttpRequest.class);
+        HttpResponse response = mock(HttpResponse.class);
+
+        when(request.getMethod()).thenReturn(HttpVerb.GET);
+
+        HttpRequestDispatcher.dispatch(handler, request, response);
+        verify(response, times(1)).setStatus(HttpStatus.CLIENT_ERROR_BAD_REQUEST);
+        verify(response, times(1)).write("testMessage");
+        verify(response, times(1)).finish();
+    }
+}

Propchange: incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/HttpRequestDispatcherTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/AsynchronousHttpClientTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/AsynchronousHttpClientTest.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/AsynchronousHttpClientTest.java (original)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/AsynchronousHttpClientTest.java Fri Aug  5 18:24:46 2011
@@ -19,15 +19,13 @@
  */
 package org.apache.deft.web.http.client;
 
-import static org.junit.Assert.*;
 import static org.apache.deft.web.http.client.AsynchronousHttpClient.HTTP_VERSION;
 import static org.apache.deft.web.http.client.AsynchronousHttpClient.NEWLINE;
 import static org.apache.deft.web.http.client.AsynchronousHttpClient.USER_AGENT_HEADER;
+import static org.junit.Assert.assertEquals;
 
 import org.apache.deft.web.AsyncResult;
-import org.apache.deft.web.HttpVerb;
-import org.apache.deft.web.http.client.AsynchronousHttpClient;
-import org.apache.deft.web.http.client.Response;
+import org.apache.deft.web.http.protocol.HttpVerb;
 import org.junit.Test;
 
 /**
@@ -50,7 +48,7 @@ public class AsynchronousHttpClientTest 
         String expected = HttpVerb.GET + " /path/ " + HTTP_VERSION;
         expected += "Host: testurl.com" + NEWLINE + USER_AGENT_HEADER;
         expected += NEWLINE;
-        
+
         String actual = client.makeRequestLineAndHeaders();
 
         assertEquals(expected, actual);
@@ -75,33 +73,33 @@ public class AsynchronousHttpClientTest 
         expected += NEWLINE + NEWLINE;
         expected += "name=value";
         expected += NEWLINE;
-        
+
         String actual = client.makeRequestLineAndHeaders();
 
         assertEquals(expected, actual);
     }
-    
+
     @Test
     public void testMakeRequestLineAndHeadersWithZeroLengthBody() {
-        
+
         AsynchronousHttpClient client = new AsynchronousHttpClient() {
             @Override
             protected void doFetch(AsyncResult<Response> callback, long requestStarted) {
                 // Do nothing.
             }
         };
-        
+
         client.post("http://testurl.com/path/", "", null);
-        
+
         String expected = HttpVerb.POST + " /path/ " + HTTP_VERSION;
         expected += "Host: testurl.com" + NEWLINE + USER_AGENT_HEADER;
         expected += "Content-Type: application/x-www-form-urlencoded" + NEWLINE;
         expected += "Content-Length: 0";
         expected += NEWLINE + NEWLINE;
         expected += NEWLINE;
-        
+
         String actual = client.makeRequestLineAndHeaders();
-        
+
         assertEquals(expected, actual);
     }
 }

Modified: incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/RequestTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/RequestTest.java?rev=1154336&r1=1154335&r2=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/RequestTest.java (original)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/RequestTest.java Fri Aug  5 18:24:46 2011
@@ -24,9 +24,8 @@ import static org.junit.Assert.assertTru
 
 import java.util.Arrays;
 
-import org.apache.deft.web.HttpVerb;
-import org.apache.deft.web.http.ContentType;
-import org.apache.deft.web.http.client.Request;
+import org.apache.deft.web.http.protocol.ContentType;
+import org.apache.deft.web.http.protocol.HttpVerb;
 import org.junit.Test;
 
 import com.google.common.base.Charsets;

Copied: incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/ContentTypeTest.java (from r1153986, incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/ContentTypeTest.java)
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/ContentTypeTest.java?p2=incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/ContentTypeTest.java&p1=incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/ContentTypeTest.java&r1=1153986&r2=1154336&rev=1154336&view=diff
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/ContentTypeTest.java (original)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/ContentTypeTest.java Fri Aug  5 18:24:46 2011
@@ -17,11 +17,10 @@
  *  under the License. 
  *  
  */
-package org.apache.deft.web.http;
+package org.apache.deft.web.http.protocol;
 
 import static org.junit.Assert.assertTrue;
 
-import org.apache.deft.web.http.ContentType;
 import org.junit.Test;
 
 /**

Added: incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/HttpStatusTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/HttpStatusTest.java?rev=1154336&view=auto
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/HttpStatusTest.java (added)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/HttpStatusTest.java Fri Aug  5 18:24:46 2011
@@ -0,0 +1,66 @@
+/*
+ *  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.deft.web.http.protocol;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Test cases for {@link HttpStatus}.
+ */
+public class HttpStatusTest {
+
+    private static int STATUS_CODE_COUNT = 37;
+
+    @Test
+    public void testCount() {
+        assertEquals(STATUS_CODE_COUNT, HttpStatus.values().length);
+    }
+
+    @Test
+    public void testCode() {
+
+        for (final HttpStatus status : HttpStatus.values()) {
+            if (status.name().startsWith("SUCCESS")) {
+                assertTrue("Incorrect: " + status.name(), status.code() >= 200 && status.code() < 300);
+            } else if (status.name().startsWith("REDIRECTION")) {
+                assertTrue("Incorrect: " + status.name(), status.code() >= 300 && status.code() < 400);
+            } else if (status.name().startsWith("CLIENT_ERROR")) {
+                assertTrue("Incorrect: " + status.name(), status.code() >= 400 && status.code() < 500);
+            } else if (status.name().startsWith("SERVER_ERROR")) {
+                assertTrue("Incorrect: " + status.name(), status.code() >= 500 && status.code() < 600);
+            } else {
+                assertTrue("Unknown: " + status.name(), false);
+            }
+        }
+    }
+
+    @Test
+    public void testLine() {
+
+        for (final HttpStatus status : HttpStatus.values()) {
+            assertNotNull(status.line());
+            assertTrue("Incorrect: " + status.name(), status.line().startsWith("HTTP/1.1 " + status.code()));
+        }
+    }
+}

Propchange: incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/protocol/HttpStatusTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message