CAMEL-8218: Fix the issue that REST DSL with RestletComponent doesn't support servelet container
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2aea6e1b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2aea6e1b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2aea6e1b Branch: refs/heads/master Commit: 2aea6e1b10d33681c8df9b962544e4b9d837eb17 Parents: 6670a91 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Thu Jan 8 14:42:48 2015 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Thu Jan 8 14:47:08 2015 +0800 ---------------------------------------------------------------------- .../camel/component/restlet/RestletComponent.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2aea6e1b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java index 44fb434..350d9a1 100644 --- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java +++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java @@ -608,7 +608,8 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R String scheme = "http"; String host = ""; - int port = 0; + // use the component's port as the default value + int port = this.getPort(); // if no explicit port/host configured, then use port from rest configuration RestConfiguration config = getCamelContext().getRestConfiguration(); @@ -645,15 +646,22 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R String query = URISupport.createQueryString(map); - String url = "restlet:%s://%s:%s/%s?restletMethod=%s"; + String url; // must use upper case for restrict String restrict = verb.toUpperCase(Locale.US); - // get the endpoint - url = String.format(url, scheme, host, port, path, restrict); + + if (port > 0) { + url = "restlet:%s://%s:%s/%s?restletMethod=%s"; + url = String.format(url, scheme, host, port, path, restrict); + } else { + // It could use the restlet servlet transport + url = "restlet:/%s?restletMethod=%s"; + url = String.format(url, path, restrict); + } if (!query.isEmpty()) { url = url + "&" + query; } - + // get the endpoint RestletEndpoint endpoint = camelContext.getEndpoint(url, RestletEndpoint.class); setProperties(endpoint, parameters);