Repository: camel Updated Branches: refs/heads/master 965d2377a -> 14cd8d6b3
Rest DSL. camel-swagger work in progress. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/14cd8d6b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/14cd8d6b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/14cd8d6b Branch: refs/heads/master Commit: 14cd8d6b32d8f6b3eb4fe2fe62947c11c3a5c935 Parents: 965d237 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Aug 10 16:55:10 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Aug 10 16:55:10 2014 +0200 ---------------------------------------------------------------------- .../camel/component/netty/http/ContextPathMatcher.java | 5 +++-- .../netty/http/DefaultContextPathMatcher.java | 8 ++++---- .../component/netty/http/RestContextPathMatcher.java | 6 +++--- .../netty/http/handlers/HttpServerChannelHandler.java | 2 -- .../handlers/HttpServerMultiplexChannelHandler.java | 6 +++++- .../camel/component/swagger/RestSwaggerReader.scala | 5 +---- .../src/main/webapp/WEB-INF/web.xml | 13 ++++++++----- 7 files changed, 24 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/14cd8d6b/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 030fb9f..a3c02d8 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 @@ -29,8 +29,9 @@ public interface ContextPathMatcher { /** * Whether the target context-path matches. * - * @param target the context-path from the incoming HTTP request + * @param method the HTTP method such as GET, POST + * @param path the context-path from the incoming HTTP request * @return <tt>true</tt> to match, <tt>false</tt> if not. */ - boolean matches(String target); + boolean matches(String method, String path); } http://git-wip-us.apache.org/repos/asf/camel/blob/14cd8d6b/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 2efc357..e1a4d52 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,14 +31,14 @@ public class DefaultContextPathMatcher implements ContextPathMatcher { this.matchOnUriPrefix = matchOnUriPrefix; } - public boolean matches(String target) { - target = target.toLowerCase(Locale.US); + public boolean matches(String method, String path) { + path = path.toLowerCase(Locale.US); if (!matchOnUriPrefix) { // exact match - return target.equals(path); + return path.equals(this.path); } else { // match on prefix, then we just need to match the start of the context-path - return target.startsWith(path); + return path.startsWith(this.path); } } http://git-wip-us.apache.org/repos/asf/camel/blob/14cd8d6b/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 f7e73db..f0838e3 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 @@ -31,11 +31,11 @@ public class RestContextPathMatcher extends DefaultContextPathMatcher { } @Override - public boolean matches(String target) { + public boolean matches(String method, String path) { if (useRestMatching(rawPath)) { - return matchRestPath(target, rawPath); + return matchRestPath(path, rawPath); } else { - return super.matches(target); + return super.matches(method, path); } } http://git-wip-us.apache.org/repos/asf/camel/blob/14cd8d6b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java index 3bf21ba..0e20a4d 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java @@ -110,8 +110,6 @@ public class HttpServerChannelHandler extends ServerChannelHandler { messageEvent.getChannel().write(response); return; } - - if (consumer.getEndpoint().getHttpMethodRestrict() != null && !consumer.getEndpoint().getHttpMethodRestrict().contains(request.getMethod().getName())) { HttpResponse response = new DefaultHttpResponse(HTTP_1_1, METHOD_NOT_ALLOWED); http://git-wip-us.apache.org/repos/asf/camel/blob/14cd8d6b/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 aedd1e1..7fccde5 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 @@ -136,6 +136,8 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand private HttpServerChannelHandler getHandler(HttpRequest request) { // need to strip out host and port etc, as we only need the context-path for matching + String method = request.getMethod().getName(); + String path = request.getUri(); int idx = path.indexOf(token); if (idx > -1) { @@ -145,9 +147,11 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand // use the path as key to find the consumer handler to use path = pathAsKey(path); + // TODO: improve matching like we have done in camel-servlet, eg using candidates + // find the one that matches for (Map.Entry<ContextPathMatcher, HttpServerChannelHandler> entry : consumers.entrySet()) { - if (entry.getKey().matches(path)) { + if (entry.getKey().matches(method, path)) { return entry.getValue(); } } http://git-wip-us.apache.org/repos/asf/camel/blob/14cd8d6b/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala ---------------------------------------------------------------------- diff --git a/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala b/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala index aa48d61..ccd846e 100644 --- a/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala +++ b/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala @@ -40,10 +40,7 @@ import scala.collection.JavaConverters._ class RestSwaggerReader { private val LOG = LoggerFactory.getLogger(classOf[RestSwaggerReader]) - - // TODO: add parameters to operations - // - {id} is a path type, and required - // - type/outType is body type and required + // TODO: add logging def read(rest: RestDefinition, config: SwaggerConfig): Option[ApiListing] = { http://git-wip-us.apache.org/repos/asf/camel/blob/14cd8d6b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml index ee0c9f1..cd3e527 100755 --- a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml +++ b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml @@ -16,9 +16,9 @@ limitations under the License. --> -<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" +<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>My Camel Rest Application</display-name> @@ -41,8 +41,8 @@ <!-- to setup Camel Servlet --> <servlet> - <servlet-name>CamelServlet</servlet-name> <display-name>Camel Http Transport Servlet</display-name> + <servlet-name>CamelServlet</servlet-name> <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> @@ -52,7 +52,6 @@ <servlet> <servlet-name>ApiDeclarationServlet</servlet-name> <servlet-class>org.apache.camel.component.swagger.RestSwaggerApiDeclarationServlet</servlet-class> - <load-on-startup>2</load-on-startup> <init-param> <param-name>base.path</param-name> <param-value>http://localhost:8080/rest</param-value> @@ -73,6 +72,7 @@ <param-name>api.description</param-name> <param-value>Camel Rest Example with Swagger that provides an User REST service</param-value> </init-param> + <load-on-startup>2</load-on-startup> </servlet> <!-- swagger api declaration --> @@ -88,6 +88,7 @@ <url-pattern>/rest/*</url-pattern> </servlet-mapping> + <!-- START SNIPPET: e2 --> <!-- enable CORS filter so people can use swagger ui to browse and test the apis --> <filter> <filter-name>RestSwaggerCorsFilter</filter-name> @@ -96,7 +97,9 @@ <filter-mapping> <filter-name>RestSwaggerCorsFilter</filter-name> - <url-pattern>/*</url-pattern> + <url-pattern>/api-docs/*</url-pattern> + <url-pattern>/rest/*</url-pattern> </filter-mapping> + <!-- END SNIPPET: e2 --> </web-app> \ No newline at end of file