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 2015/09/24 11:05:14 UTC
[2/4] camel git commit: CAMEL-9156: Add JMX api for the swagger api
CAMEL-9156: Add JMX api for the swagger api
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cac4ae2d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cac4ae2d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cac4ae2d
Branch: refs/heads/master
Commit: cac4ae2d086e2994015a0a0eae4e2ab1712061d2
Parents: 35b59f1
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Sep 24 10:24:15 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Sep 24 10:24:15 2015 +0200
----------------------------------------------------------------------
.../camel/component/rest/RestApiEndpoint.java | 18 ++++++++----
.../management/mbean/ManagedRestRegistry.java | 31 ++++++++++++++++----
2 files changed, 38 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/cac4ae2d/camel-core/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
index 2ce98f7..7829a7c 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
@@ -21,10 +21,12 @@ import java.util.Set;
import org.apache.camel.Component;
import org.apache.camel.Consumer;
+import org.apache.camel.NoFactoryAvailableException;
import org.apache.camel.NoSuchBeanException;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.FactoryFinder;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.RestApiConsumerFactory;
import org.apache.camel.spi.RestApiProcessorFactory;
@@ -41,7 +43,8 @@ public class RestApiEndpoint extends DefaultEndpoint {
public static final String DEFAULT_API_COMPONENT_NAME = "swagger";
public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/rest/";
- @UriPath @Metadata(required = "true")
+ @UriPath
+ @Metadata(required = "true")
private String path;
@UriPath
private String contextIdPattern;
@@ -137,9 +140,14 @@ public class RestApiEndpoint extends DefaultEndpoint {
if (name == null) {
name = DEFAULT_API_COMPONENT_NAME;
}
- Object instance = getCamelContext().getFactoryFinder(RESOURCE_PATH).newInstance(name);
- if (instance instanceof RestApiProcessorFactory) {
- factory = (RestApiProcessorFactory) instance;
+ try {
+ FactoryFinder finder = getCamelContext().getFactoryFinder(RESOURCE_PATH);
+ Object instance = finder.newInstance(name);
+ if (instance instanceof RestApiProcessorFactory) {
+ factory = (RestApiProcessorFactory) instance;
+ }
+ } catch (NoFactoryAvailableException e) {
+ // ignore
}
}
@@ -183,7 +191,7 @@ public class RestApiEndpoint extends DefaultEndpoint {
Processor processor = factory.createApiProcessor(getCamelContext(), path, getContextIdPattern(), contextIdListing, config, getParameters());
return new RestApiProducer(this, processor);
} else {
- throw new IllegalStateException("Cannot find RestApiProcessorFactory in Registry or classpath");
+ throw new IllegalStateException("Cannot find RestApiProcessorFactory in Registry or classpath (such as the camel-swagger-java component)");
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/cac4ae2d/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 e9e5f7c..eca3508 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
@@ -31,6 +31,9 @@ import org.apache.camel.Producer;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.api.management.mbean.CamelOpenMBeanTypes;
import org.apache.camel.api.management.mbean.ManagedRestRegistryMBean;
+import org.apache.camel.component.rest.RestApiEndpoint;
+import org.apache.camel.component.rest.RestEndpoint;
+import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RestRegistry;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ServiceHelper;
@@ -91,22 +94,38 @@ public class ManagedRestRegistry extends ManagedService implements ManagedRestRe
@Override
public String apiDocAsJson() {
// see if there is a rest-api endpoint which would be the case if rest api-doc has been explicit enabled
- Endpoint found = null;
+ Endpoint restApiEndpoint = null;
+ Endpoint restEndpoint = null;
for (Map.Entry<String, Endpoint> entry : getContext().getEndpointMap().entrySet()) {
String uri = entry.getKey();
- if (uri.startsWith("rest-api")) {
- found = entry.getValue();
+ if (uri.startsWith("rest-api:")) {
+ restApiEndpoint = entry.getValue();
break;
+ } else if (restEndpoint == null && uri.startsWith("rest:")) {
+ restEndpoint = entry.getValue();
+ }
+ }
+
+ if (restApiEndpoint == null && restEndpoint != null) {
+ // no rest-api has been explicit enabled, then we need to create it first
+ RestEndpoint rest = (RestEndpoint) restEndpoint;
+ String componentName = rest.getComponentName();
+
+ if (componentName != null) {
+ RestConfiguration config = getContext().getRestConfiguration(componentName, true);
+ String apiComponent = config.getApiComponent() != null ? config.getApiComponent() : RestApiEndpoint.DEFAULT_API_COMPONENT_NAME;
+ String path = config.getApiContextPath() != null ? config.getApiContextPath() : "api-doc";
+ restApiEndpoint = getContext().getEndpoint(String.format("rest-api:%s/%s?componentName=%s&apiComponentName=%s&contextIdPattern=#name#", path, getCamelId(), componentName, apiComponent));
}
}
try {
- if (found != null) {
- Producer producer = found.createProducer();
+ if (restApiEndpoint != null) {
+ Producer producer = restApiEndpoint.createProducer();
ServiceHelper.startService(producer);
try {
- Exchange dummy = found.createExchange();
+ Exchange dummy = restApiEndpoint.createExchange();
producer.process(dummy);
String json = dummy.hasOut() ? dummy.getOut().getBody(String.class) : dummy.getIn().getBody(String.class);