camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [3/7] git commit: CAMEL-7899 merged the patch to camel-netty4-http
Date Thu, 09 Oct 2014 08:15:51 GMT
CAMEL-7899 merged the patch to camel-netty4-http


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

Branch: refs/heads/camel-2.14.x
Commit: e2cd838cf5ccf30003e1952a4a58d4d14cd3c5be
Parents: 992a2bb
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Thu Oct 9 15:38:00 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Thu Oct 9 16:14:32 2014 +0800

----------------------------------------------------------------------
 .../netty4/http/DefaultContextPathMatcher.java  |  4 +--
 .../netty4/http/RestContextPathMatcher.java     | 27 +++++++++++++++++++-
 .../HttpServerMultiplexChannelHandler.java      |  4 +--
 .../http/rest/RestNettyHttpPojoInOutTest.java   | 19 +++++++++++++-
 .../netty4/http/rest/RestPathMatchingTest.java  |  2 +-
 5 files changed, 49 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e2cd838c/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultContextPathMatcher.java
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultContextPathMatcher.java
index f30cc66..96dbe78 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultContextPathMatcher.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultContextPathMatcher.java
@@ -23,8 +23,8 @@ import java.util.Locale;
  */
 public class DefaultContextPathMatcher implements ContextPathMatcher {
 
-    private final String path;
-    private final boolean matchOnUriPrefix;
+    protected final String path;
+    protected final boolean matchOnUriPrefix;
 
     public DefaultContextPathMatcher(String path, boolean matchOnUriPrefix) {
         this.path = path.toLowerCase(Locale.US);

http://git-wip-us.apache.org/repos/asf/camel/blob/e2cd838c/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/RestContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/RestContextPathMatcher.java
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/RestContextPathMatcher.java
index 587eef7..a07435d 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/RestContextPathMatcher.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/RestContextPathMatcher.java
@@ -18,16 +18,19 @@ package org.apache.camel.component.netty4.http;
 
 import java.util.Locale;
 
+
 /**
  * A {@link org.apache.camel.component.netty.http.ContextPathMatcher} that supports the Rest
DSL.
  */
 public class RestContextPathMatcher extends DefaultContextPathMatcher {
 
     private final String rawPath;
+    private final String comparePath;
 
-    public RestContextPathMatcher(String rawPath, String path, boolean matchOnUriPrefix)
{
+    public RestContextPathMatcher(String rawPath, String path, String restrictMethod, boolean
matchOnUriPrefix) {
         super(path, matchOnUriPrefix);
         this.rawPath = rawPath;
+        this.comparePath = rawPath + "?" + restrictMethod;
     }
 
     @Override
@@ -98,5 +101,27 @@ public class RestContextPathMatcher extends DefaultContextPathMatcher
{
         // assume matching
         return true;
     }
+    
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        RestContextPathMatcher that = (RestContextPathMatcher) o;
+
+        if (comparePath.equals(that.comparePath))  {
+            return super.equals(o);
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return 31 * comparePath.hashCode() + (matchOnUriPrefix ? 1 : 0);
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/e2cd838c/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
index b83cd45..348641f 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
@@ -74,7 +74,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
         String rawPath = consumer.getConfiguration().getPath();
         String path = pathAsKey(consumer.getConfiguration().getPath());
         // use rest path matcher in case Rest DSL is in use
-        ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getConfiguration().isMatchOnUriPrefix());
+        ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getEndpoint().getHttpMethodRestrict(),
consumer.getConfiguration().isMatchOnUriPrefix());
         consumers.put(matcher, new HttpServerChannelHandler(consumer));
     }
 
@@ -82,7 +82,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
         String rawPath = consumer.getConfiguration().getPath();
         String path = pathAsKey(consumer.getConfiguration().getPath());
         // use rest path matcher in case Rest DSL is in use
-        ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getConfiguration().isMatchOnUriPrefix());
+        ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getEndpoint().getHttpMethodRestrict(),
consumer.getConfiguration().isMatchOnUriPrefix());
         consumers.remove(matcher);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/e2cd838c/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpPojoInOutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpPojoInOutTest.java
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpPojoInOutTest.java
index a783b91..e215a9c 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpPojoInOutTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpPojoInOutTest.java
@@ -24,13 +24,21 @@ import org.junit.Test;
 public class RestNettyHttpPojoInOutTest extends BaseNettyTest {
 
     @Test
-    public void testJettyPojoInOut() throws Exception {
+    public void testNettyPojoInOut() throws Exception {
         String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
         String out = template.requestBody("netty4-http:http://localhost:" + getPort() + "/users/lives",
body, String.class);
 
         assertNotNull(out);
         assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
     }
+    
+    @Test
+    public void testNettyGetRequest() throws Exception {
+        String out = template.requestBody("netty4-http:http://localhost:" + getPort() + "/users/lives",
null, String.class);
+
+        assertNotNull(out);
+        assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
+    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -43,9 +51,18 @@ public class RestNettyHttpPojoInOutTest extends BaseNettyTest {
 
                 // use the rest DSL to define the rest services
                 rest("/users/")
+                    // just return the default country here
+                    .get("lives").to("direct:start")
                     .post("lives").type(UserPojo.class).outType(CountryPojo.class)
                         .route()
                         .bean(new UserService(), "livesWhere");
+            
+                CountryPojo country = new CountryPojo();
+                country.setIso("EN");
+                country.setCountry("England");
+                
+                from("direct:start").transform().constant(country);
+                
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/e2cd838c/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestPathMatchingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestPathMatchingTest.java
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestPathMatchingTest.java
index b297288..228a4c5 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestPathMatchingTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestPathMatchingTest.java
@@ -21,7 +21,7 @@ import org.apache.camel.component.netty4.http.RestContextPathMatcher;
 
 public class RestPathMatchingTest extends TestCase {
 
-    private RestContextPathMatcher matcher = new RestContextPathMatcher("", "", true);
+    private RestContextPathMatcher matcher = new RestContextPathMatcher("", "", null, true);
 
     public void testRestPathMatcher() throws Exception {
         assertTrue(matcher.matchRestPath("/foo/", "/foo/", true));


Mime
View raw message