Repository: camel Updated Branches: refs/heads/camel-2.14.x 994483a75 -> a0100ba07 refs/heads/master b7338568c -> 8cfabc840
CAMEL-8313: rest-dsl include optional description in the rest service jmx api. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e6e96163 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e6e96163 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e6e96163 Branch: refs/heads/master Commit: e6e961639107fc0f6df886719bc2ccd6c711020f Parents: b733856 Author: Claus Ibsen <[email protected]> Authored: Mon Dec 8 15:17:32 2014 +0100 Committer: Claus Ibsen <[email protected]> Committed: Mon Dec 8 15:19:33 2014 +0100 ---------------------------------------------------------------------- .../api/management/mbean/CamelOpenMBeanTypes.java | 8 +++++--- .../org/apache/camel/component/rest/RestEndpoint.java | 6 +++++- .../org/apache/camel/impl/DefaultRestRegistry.java | 14 ++++++++++---- .../camel/management/mbean/ManagedRestRegistry.java | 5 +++-- .../org/apache/camel/model/rest/RestDefinition.java | 13 +++++++++++++ .../main/java/org/apache/camel/spi/RestRegistry.java | 8 +++++++- .../camel/management/ManagedRestRegistryTest.java | 8 ++++---- 7 files changed, 47 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/e6e96163/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 9b08930..c2dfa59 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,12 @@ public final class CamelOpenMBeanTypes { } public static CompositeType listRestServicesCompositeType() throws OpenDataException { - return new CompositeType("rests", "Rest Services", new String[]{"url", "baseUrl", "basePath", "uriTemplate", "method", "consumes", "produces", "inType", "outType", "state", "routeId"}, - new String[]{"Url", "Base Url", "Base Path", "Uri Template", "Method", "Consumes", "Produces", "Input Type", "Output Type", "State", "Route Id"}, + return new CompositeType("rests", "Rest Services", new String[]{"url", "baseUrl", "basePath", "uriTemplate", "method", "consumes", + "produces", "inType", "outType", "state", "routeId", "description"}, + new String[]{"Url", "Base Url", "Base Path", "Uri Template", "Method", "Consumes", + "Produces", "Input Type", "Output Type", "State", "Route Id", "Description"}, new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, - SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING}); + SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING}); } public static TabularType listEndpointsTabularType() throws OpenDataException { http://git-wip-us.apache.org/repos/asf/camel/blob/e6e96163/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 f5a49cb..8966dea 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 @@ -232,10 +232,14 @@ public class RestEndpoint extends DefaultEndpoint { // the route id when using rest-dsl String routeId = (String) getParameters().get("routeId"); + // optional description + String description = (String) getParameters().get("description"); + // 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, baseUrl, getPath(), getUriTemplate(), getMethod(), getConsumes(), getProduces(), inType, outType, routeId); + getCamelContext().getRestRegistry().addRestService(consumer, url, baseUrl, getPath(), getUriTemplate(), getMethod(), + getConsumes(), getProduces(), inType, outType, routeId, description); return consumer; } else { throw new IllegalStateException("Cannot find RestConsumerFactory in Registry or as a Component to use"); http://git-wip-us.apache.org/repos/asf/camel/blob/e6e96163/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 4da2987..f36d505 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 @@ -40,8 +40,8 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService private final Map<Consumer, RestService> registry = new LinkedHashMap<Consumer, RestService>(); public void addRestService(Consumer consumer, String url, String baseUrl, String basePath, String uriTemplate, String method, - String consumes, String produces, String inType, String outType, String routeId) { - RestServiceEntry entry = new RestServiceEntry(consumer, url, baseUrl, basePath, uriTemplate, method, consumes, produces, inType, outType, routeId); + String consumes, String produces, String inType, String outType, String routeId, String description) { + RestServiceEntry entry = new RestServiceEntry(consumer, url, baseUrl, basePath, uriTemplate, method, consumes, produces, inType, outType, routeId, description); registry.put(consumer, entry); } @@ -95,9 +95,10 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService private final String inType; private final String outType; private final String routeId; + private final String description; - private RestServiceEntry(Consumer consumer, String url, String baseUrl, String basePath, String uriTemplate, - String method, String consumes, String produces, String inType, String outType, String routeId) { + private RestServiceEntry(Consumer consumer, String url, String baseUrl, String basePath, String uriTemplate, String method, + String consumes, String produces, String inType, String outType, String routeId, String description) { this.consumer = consumer; this.url = url; this.baseUrl = baseUrl; @@ -109,6 +110,7 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService this.inType = inType; this.outType = outType; this.routeId = routeId; + this.description = description; } public Consumer getConsumer() { @@ -167,6 +169,10 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService public String getRouteId() { return routeId; } + + public String getDescription() { + return description; + } } /** http://git-wip-us.apache.org/repos/asf/camel/blob/e6e96163/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 97af622..244182e 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 @@ -70,10 +70,11 @@ public class ManagedRestRegistry extends ManagedService implements ManagedRestRe String inType = entry.getInType(); String outType = entry.getOutType(); String routeId = entry.getRouteId(); + String description = entry.getDescription(); CompositeData data = new CompositeDataSupport(ct, new String[] - {"url", "baseUrl", "basePath", "uriTemplate", "method", "consumes", "produces", "inType", "outType", "state", "routeId"}, - new Object[]{url, baseUrl, basePath, uriTemplate, method, consumes, produces, inType, outType, state, routeId}); + {"url", "baseUrl", "basePath", "uriTemplate", "method", "consumes", "produces", "inType", "outType", "state", "routeId", "description"}, + new Object[]{url, baseUrl, basePath, uriTemplate, method, consumes, produces, inType, outType, state, routeId, description}); answer.put(data); } return answer; http://git-wip-us.apache.org/repos/asf/camel/blob/e6e96163/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 42a3bf4..479f830 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 @@ -437,6 +437,19 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> String routeId = route.idOrCreate(camelContext.getNodeIdFactory()); options.put("routeId", routeId); + // include optional description, which we favor from 1) to/route description 2) verb description 3) rest description + // this allows end users to define general descriptions and override then per to/route or verb + String description = verb.getTo() != null ? verb.getTo().getDescriptionText() : route.getDescriptionText(); + if (description == null) { + description = verb.getDescriptionText(); + } + if (description == null) { + description = getDescriptionText(); + } + if (description != null) { + options.put("description", description); + } + if (!options.isEmpty()) { String query; try { http://git-wip-us.apache.org/repos/asf/camel/blob/e6e96163/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 62c8542..c307383 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 @@ -96,6 +96,11 @@ public interface RestRegistry extends Service { */ String getRouteId(); + /** + * Optional description about this rest service. + */ + String getDescription(); + } /** @@ -112,9 +117,10 @@ public interface RestRegistry extends Service { * @param inType optional detail input binding to a FQN class name * @param outType optional detail output binding to a FQN class name * @param routeId the id of the route this rest service will be using + * @param description optional description about the the service */ void addRestService(Consumer consumer, String url, String baseUrl, String basePath, String uriTemplate, String method, String consumes, String produces, - String inType, String outType, String routeId); + String inType, String outType, String routeId, String description); /** * Removes the REST service from the registry http://git-wip-us.apache.org/repos/asf/camel/blob/e6e96163/camel-core/src/test/java/org/apache/camel/management/ManagedRestRegistryTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRestRegistryTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRestRegistryTest.java index b023a92..e0a6d90 100644 --- a/camel-core/src/test/java/org/apache/camel/management/ManagedRestRegistryTest.java +++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRestRegistryTest.java @@ -81,15 +81,15 @@ public class ManagedRestRegistryTest extends ManagementTestSupport { @Override public void configure() throws Exception { rest("/say/hello/{name}") - .get().to("direct:hello"); + .get().to("direct:hello").description("Calling direct route"); - rest("/say/bye") - .get().consumes("application/json") + rest("/say/bye").description("the bye rest service") + .get().consumes("application/json").description("I am saying bye world") .route().routeId("myRestRoute").transform().constant("Bye World").endRest() .post() .to("mock:update"); - from("direct:hello") + from("direct:hello").description("The hello route") .transform().simple("Hello ${header.name}"); } };
