Repository: camel Updated Branches: refs/heads/master d4a164bc1 -> 1c64ca33c
CAMEL-7620: Rest DSL. Enlist rest services in RestRegistry and JMX. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1c64ca33 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1c64ca33 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1c64ca33 Branch: refs/heads/master Commit: 1c64ca33cc08fd60336af1a4e8ac68f462aa73c7 Parents: d4a164b Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Aug 6 11:26:45 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Aug 6 11:26:45 2014 +0200 ---------------------------------------------------------------------- .../management/mbean/CamelOpenMBeanTypes.java | 7 ++- .../camel/component/rest/RestEndpoint.java | 10 +++- .../apache/camel/impl/DefaultRestRegistry.java | 26 ++++++--- .../management/mbean/ManagedRestRegistry.java | 8 +-- .../apache/camel/model/rest/RestDefinition.java | 56 +++++++++++++------- .../java/org/apache/camel/spi/RestRegistry.java | 17 +++++- 6 files changed, 89 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/1c64ca33/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java index d9ae462..ec56266 100644 --- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java +++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java @@ -47,10 +47,9 @@ public final class CamelOpenMBeanTypes { } public static CompositeType listRestServicesCompositeType() throws OpenDataException { - return new CompositeType("rests", "Rest Services", new String[]{"url", "method", "uriTemplate", "consumes", "produces", "state"}, - new String[]{"Url", "Method", "Uri Template", "Consumes", "Produces", "State"}, - new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING}); + return new CompositeType("rests", "Rest Services", new String[]{"url", "method", "uriTemplate", "consumes", "produces", "inType", "outType", "state"}, + new String[]{"Url", "Method", "Uri Template", "Consumes", "Produces", "Input Type", "Output Type", "State"}, + new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING}); } - } http://git-wip-us.apache.org/repos/asf/camel/blob/1c64ca33/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java index a1e6cdf..12bf7b7 100644 --- a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java +++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java @@ -190,10 +190,14 @@ public class RestEndpoint extends DefaultEndpoint { } String url = scheme + "://" + host + (port != 80 ? ":" + port : "") + path; + // optional binding type information + String inType = (String) getParameters().get("inType"); + String outType = (String) getParameters().get("outType"); + // add to rest registry so we can keep track of them, we will remove from the registry when the consumer is removed // the rest registry will automatic keep track when the consumer is removed, // and un-register the REST service from the registry - getCamelContext().getRestRegistry().addRestService(consumer, url, getVerb(), getPath(), getConsumes(), getProduces()); + getCamelContext().getRestRegistry().addRestService(consumer, url, getVerb(), getPath(), getConsumes(), getProduces(), inType, outType); return consumer; } else { @@ -206,4 +210,8 @@ public class RestEndpoint extends DefaultEndpoint { return true; } + @Override + public boolean isLenientProperties() { + return true; + } } http://git-wip-us.apache.org/repos/asf/camel/blob/1c64ca33/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java index 082dc3e..1d6d8f6 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java +++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java @@ -38,8 +38,9 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService private CamelContext camelContext; private final Map<Consumer, RestService> registry = new LinkedHashMap<Consumer, RestService>(); - public void addRestService(Consumer consumer, String url, String method, String uriTemplate, String consumes, String produces) { - RestServiceEntry entry = new RestServiceEntry(consumer, url, uriTemplate, method, consumes, produces); + public void addRestService(Consumer consumer, String url, String method, String uriTemplate, String consumes, String produces, + String inType, String outType) { + RestServiceEntry entry = new RestServiceEntry(consumer, url, uriTemplate, method, consumes, produces, inType, outType); registry.put(consumer, entry); } @@ -85,17 +86,22 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService private final Consumer consumer; private final String url; private final String path; - private final String verb; + private final String method; private final String consumes; private final String produces; + private final String inType; + private final String outType; - private RestServiceEntry(Consumer consumer, String url, String path, String verb, String consumes, String produces) { + private RestServiceEntry(Consumer consumer, String url, String path, String method, String consumes, String produces, + String inType, String outType) { this.consumer = consumer; this.url = url; this.path = path; - this.verb = verb; + this.method = method; this.consumes = consumes; this.produces = produces; + this.inType = inType; + this.outType = outType; } public Consumer getConsumer() { @@ -111,7 +117,7 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService } public String getMethod() { - return verb; + return method; } public String getConsumes() { @@ -122,6 +128,14 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService return produces; } + public String getInType() { + return inType; + } + + public String getOutType() { + return outType; + } + public String getState() { // must use String type to be sure remote JMX can read the attribute without requiring Camel classes. ServiceStatus status = null; http://git-wip-us.apache.org/repos/asf/camel/blob/1c64ca33/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java index cbd1c6f..37214b0 100644 --- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java @@ -20,8 +20,6 @@ import java.util.List; import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeDataSupport; import javax.management.openmbean.CompositeType; -import javax.management.openmbean.OpenType; -import javax.management.openmbean.SimpleType; import javax.management.openmbean.TabularData; import javax.management.openmbean.TabularDataSupport; @@ -67,8 +65,10 @@ public class ManagedRestRegistry extends ManagedService implements ManagedRestRe String consumes = entry.getConsumes(); String produces = entry.getProduces(); String state = entry.getState(); - CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "method", "uriTemplate", "consumes", "produces", "state"}, - new Object[]{url, method, uriTemplate, consumes, produces, state}); + String inType = entry.getInType(); + String outType = entry.getOutType(); + CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "method", "uriTemplate", "consumes", "produces", "inType", "outType", "state"}, + new Object[]{url, method, uriTemplate, consumes, produces, inType, outType, state}); answer.put(data); } return answer; http://git-wip-us.apache.org/repos/asf/camel/blob/1c64ca33/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java index 64be3bf..a1c7bec 100644 --- a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java @@ -306,25 +306,6 @@ public class RestDefinition { List<RouteDefinition> answer = new ArrayList<RouteDefinition>(); for (VerbDefinition verb : getVerbs()) { - String from = "rest:" + verb.asVerb() + ":" + buildUri(verb); - // append options - Map<String, Object> options = new HashMap<String, Object>(); - // verb takes precedence over configuration on rest - if (verb.getConsumes() != null) { - options.put("consumes", verb.getConsumes()); - } else if (getConsumes() != null) { - options.put("consumes", getConsumes()); - } - if (verb.getProduces() != null) { - options.put("produces", verb.getProduces()); - } else if (getProduces() != null) { - options.put("produces", getProduces()); - } - if (!options.isEmpty()) { - String query = URISupport.createQueryString(options); - from = from + "?" + query; - } - // either the verb has a singular to or a embedded route RouteDefinition route = verb.getRoute(); if (route == null) { @@ -358,6 +339,43 @@ public class RestDefinition { } route.getOutputs().add(0, binding); + // create the from endpoint uri which is using the rest component + String from = "rest:" + verb.asVerb() + ":" + buildUri(verb); + + // append options + Map<String, Object> options = new HashMap<String, Object>(); + // verb takes precedence over configuration on rest + if (verb.getConsumes() != null) { + options.put("consumes", verb.getConsumes()); + } else if (getConsumes() != null) { + options.put("consumes", getConsumes()); + } + if (verb.getProduces() != null) { + options.put("produces", verb.getProduces()); + } else if (getProduces() != null) { + options.put("produces", getProduces()); + } + + // append optional type binding information + String inType = binding.getType(); + if (binding.getList() != null && binding.getList()) { + inType = "List<" + inType + ">"; + } + if (inType != null) { + options.put("inType", inType); + } + String outType = binding.getOutType(); + if (binding.getOutList() != null && binding.getOutList()) { + outType = "List<" + outType + ">"; + } + if (outType != null) { + options.put("outType", outType); + } + if (!options.isEmpty()) { + String query = URISupport.createQueryString(options); + from = from + "?" + query; + } + // the route should be from this rest endpoint route.fromRest(from); route.setRestDefinition(this); http://git-wip-us.apache.org/repos/asf/camel/blob/1c64ca33/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java b/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java index db06295..f8c894e 100644 --- a/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java +++ b/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java @@ -67,6 +67,20 @@ public interface RestRegistry extends Service { */ String getProduces(); + /** + * Optional detail about input binding to a FQN class name. + * <p/> + * If the input accepts a list, then <tt>List<class name></tt> is enclosed the name. + */ + String getInType(); + + /** + * Optional detail about output binding to a FQN class name. + * <p/> + * If the output accepts a list, then <tt>List<class name></tt> is enclosed the name. + */ + String getOutType(); + } /** @@ -79,7 +93,8 @@ public interface RestRegistry extends Service { * @param consumes optional details about what media-types the REST service accepts * @param produces optional details about what media-types the REST service returns */ - void addRestService(Consumer consumer, String url, String method, String uriTemplate, String consumes, String produces); + void addRestService(Consumer consumer, String url, String method, String uriTemplate, String consumes, String produces, + String inType, String outType); /** * Removes the REST service from the registry