camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-10865: camel catalog - Add catalog for connectors
Date Tue, 21 Feb 2017 12:22:40 GMT
Repository: camel
Updated Branches:
  refs/heads/master 615314557 -> dbeb42c42


CAMEL-10865: camel catalog - Add catalog for connectors


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/dbeb42c4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/dbeb42c4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/dbeb42c4

Branch: refs/heads/master
Commit: dbeb42c42eeea3ede0ead9dd8a05ec519a6c7ee3
Parents: 6153145
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Feb 21 13:20:53 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Feb 21 13:21:21 2017 +0100

----------------------------------------------------------------------
 platforms/catalog-rest-app/ReadMe.md            |  2 +-
 .../catalog/rest/CamelCatalogRestMain.java      | 18 +++-
 platforms/catalog-rest/pom.xml                  | 37 ++++----
 .../catalog/rest/CamelConnectorCatalogRest.java | 99 ++++++++++++++++++++
 .../catalog/rest/CamelCatalogRestTest.java      |  4 +-
 .../rest/CamelConnectorCatalogRestTest.java     | 88 +++++++++++++++++
 6 files changed, 225 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/dbeb42c4/platforms/catalog-rest-app/ReadMe.md
----------------------------------------------------------------------
diff --git a/platforms/catalog-rest-app/ReadMe.md b/platforms/catalog-rest-app/ReadMe.md
index 97ea172..8506593 100644
--- a/platforms/catalog-rest-app/ReadMe.md
+++ b/platforms/catalog-rest-app/ReadMe.md
@@ -1,7 +1,7 @@
 Camel Catalog REST Application
 ==============================
 
-This is a little standalone application which hosts the Camel Catalog REST API.
+This is a little standalone application which hosts the Camel Catalog and Connector Catalog
REST API.
 
 You can run the application using
 

http://git-wip-us.apache.org/repos/asf/camel/blob/dbeb42c4/platforms/catalog-rest-app/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRestMain.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-rest-app/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRestMain.java
b/platforms/catalog-rest-app/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRestMain.java
index 9f22952..674a126 100644
--- a/platforms/catalog-rest-app/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRestMain.java
+++ b/platforms/catalog-rest-app/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRestMain.java
@@ -27,8 +27,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Main to start the Camel Catalog REST Api application which runs standalone using an embedded
CXF/Jetty server
- * with embedded Swagger Doc and Swagger UI.
+ * Main to start the Camel Catalog and Connector Catalog REST Api application
+ * which runs standalone using an embedded CXF/Jetty server with embedded Swagger Doc and
Swagger UI.
  */
 public class CamelCatalogRestMain {
 
@@ -36,6 +36,7 @@ public class CamelCatalogRestMain {
 
     private Server server;
     private CamelCatalogRest catalog;
+    private CamelConnectorCatalogRest connectorCatalog;
     private int port = 8080;
 
     public static void main(String[] args) {
@@ -47,19 +48,21 @@ public class CamelCatalogRestMain {
         LOGGER.info("Starting ...");
 
         catalog = new CamelCatalogRest();
+        connectorCatalog = new CamelConnectorCatalogRest();
 
         // setup Apache CXF REST server
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
-        sf.setResourceClasses(CamelCatalogRest.class);
+        sf.setResourceClasses(CamelCatalogRest.class, CamelConnectorCatalogRest.class);
         sf.setResourceProvider(CamelCatalogRest.class, new SingletonResourceProvider(catalog));
+        sf.setResourceProvider(CamelConnectorCatalogRest.class, new SingletonResourceProvider(connectorCatalog));
 
         Swagger2Feature swagger = new Swagger2Feature();
         swagger.setBasePath("/");
         swagger.setScanAllResources(false);
         swagger.setPrettyPrint(true);
         swagger.setSupportSwaggerUi(true);
-        swagger.setTitle("Camel Catalog REST Api");
-        swagger.setDescription("REST Api for the Camel Catalog");
+        swagger.setTitle("Camel Catalog and Connector Catalog REST Api");
+        swagger.setDescription("REST Api for the Camel Catalog and Connector Catalog");
         swagger.setVersion(catalog.getCatalogVersion());
         swagger.setContact("Apache Camel");
         sf.getFeatures().add(swagger);
@@ -76,6 +79,11 @@ public class CamelCatalogRestMain {
         LOGGER.info("");
         LOGGER.info("\tRest API base path: http://localhost:{}/camel-catalog", port);
         LOGGER.info("\tRest API version: http://localhost:{}/camel-catalog/catalogVersion",
port);
+        LOGGER.info("");
+        LOGGER.info("CamelConnectorCatalog REST Api started");
+        LOGGER.info("");
+        LOGGER.info("\tRest API base path: http://localhost:{}/camel-connector-catalog",
port);
+        LOGGER.info("");
         LOGGER.info("\tSwagger Doc: http://localhost:{}/swagger.json", port);
         LOGGER.info("\tSwagger UI: http://localhost:{}/api-docs?url=/swagger.json", port);
         LOGGER.info("");

http://git-wip-us.apache.org/repos/asf/camel/blob/dbeb42c4/platforms/catalog-rest/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/catalog-rest/pom.xml b/platforms/catalog-rest/pom.xml
index 4ebc70f..4e67268 100644
--- a/platforms/catalog-rest/pom.xml
+++ b/platforms/catalog-rest/pom.xml
@@ -1,21 +1,22 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <!--
-    Licensed to the Apache Software Foundation (ASF) under one or more
-    contributor license agreements.  See the NOTICE file distributed with
-    this work for additional information regarding copyright ownership.
-    The ASF licenses this file to You under the Apache License, Version 2.0
-    (the "License"); you may not use this file except in compliance with
-    the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
-  -->
+
   <modelVersion>4.0.0</modelVersion>
 
   <parent>
@@ -35,6 +36,10 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-catalog</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-catalog-connector</artifactId>
+    </dependency>
 
     <!-- REST api -->
     <dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/dbeb42c4/platforms/catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java
b/platforms/catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java
new file mode 100644
index 0000000..afe2445
--- /dev/null
+++ b/platforms/catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.catalog.rest;
+
+import java.util.List;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.apache.camel.catalog.connector.CamelConnectorCatalog;
+import org.apache.camel.catalog.connector.ConnectorDto;
+import org.apache.camel.catalog.connector.DefaultCamelConnectorCatalog;
+
+/**
+ * A REST based {@link CamelConnectorCatalog} service as a JAX-RS resource class.
+ */
+@Api(value = "/camel-connector-catalog", description = "Camel Connector Catalog REST API")
+@Path("/camel-connector-catalog")
+public class CamelConnectorCatalogRest {
+
+    private CamelConnectorCatalog catalog = new DefaultCamelConnectorCatalog();
+
+    public CamelConnectorCatalog getCatalog() {
+        return catalog;
+    }
+
+    /**
+     * To inject an existing {@link CamelConnectorCatalog}
+     */
+    public void setCatalog(CamelConnectorCatalog catalog) {
+        this.catalog = catalog;
+    }
+
+    @GET
+    @Path("/findConnector")
+    @Produces("application/json")
+    @ApiOperation(value = "Find all the connectors from the catalog")
+    public List<ConnectorDto> findConnector(@ApiParam("Whether to include latest version
only")
+                                            @QueryParam("latestVersionOnly") boolean latestVersionOnly)
{
+        return catalog.findConnector(latestVersionOnly);
+    }
+
+    @GET
+    @Path("/findConnector/{filter}")
+    @Produces("application/json")
+    @ApiOperation(value = "Find all the connectors from the catalog")
+    public List<ConnectorDto> findConnector(@ApiParam("Filter the connector matching
by name, description or labels")
+                                            @PathParam("filter") String filter,
+                                            @ApiParam("Whether to include latest version
only")
+                                            @QueryParam("latestVersionOnly") boolean latestVersionOnly)
{
+        return catalog.findConnector(latestVersionOnly);
+    }
+
+    @GET
+    @Path("/connectorJSon/{groupId}/{artifactId}/{version}")
+    @Produces("application/json")
+    @ApiOperation(value = "Returns the camel-connector json file for the given connector
with the Maven coordinate")
+    public String connectorJSon(@ApiParam("Maven groupdId of the connector")
+                                @PathParam("groupId") String groupId,
+                                @ApiParam("Maven artifactId of the connector")
+                                @PathParam("artifactId") String artifactId,
+                                @ApiParam("Maven version of the connector")
+                                @PathParam("version") String version) {
+        return catalog.connectorJSon(groupId, artifactId, version);
+    }
+
+    @GET
+    @Path("/connectorSchemaJSon/{groupId}/{artifactId}/{version}")
+    @Produces("application/json")
+    @ApiOperation(value = "Returns the camel-connector-schema json file for the given connector
with the Maven coordinate")
+    public String connectorSchemaJSon(@ApiParam("Maven groupdId of the connector")
+                                      @PathParam("groupId") String groupId,
+                                      @ApiParam("Maven artifactId of the connector")
+                                      @PathParam("artifactId") String artifactId,
+                                      @ApiParam("Maven version of the connector")
+                                      @PathParam("version") String version) {
+        return catalog.connectorSchemaJSon(groupId, artifactId, version);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/dbeb42c4/platforms/catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogRestTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogRestTest.java
b/platforms/catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogRestTest.java
index 44a17f6..46f233b 100644
--- a/platforms/catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogRestTest.java
+++ b/platforms/catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelCatalogRestTest.java
@@ -64,7 +64,8 @@ public class CamelCatalogRestTest {
     @Test
     public void testFindComponentLabels() throws Exception {
         given().
-           baseUri("http://localhost:" + port).
+            baseUri("http://localhost:" + port).
+            accept("application/json").
             when().
                 get("/camel-catalog/findComponentLabels").
             then().
@@ -75,6 +76,7 @@ public class CamelCatalogRestTest {
     public void testComponentJSonSchema() throws Exception {
         given().
             baseUri("http://localhost:" + port).
+            accept("application/json").
             when().
                 get("/camel-catalog/componentJSonSchema/quartz2").
             then().

http://git-wip-us.apache.org/repos/asf/camel/blob/dbeb42c4/platforms/catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRestTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRestTest.java
b/platforms/catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRestTest.java
new file mode 100644
index 0000000..04dfc22
--- /dev/null
+++ b/platforms/catalog-rest/src/test/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRestTest.java
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.catalog.rest;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.hamcrest.Matchers;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static io.restassured.RestAssured.given;
+
+public class CamelConnectorCatalogRestTest {
+
+    private Server server;
+    private CamelConnectorCatalogRest catalog;
+    private int port;
+
+    @Before
+    public void setup() {
+        catalog = new CamelConnectorCatalogRest();
+
+        port = AvailablePortFinder.getNextAvailable(9000);
+
+        // setup Apache CXF REST server
+        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+        sf.setResourceClasses(CamelConnectorCatalogRest.class);
+        sf.setResourceProvider(CamelConnectorCatalogRest.class, new SingletonResourceProvider(catalog));
+        // to use jackson for json
+        sf.setProvider(JacksonJsonProvider.class);
+        sf.setAddress("http://localhost:" + port);
+
+        // create and start the CXF server (non blocking)
+        server = sf.create();
+        server.start();
+    }
+
+    @After
+    public void stop() {
+        if (server != null) {
+            server.stop();
+        }
+    }
+
+    @Test
+    public void testEmptyFindConnectors() throws Exception {
+        given().
+            baseUri("http://localhost:" + port).
+            accept("application/json").
+            when().
+                get("/camel-connector-catalog/findConnector?latestVersionOnly=false").
+            then().
+                body(Matchers.hasToString("[]"));
+    }
+
+    @Test
+    public void testFindConnectors() throws Exception {
+        catalog.getCatalog().addConnector("org.apache.camel", "myfoo-connector", "2.19.0",
"MyFoo", "Something cool", "foo,timer", null, null);
+
+        given().
+            baseUri("http://localhost:" + port).
+            accept("application/json").
+            when().
+                get("/camel-connector-catalog/findConnector?latestVersionOnly=false").
+            then().
+                body(Matchers.containsString("MyFoo"));
+
+    }
+
+}


Mime
View raw message