You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/10/09 09:46:56 UTC

[2/4] git commit: CAMEL-7899 Fixed the same issue in camel-netty-http

CAMEL-7899 Fixed the same issue in camel-netty-http


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

Branch: refs/heads/master
Commit: 2a45170bb2c9c52d61b4fe38f6fabd4845b9912b
Parents: 892d369
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Oct 9 15:37:35 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Oct 9 15:37:35 2014 +0800

----------------------------------------------------------------------
 .../netty/http/DefaultContextPathMatcher.java   |  4 +--
 .../netty/http/RestContextPathMatcher.java      | 26 +++++++++++++++++++-
 .../HttpServerMultiplexChannelHandler.java      |  4 +--
 .../http/rest/RestNettyHttpPojoInOutTest.java   | 18 +++++++++++++-
 .../netty/http/rest/RestPathMatchingTest.java   |  2 +-
 5 files changed, 47 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2a45170b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java
index 9f7d98f..9ba2248 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/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/2a45170b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/RestContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/RestContextPathMatcher.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/RestContextPathMatcher.java
index 8e35f50..efc9258 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/RestContextPathMatcher.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/RestContextPathMatcher.java
@@ -24,10 +24,12 @@ import java.util.Locale;
 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 +100,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/2a45170b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
index b452bb8..8c835e2 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
@@ -72,7 +72,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
         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));
     }
 
@@ -80,7 +80,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
         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/2a45170b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java
index 4709fef..355fe61 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java
@@ -24,13 +24,22 @@ 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("netty-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("netty-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 +52,16 @@ 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/2a45170b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestPathMatchingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestPathMatchingTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestPathMatchingTest.java
index af364ae..b128286 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestPathMatchingTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestPathMatchingTest.java
@@ -21,7 +21,7 @@ import org.apache.camel.component.netty.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));