Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 57A4D1722E for ; Thu, 9 Oct 2014 08:15:50 +0000 (UTC) Received: (qmail 96035 invoked by uid 500); 9 Oct 2014 08:15:49 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 95888 invoked by uid 500); 9 Oct 2014 08:15:49 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 95635 invoked by uid 99); 9 Oct 2014 08:15:49 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Oct 2014 08:15:49 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 7FA50995772; Thu, 9 Oct 2014 08:15:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ningjiang@apache.org To: commits@camel.apache.org Date: Thu, 09 Oct 2014 08:15:51 -0000 Message-Id: <0aa348ce3e99441ea018da34c0cbc024@git.apache.org> In-Reply-To: <1cb0090cd5c14e1294244397141ac3d9@git.apache.org> References: <1cb0090cd5c14e1294244397141ac3d9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/7] git commit: CAMEL-7899 merged the patch to camel-netty4-http 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 Authored: Thu Oct 9 15:38:00 2014 +0800 Committer: Willem Jiang 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));