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 14:51:22 UTC
[4/4] camel git commit: CAMEL-8313: rest-dsl include route id in the
rest service jmx api.
CAMEL-8313: rest-dsl include route id 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/994483a7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/994483a7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/994483a7
Branch: refs/heads/camel-2.14.x
Commit: 994483a754aa15395d6162c152262794650b0545
Parents: 92135be
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Dec 8 14:50:33 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Dec 8 14:51:08 2014 +0100
----------------------------------------------------------------------
.../camel/api/management/mbean/CamelOpenMBeanTypes.java | 6 +++---
.../org/apache/camel/component/rest/RestEndpoint.java | 6 ++++--
.../java/org/apache/camel/impl/DefaultRestRegistry.java | 12 +++++++++---
.../camel/management/mbean/ManagedRestRegistry.java | 5 +++--
.../org/apache/camel/model/rest/RestDefinition.java | 4 ++++
.../main/java/org/apache/camel/spi/RestRegistry.java | 8 +++++++-
.../camel/management/ManagedRestRegistryTest.java | 9 ++++-----
7 files changed, 34 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/994483a7/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 3102713..45b3745 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,9 +47,9 @@ 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"},
- new String[]{"Url", "Base Url", "Base Path", "Uri Template", "Method", "Consumes", "Produces", "Input Type", "Output Type", "State"},
- new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING,
+ 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"},
+ new OpenType[]{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/994483a7/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 1e2aac8..0ea94ac 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
@@ -228,11 +228,13 @@ public class RestEndpoint extends DefaultEndpoint {
String inType = (String) getParameters().get("inType");
String outType = (String) getParameters().get("outType");
+ // the route id when using rest-dsl
+ String routeId = (String) getParameters().get("routeId");
+
// 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);
-
+ getCamelContext().getRestRegistry().addRestService(consumer, url, baseUrl, getPath(), getUriTemplate(), getMethod(), getConsumes(), getProduces(), inType, outType, routeId);
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/994483a7/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 f32c5c5..4da2987 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) {
- RestServiceEntry entry = new RestServiceEntry(consumer, url, baseUrl, basePath, uriTemplate, method, consumes, produces, inType, outType);
+ 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);
registry.put(consumer, entry);
}
@@ -94,9 +94,10 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService
private final String produces;
private final String inType;
private final String outType;
+ private final 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 method, String consumes, String produces, String inType, String outType, String routeId) {
this.consumer = consumer;
this.url = url;
this.baseUrl = baseUrl;
@@ -107,6 +108,7 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService
this.produces = produces;
this.inType = inType;
this.outType = outType;
+ this.routeId = routeId;
}
public Consumer getConsumer() {
@@ -161,6 +163,10 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService
}
return status.name();
}
+
+ public String getRouteId() {
+ return routeId;
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/994483a7/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 b2264d2..97af622 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
@@ -69,10 +69,11 @@ public class ManagedRestRegistry extends ManagedService implements ManagedRestRe
String state = entry.getState();
String inType = entry.getInType();
String outType = entry.getOutType();
+ String routeId = entry.getRouteId();
CompositeData data = new CompositeDataSupport(ct, new String[]
- {"url", "baseUrl", "basePath", "uriTemplate", "method", "consumes", "produces", "inType", "outType", "state"},
- new Object[]{url, baseUrl, basePath, uriTemplate, method, consumes, produces, inType, outType, state});
+ {"url", "baseUrl", "basePath", "uriTemplate", "method", "consumes", "produces", "inType", "outType", "state", "routeId"},
+ new Object[]{url, baseUrl, basePath, uriTemplate, method, consumes, produces, inType, outType, state, routeId});
answer.put(data);
}
return answer;
http://git-wip-us.apache.org/repos/asf/camel/blob/994483a7/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 2ddbcca..42a3bf4 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
@@ -433,6 +433,10 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
if (outType != null) {
options.put("outType", outType);
}
+ // include route id
+ String routeId = route.idOrCreate(camelContext.getNodeIdFactory());
+ options.put("routeId", routeId);
+
if (!options.isEmpty()) {
String query;
try {
http://git-wip-us.apache.org/repos/asf/camel/blob/994483a7/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 92ac05d..62c8542 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
@@ -91,6 +91,11 @@ public interface RestRegistry extends Service {
*/
String getOutType();
+ /**
+ * Gets the id of the route this rest service will be using.
+ */
+ String getRouteId();
+
}
/**
@@ -106,9 +111,10 @@ public interface RestRegistry extends Service {
* @param produces optional details about what media-types the REST service returns
* @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
*/
void addRestService(Consumer consumer, String url, String baseUrl, String basePath, String uriTemplate, String method, String consumes, String produces,
- String inType, String outType);
+ String inType, String outType, String routeId);
/**
* Removes the REST service from the registry
http://git-wip-us.apache.org/repos/asf/camel/blob/994483a7/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 be78174..b023a92 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
@@ -84,14 +84,13 @@ public class ManagedRestRegistryTest extends ManagementTestSupport {
.get().to("direct:hello");
rest("/say/bye")
- .get().consumes("application/json").to("direct:bye")
- .post().to("mock:update");
+ .get().consumes("application/json")
+ .route().routeId("myRestRoute").transform().constant("Bye World").endRest()
+ .post()
+ .to("mock:update");
from("direct:hello")
.transform().simple("Hello ${header.name}");
-
- from("direct:bye")
- .transform().constant("Bye World");
}
};
}