You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/12/08 15:50:23 UTC
[3/4] camel git commit: CAMEL-8313: rest-dsl include optional
description in the rest service jmx api.
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/b259d4bf
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b259d4bf
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b259d4bf
Branch: refs/heads/camel-2.14.x
Commit: b259d4bfd03f6be2144e6b6600c7ec53dae622b6
Parents: 994483a
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Dec 8 15:17:32 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Dec 8 15:50:05 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/b259d4bf/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 45b3745..353fb0d 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});
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/b259d4bf/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 0ea94ac..659971e 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
@@ -231,10 +231,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/b259d4bf/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/b259d4bf/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/b259d4bf/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/b259d4bf/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/b259d4bf/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}");
}
};