You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/09/06 05:47:39 UTC

[camel] branch master updated (4b8aafd -> f7cacf5)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 4b8aafd  Fix typo in RestDefinition#outTypeList java doc
     new 0e7ba6a  CAMEL-12320: camel-restlet - Should match better on uri pattern and return 404 for invalid urls
     new f7cacf5  Camel-restlet: Removed a system.out.println statement from test

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/restlet/MethodBasedRouter.java | 29 ++++++++++++++--------
 ...etFaultTest.java => RestletInvalidURLTest.java} | 24 +++++++-----------
 .../restlet/RestletProducerSynchronouslyTest.java  |  2 +-
 .../restlet/SpringRestRestletPojoInOutTest.java    |  1 -
 4 files changed, 29 insertions(+), 27 deletions(-)
 copy components/camel-restlet/src/test/java/org/apache/camel/component/restlet/{RestletFaultTest.java => RestletInvalidURLTest.java} (72%)


[camel] 01/02: CAMEL-12320: camel-restlet - Should match better on uri pattern and return 404 for invalid urls

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0e7ba6ab63e9466711fa6c758db5d73021c16223
Author: Ramu <kk...@redhat.com>
AuthorDate: Wed Sep 5 22:13:22 2018 +0530

    CAMEL-12320: camel-restlet - Should match better on uri pattern and return 404 for invalid urls
---
 .../camel/component/restlet/MethodBasedRouter.java | 29 +++++++-----
 .../component/restlet/RestletInvalidURLTest.java   | 51 ++++++++++++++++++++++
 .../restlet/RestletProducerSynchronouslyTest.java  |  2 +-
 .../restlet/SpringRestRestletPojoInOutTest.java    |  1 -
 4 files changed, 71 insertions(+), 12 deletions(-)

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 d11ceae..d631249 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
@@ -20,6 +20,7 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.apache.camel.support.RestConsumerContextPathMatcher;
 import org.restlet.Request;
 import org.restlet.Response;
 import org.restlet.Restlet;
@@ -48,18 +49,26 @@ class MethodBasedRouter extends Restlet {
     public void handle(Request request, Response response) {
         Method method = request.getMethod();
         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);
+        String requestPath = request.getResourceRef().getPath();
+        String consumerPath = request.getRootRef().getPath();
+        boolean matchOnUriPrefix = false;
+        boolean  result = RestConsumerContextPathMatcher.matchPath(requestPath, consumerPath, matchOnUriPrefix);
+        if (result) {
+            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);
+            }
         } else {
-            LOG.debug("MethodRouter ({}) method not allowed: {}", uriPattern, method);
-            response.setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
+            response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
         }
+    
     }
 
     void addRoute(Method method, Restlet target) {
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletInvalidURLTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletInvalidURLTest.java
new file mode 100644
index 0000000..a40597e
--- /dev/null
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletInvalidURLTest.java
@@ -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.camel.component.restlet;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.junit.Test;
+
+public class RestletInvalidURLTest extends RestletTestSupport {
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("restlet:http://localhost:" + portNum + "/users/{username}?restletMethod=POST").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        
+                    }
+                });
+                from("direct:start").to("restlet:http://localhost:" + portNum + "/users/tester?restletMethod=POST");
+            }
+        };
+    }
+    
+    @Test
+    public void testExceptionResponse() throws Exception {
+        HttpResponse response = doExecute(new HttpPost("http://localhost:" + portNum + "/users/123/45"));
+        System.out.println(response.getStatusLine().getStatusCode());
+        assertEquals(404, response.getStatusLine().getStatusCode());
+    }
+   
+}
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerSynchronouslyTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerSynchronouslyTest.java
index 96e781b..39793cc 100644
--- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerSynchronouslyTest.java
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerSynchronouslyTest.java
@@ -49,7 +49,7 @@ public class RestletProducerSynchronouslyTest extends RestletTestSupport {
 
                 from("direct:start").to("restlet:http://localhost:" + portNum + "/users/123/basic").to("log:reply");
                 
-                from("direct:delete").to("restlet:http://localhost:" + portNum + "/users/123/basicrestletMethod=DELETE");
+                from("direct:delete").to("restlet:http://localhost:" + portNum + "/users/123/basic");
 
                 from("restlet:http://localhost:" + portNum + "/users/{id}/basic?restletMethods=GET,DELETE")
                     .process(new Processor() {
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/SpringRestRestletPojoInOutTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/SpringRestRestletPojoInOutTest.java
index 6b11b97..73e1cf1 100644
--- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/SpringRestRestletPojoInOutTest.java
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/SpringRestRestletPojoInOutTest.java
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 package org.apache.camel.component.restlet;
-import org.junit.Before;
 
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.spring.CamelSpringTestSupport;


[camel] 02/02: Camel-restlet: Removed a system.out.println statement from test

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f7cacf51b799b7e9c4cff37e4575edd381c0cdb7
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Sep 6 07:47:04 2018 +0200

    Camel-restlet: Removed a system.out.println statement from test
---
 .../java/org/apache/camel/component/restlet/RestletInvalidURLTest.java   | 1 -
 1 file changed, 1 deletion(-)

diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletInvalidURLTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletInvalidURLTest.java
index a40597e..9c69abb 100644
--- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletInvalidURLTest.java
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletInvalidURLTest.java
@@ -44,7 +44,6 @@ public class RestletInvalidURLTest extends RestletTestSupport {
     @Test
     public void testExceptionResponse() throws Exception {
         HttpResponse response = doExecute(new HttpPost("http://localhost:" + portNum + "/users/123/45"));
-        System.out.println(response.getStatusLine().getStatusCode());
         assertEquals(404, response.getStatusLine().getStatusCode());
     }