git commit: CAMEL-7354: Rest DSL. Integrate with camel-netty-http.
Repository: camel Updated Branches: refs/heads/master 6dc9d8a48 -> 6fae19134 CAMEL-7354: Rest DSL. Integrate with 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/6fae1913 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6fae1913 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6fae1913 Branch: refs/heads/master Commit: 6fae1913455279019c2dbcdc1199ab8685feaeba Parents: 6dc9d8a Author: Claus Ibsen Authored: Wed Aug 13 13:53:33 2014 +0200 Committer: Claus Ibsen Committed: Wed Aug 13 13:53:33 2014 +0200 -- .../netty/http/ContextPathMatcher.java | 26 +- .../netty/http/DefaultContextPathMatcher.java | 14 +++- .../netty/http/RestContextPathMatcher.java | 31 --- .../http/handlers/HttpServerChannelHandler.java | 4 + .../HttpServerMultiplexChannelHandler.java | 60 -- .../RestNettyHttpContextPathMatchGetTest.java | 68 .../netty/http/rest/RestPathMatchingTest.java | 86 7 files changed, 265 insertions(+), 24 deletions(-) -- http://git-wip-us.apache.org/repos/asf/camel/blob/6fae1913/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/ContextPathMatcher.java -- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/ContextPathMatcher.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/ContextPathMatcher.java index a3c02d8..df8498a 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/ContextPathMatcher.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/ContextPathMatcher.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.netty.http; +import java.util.Locale; + /** * A matcher used for selecting the correct {@link org.apache.camel.component.netty.http.handlers.HttpServerChannelHandler} * to handle an incoming {@link org.jboss.netty.handler.codec.http.HttpRequest} when you use multiple routes on the same @@ -27,11 +29,29 @@ package org.apache.camel.component.netty.http; public interface ContextPathMatcher { /** - * Whether the target context-path matches. + * Whether the target context-path matches a regular url. + * + * @param path the context-path from the incoming HTTP request + * @return true to match, false if not. + */ +boolean matches(String path); + +/** + * Whether the target context-path matches a REST url. * - * @param method the HTTP method such as GET, POST * @param path the context-path from the incoming HTTP request + * @param wildcard whether to match strict or by wildcards * @return true to match, false if not. */ -boolean matches(String method, String path); +boolean matchesRest(String path, boolean wildcard); + +/** + * Matches the given request HTTP method with the configured HTTP method of the consumer + * + * @param methodthe request HTTP method + * @param restrict the consumer configured HTTP restrict method + * @return true if matched, false otherwise + */ +boolean matchMethod(String method, String restrict); + } http://git-wip-us.apache.org/repos/asf/camel/blob/6fae1913/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 e1a4d52..9f7d98f 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 @@ -31,7 +31,8 @@ public class DefaultContextPathMatcher implements ContextPathMatcher { this.matchOnUriPrefix = matchOnUriPrefix; } -public boolean matches(String method, String path) { +@Override +public boolean matches(String path) { path = path.toLowerCase(Locale.US); if (!matchOnUriPrefix) { // exact match @@ -42,6 +43,17 @@ public class DefaultContextPathMatcher implements ContextPathMatcher { } } +@Override +public boolean matchesRest(String path, boolean wildcard) { +return false; +} + +@Override +public boolean matchMethod(String method, String restrict) { +// always match as HttpServerChannelHandler will de
[1/2] git commit: CAMEL-7354: Rest DSL. Integrate with camel-netty-http.
Repository: camel Updated Branches: refs/heads/master d58fd1107 -> 09bd4db06 CAMEL-7354: Rest DSL. Integrate with 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/09bd4db0 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/09bd4db0 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/09bd4db0 Branch: refs/heads/master Commit: 09bd4db06266265f5a9bd8834a3219fe48338514 Parents: 248f8cd Author: Claus Ibsen Authored: Tue Jul 29 10:09:19 2014 +0200 Committer: Claus Ibsen Committed: Tue Jul 29 10:12:10 2014 +0200 -- .../RestJettyBindingModeAutoWithJsonTest.java | 2 +- components/camel-netty-http/pom.xml | 11 +++ .../component/netty/http/rest/CountryPojo.java | 40 ++ ...estNettyHttpBindingModeAutoWithJsonTest.java | 59 +++ ...RestNettyHttpBindingModeAutoWithXmlTest.java | 59 +++ .../rest/RestNettyHttpBindingModeJsonTest.java | 76 +++ .../rest/RestNettyHttpBindingModeXmlTest.java | 77 +++ .../http/rest/RestNettyHttpPojoInOutTest.java | 55 ++ .../rest/RestNettyHttpPostJsonJaxbPojoTest.java | 63 .../rest/RestNettyHttpPostJsonPojoListTest.java | 68 + .../rest/RestNettyHttpPostJsonPojoTest.java | 63 .../rest/RestNettyHttpPostXmlJaxbPojoTest.java | 79 .../component/netty/http/rest/UserJaxbPojo.java | 48 .../component/netty/http/rest/UserPojo.java | 40 ++ .../component/netty/http/rest/UserService.java | 33 15 files changed, 772 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java -- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java index c4fb469..43ec8f3 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java @@ -50,7 +50,7 @@ public class RestJettyBindingModeAutoWithJsonTest extends BaseJettyTest { // use the rest DSL to define the rest services rest("/users/") - .post("new").consumes("application/json").type(UserPojo.class) + .post("new").consumes("application/json").type(UserPojo.class) .to("mock:input"); } }; http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/pom.xml -- diff --git a/components/camel-netty-http/pom.xml b/components/camel-netty-http/pom.xml index 8eb6962..6e56b2d 100644 --- a/components/camel-netty-http/pom.xml +++ b/components/camel-netty-http/pom.xml @@ -57,6 +57,17 @@ junit test + + + org.apache.camel + camel-jackson + test + + + org.apache.camel + camel-jaxb + test + http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/CountryPojo.java -- diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/CountryPojo.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/CountryPojo.java new file mode 100644 index 000..99d41fe --- /dev/null +++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/CountryPojo.java @@ -0,0 +1,40 @@ +/** + * 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 O
[2/2] git commit: CAMEL-7354: Rest DSL. Integrate with camel-netty-http.
CAMEL-7354: Rest DSL. Integrate with 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/248f8cd7 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/248f8cd7 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/248f8cd7 Branch: refs/heads/master Commit: 248f8cd74885521abe8e8f0456a4323d2733a79b Parents: d58fd11 Author: Claus Ibsen Authored: Tue Jul 29 09:08:24 2014 +0200 Committer: Claus Ibsen Committed: Tue Jul 29 10:12:10 2014 +0200 -- .../netty/http/DefaultContextPathMatcher.java | 4 + .../netty/http/NettyHttpComponent.java | 86 -- .../netty/http/RestContextPathMatcher.java | 95 .../netty/http/RestNettyHttpBinding.java| 91 +++ .../HttpServerMultiplexChannelHandler.java | 9 +- .../netty/http/rest/RestNettyHttpGetTest.java | 56 6 files changed, 331 insertions(+), 10 deletions(-) -- http://git-wip-us.apache.org/repos/asf/camel/blob/248f8cd7/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 55bfb58..2efc357 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 @@ -42,6 +42,10 @@ public class DefaultContextPathMatcher implements ContextPathMatcher { } } +public String getPath() { +return path; +} + @Override public boolean equals(Object o) { if (this == o) { http://git-wip-us.apache.org/repos/asf/camel/blob/248f8cd7/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java -- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java index 3732454..90f09f1 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java @@ -18,15 +18,22 @@ package org.apache.camel.component.netty.http; import java.net.URI; import java.util.HashMap; +import java.util.Locale; import java.util.Map; +import org.apache.camel.CamelContext; +import org.apache.camel.Consumer; import org.apache.camel.Endpoint; +import org.apache.camel.Processor; import org.apache.camel.component.netty.NettyComponent; import org.apache.camel.component.netty.NettyConfiguration; import org.apache.camel.component.netty.NettyServerBootstrapConfiguration; import org.apache.camel.component.netty.http.handlers.HttpServerMultiplexChannelHandler; import org.apache.camel.spi.HeaderFilterStrategy; import org.apache.camel.spi.HeaderFilterStrategyAware; +import org.apache.camel.spi.RestConfiguration; +import org.apache.camel.spi.RestConsumerFactory; +import org.apache.camel.util.FileUtil; import org.apache.camel.util.IntrospectionSupport; import org.apache.camel.util.ServiceHelper; import org.apache.camel.util.URISupport; @@ -37,7 +44,7 @@ import org.slf4j.LoggerFactory; /** * Netty HTTP based component. */ -public class NettyHttpComponent extends NettyComponent implements HeaderFilterStrategyAware { +public class NettyHttpComponent extends NettyComponent implements HeaderFilterStrategyAware, RestConsumerFactory { private static final Logger LOG = LoggerFactory.getLogger(NettyHttpComponent.class); @@ -53,7 +60,8 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt super(NettyHttpEndpoint.class); setConfiguration(new NettyHttpConfiguration()); setHeaderFilterStrategy(new NettyHttpHeaderFilterStrategy()); -setNettyHttpBinding(new DefaultNettyHttpBinding(getHeaderFilterStrategy())); +// use the binding that supports Rest DSL +setNettyHttpBinding(new RestNettyHttpBinding(getHeaderFilterStrategy())); } @Override @@ -102,12 +110,16 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt NettyHttpEndpoint answer = new NettyHttpEndpoint(addressUri, this, config); answer.setTimer(getTimer()); -// set compon