camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [1/2] camel git commit: CAMEL-11316: Added support for HTTP OPTIONS in camel-restlet
Date Mon, 21 Aug 2017 08:42:04 GMT
Repository: camel
Updated Branches:
  refs/heads/master 16cac67c1 -> ac1cd9500


CAMEL-11316: Added support for HTTP OPTIONS in camel-restlet


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d78a658e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d78a658e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d78a658e

Branch: refs/heads/master
Commit: d78a658e976b60c5072ab7d353569d15915e9518
Parents: 16cac67
Author: aldettinger <aldettinger@gmail.com>
Authored: Mon Aug 14 15:49:23 2017 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Mon Aug 21 10:40:03 2017 +0200

----------------------------------------------------------------------
 .../component/restlet/MethodBasedRouter.java    |  6 +++--
 .../component/restlet/RestletComponent.java     | 26 +++++++++++---------
 .../restlet/RestRestletHttpOptionsTest.java     |  5 ++--
 3 files changed, 21 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d78a658e/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/MethodBasedRouter.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/MethodBasedRouter.java
b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/MethodBasedRouter.java
index b9518c3..7e78245 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/MethodBasedRouter.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/MethodBasedRouter.java
@@ -50,13 +50,15 @@ class MethodBasedRouter extends Restlet {
         LOG.debug("MethodRouter ({}) received request method: {}", uriPattern, method);
         
         Restlet target = routes.get(method);
+        if (target == null || org.restlet.data.Method.OPTIONS.equals(method)) {
+            // must include list of allowed methods
+            response.setAllowedMethods(routes.keySet());
+        }
         if (target != null) {
             target.handle(request, response);
         } else {
             LOG.debug("MethodRouter ({}) method not allowed: {}", uriPattern, method);
             response.setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
-            // must include list of allowed methods
-            response.setAllowedMethods(routes.keySet());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/d78a658e/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
index e2f1b71..c01a1ea 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
@@ -22,6 +22,7 @@ import java.security.GeneralSecurityException;
 import java.security.InvalidParameterException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -284,13 +285,16 @@ public class RestletComponent extends HeaderFilterStrategyComponent
implements R
         }
 
         for (MethodBasedRouter router : routesToRemove) {
+
+            List<Method> methods = new ArrayList<>();
+            Collections.addAll(methods, Method.OPTIONS);
             if (endpoint.getRestletMethods() != null) {
-                Method[] methods = endpoint.getRestletMethods();
-                for (Method method : methods) {
-                    router.removeRoute(method);
-                }
+                Collections.addAll(methods, endpoint.getRestletMethods());
             } else {
-                router.removeRoute(endpoint.getRestletMethod());
+                Collections.addAll(methods, endpoint.getRestletMethod());
+            }
+            for (Method method : methods) {
+                router.removeRoute(method);
             }
 
             if (LOG.isDebugEnabled()) {
@@ -488,14 +492,14 @@ public class RestletComponent extends HeaderFilterStrategyComponent
implements R
             LOG.debug("Target has been set to guard: {}", guard);
         }
 
+        List<Method> methods = new ArrayList<>();
+        Collections.addAll(methods, Method.OPTIONS);
         if (endpoint.getRestletMethods() != null) {
-            Method[] methods = endpoint.getRestletMethods();
-            for (Method method : methods) {
-                router.addRoute(method, target);
-                LOG.debug("Attached restlet uriPattern: {} method: {}", uriPattern, method);
-            }
+            Collections.addAll(methods, endpoint.getRestletMethods());
         } else {
-            Method method = endpoint.getRestletMethod();
+            Collections.addAll(methods, endpoint.getRestletMethod());
+        }
+        for (Method method : methods) {
             router.addRoute(method, target);
             LOG.debug("Attached restlet uriPattern: {} method: {}", uriPattern, method);
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/d78a658e/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletHttpOptionsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletHttpOptionsTest.java
b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletHttpOptionsTest.java
index e862573..6d1ecad 100644
--- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletHttpOptionsTest.java
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletHttpOptionsTest.java
@@ -25,7 +25,6 @@ import org.junit.Test;
 /**
  * @version 
  */
-@Ignore("Not supported by camel-restlet yet")
 public class RestRestletHttpOptionsTest extends RestletTestSupport {
 
     @Test
@@ -38,12 +37,12 @@ public class RestRestletHttpOptionsTest extends RestletTestSupport {
         });
 
         assertEquals(200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
-        assertEquals("OPTIONS,GET", exchange.getOut().getHeader("ALLOW"));
+        assertEquals("GET, OPTIONS", exchange.getOut().getHeader("ALLOW"));
         assertEquals("", exchange.getOut().getBody(String.class));
 
         exchange = fluentTemplate.to("http://localhost:" + portNum + "/users/v1/123").withHeader(Exchange.HTTP_METHOD,
"OPTIONS").send();
         assertEquals(200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
-        assertEquals("OPTIONS,PUT", exchange.getOut().getHeader("ALLOW"));
+        assertEquals("OPTIONS, PUT", exchange.getOut().getHeader("ALLOW"));
         assertEquals("", exchange.getOut().getBody(String.class));
     }
 


Mime
View raw message