camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-10967: camel-catalog-connector - Add api to build endpoint uri based on connection options
Date Thu, 09 Mar 2017 12:32:58 GMT
Repository: camel
Updated Branches:
  refs/heads/master 7f561212a -> 1dfb70985


CAMEL-10967: camel-catalog-connector - Add api to build endpoint uri based on connection options


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

Branch: refs/heads/master
Commit: 1dfb70985f1962d30eb9336488c63c39fd1b30c8
Parents: 655916c
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Mar 9 13:32:41 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Mar 9 13:32:48 2017 +0100

----------------------------------------------------------------------
 .../connector/CamelConnectorCatalog.java        | 22 ------------
 .../connector/DefaultCamelConnectorCatalog.java | 36 --------------------
 .../camel/catalog/rest/CamelCatalogRest.java    | 18 +++++++++-
 .../catalog/rest/CamelConnectorCatalogRest.java | 35 +++++++++++++++++++
 .../org/apache/camel/catalog/CamelCatalog.java  |  4 +--
 5 files changed, 54 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1dfb7098/platforms/camel-catalog-connector/src/main/java/org/apache/camel/catalog/connector/CamelConnectorCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/camel-catalog-connector/src/main/java/org/apache/camel/catalog/connector/CamelConnectorCatalog.java
b/platforms/camel-catalog-connector/src/main/java/org/apache/camel/catalog/connector/CamelConnectorCatalog.java
index 5bbebf3..80c9fae 100644
--- a/platforms/camel-catalog-connector/src/main/java/org/apache/camel/catalog/connector/CamelConnectorCatalog.java
+++ b/platforms/camel-catalog-connector/src/main/java/org/apache/camel/catalog/connector/CamelConnectorCatalog.java
@@ -112,28 +112,6 @@ public interface CamelConnectorCatalog {
     String componentSchemaJSon(String groupId, String artifactId, String version);
 
     /**
-     * Creates an endpoint uri in Java style from the information in the json schema
-     *
-     * @param scheme the endpoint schema
-     * @param json the json schema with the endpoint properties
-     * @param encode whether to URL encode the returned uri or not
-     * @return the constructed endpoint uri
-     * @throws java.net.URISyntaxException is thrown if there is encoding error
-     */
-    String asEndpointUri(String scheme, String json, boolean encode) throws URISyntaxException;
-
-    /**
-     * Creates an endpoint uri in XML style (eg escape & as &ampl;) from the information
in the json schema
-     *
-     * @param scheme the endpoint schema
-     * @param json the json schema with the endpoint properties
-     * @param encode whether to URL encode the returned uri or not
-     * @return the constructed endpoint uri
-     * @throws java.net.URISyntaxException is thrown if there is encoding error
-     */
-    String asEndpointUriXml(String scheme, String json, boolean encode) throws URISyntaxException;
-
-    /**
      * Creates an endpoint uri in Java style from the information from the properties
      *
      * @param scheme the endpoint schema

http://git-wip-us.apache.org/repos/asf/camel/blob/1dfb7098/platforms/camel-catalog-connector/src/main/java/org/apache/camel/catalog/connector/DefaultCamelConnectorCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/camel-catalog-connector/src/main/java/org/apache/camel/catalog/connector/DefaultCamelConnectorCatalog.java
b/platforms/camel-catalog-connector/src/main/java/org/apache/camel/catalog/connector/DefaultCamelConnectorCatalog.java
index 57d5f3f..387164c 100644
--- a/platforms/camel-catalog-connector/src/main/java/org/apache/camel/catalog/connector/DefaultCamelConnectorCatalog.java
+++ b/platforms/camel-catalog-connector/src/main/java/org/apache/camel/catalog/connector/DefaultCamelConnectorCatalog.java
@@ -106,42 +106,6 @@ public class DefaultCamelConnectorCatalog implements CamelConnectorCatalog
{
     }
 
     @Override
-    public String asEndpointUri(String scheme, String json, boolean encode) throws URISyntaxException
{
-        // delegate to use CamelCatalog
-        Optional<ConnectorDto> found = dataStore.findConnector(null, true).stream().filter(d
-> d.getScheme().equals(scheme)).findAny();
-        if (found.isPresent()) {
-            ConnectorDto dto = found.get();
-
-            // need to add custom connector as component to the catalog before we can build
the uri
-            String javaType = dto.getJavaType();
-            String componentJson = componentSchemaJSon(dto.getGroupId(), dto.getArtifactId(),
dto.getVersion());
-
-            camelCatalog.addComponent(scheme, javaType, componentJson);
-            return camelCatalog.asEndpointUri(scheme, json, encode);
-        }
-        // no connector with that scheme
-        return null;
-    }
-
-    @Override
-    public String asEndpointUriXml(String scheme, String json, boolean encode) throws URISyntaxException
{
-        // delegate to use CamelCatalog
-        Optional<ConnectorDto> found = dataStore.findConnector(null, true).stream().filter(d
-> d.getScheme().equals(scheme)).findAny();
-        if (found.isPresent()) {
-            ConnectorDto dto = found.get();
-
-            // need to add custom connector as component to the catalog before we can build
the uri
-            String javaType = dto.getJavaType();
-            String componentJson = componentSchemaJSon(dto.getGroupId(), dto.getArtifactId(),
dto.getVersion());
-
-            camelCatalog.addComponent(scheme, javaType, componentJson);
-            return camelCatalog.asEndpointUriXml(scheme, json, encode);
-        }
-        // no connector with that scheme
-        return null;
-    }
-
-    @Override
     public String asEndpointUri(String scheme, Map<String, String> properties, boolean
encode) throws URISyntaxException {
         // delegate to use CamelCatalog
         Optional<ConnectorDto> found = dataStore.findConnector(null, true).stream().filter(d
-> d.getScheme().equals(scheme)).findAny();

http://git-wip-us.apache.org/repos/asf/camel/blob/1dfb7098/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRest.java
----------------------------------------------------------------------
diff --git a/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRest.java
b/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRest.java
index 6514783..9092f6c 100644
--- a/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRest.java
+++ b/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelCatalogRest.java
@@ -295,7 +295,7 @@ public class CamelCatalogRest {
     @Path("/asEndpointUri/{scheme}")
     @Consumes("application/json")
     @Produces("text/plain")
-    @ApiOperation(value = "Creates an endpoint uri in Java style from the information in
the json schema")
+    @ApiOperation(value = "Creates an endpoint uri in Java style configured using the provided
options in the JSon body")
     public String asEndpointUri(@ApiParam(value = "The component scheme", readOnly = true)
@PathParam("scheme") String scheme,
                                 @ApiParam(value = "The options as a JSon map with key/value
pairs", required = true) String json) {
         try {
@@ -308,6 +308,22 @@ public class CamelCatalogRest {
     }
 
     @POST
+    @Path("/asEndpointUriXml/{scheme}")
+    @Consumes("application/json")
+    @Produces("text/plain")
+    @ApiOperation(value = "Creates an endpoint uri in XML style configured using the provided
options in the JSon body")
+    public String asEndpointUriXml(@ApiParam(value = "The component scheme", readOnly = true)
@PathParam("scheme") String scheme,
+                                   @ApiParam(value = "The options as a JSon map with key/value
pairs", required = true) String json) {
+        try {
+            ObjectMapper mapper = new ObjectMapper();
+            Map map = mapper.readValue(json, Map.class);
+            return catalog.asEndpointUriXml(scheme, map, true);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @POST
     @Path("/mavenCacheDirectory/{name}")
     @ApiOperation(value = "Configures the Maven cache directory to use when downloading artifacts")
     public void mavenCacheDirectory(@ApiParam(value = "The name of the cache directory",
required = true) @PathParam("name") String name) {

http://git-wip-us.apache.org/repos/asf/camel/blob/1dfb7098/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java
----------------------------------------------------------------------
diff --git a/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java
b/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java
index 03ad80b..24c8153 100644
--- a/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java
+++ b/platforms/camel-catalog-rest/src/main/java/org/apache/camel/catalog/rest/CamelConnectorCatalogRest.java
@@ -17,7 +17,9 @@
 package org.apache.camel.catalog.rest;
 
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
+import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
@@ -25,6 +27,7 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -104,6 +107,38 @@ public class CamelConnectorCatalogRest {
     }
 
     @POST
+    @Path("/asEndpointUri/{scheme}")
+    @Consumes("application/json")
+    @Produces("text/plain")
+    @ApiOperation(value = "Creates an endpoint uri in Java style configured using the provided
options in the JSon body")
+    public String asEndpointUri(@ApiParam(value = "The component scheme", readOnly = true)
@PathParam("scheme") String scheme,
+                                @ApiParam(value = "The options as a JSon map with key/value
pairs", required = true) String json) {
+        try {
+            ObjectMapper mapper = new ObjectMapper();
+            Map map = mapper.readValue(json, Map.class);
+            return catalog.asEndpointUri(scheme, map, true);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @POST
+    @Path("/asEndpointUriXml/{scheme}")
+    @Consumes("application/json")
+    @Produces("text/plain")
+    @ApiOperation(value = "Creates an endpoint uri in XML style configured using the provided
options in the JSon body")
+    public String asEndpointUriXml(@ApiParam(value = "The component scheme", readOnly = true)
@PathParam("scheme") String scheme,
+                                   @ApiParam(value = "The options as a JSon map with key/value
pairs", required = true) String json) {
+        try {
+            ObjectMapper mapper = new ObjectMapper();
+            Map map = mapper.readValue(json, Map.class);
+            return catalog.asEndpointUriXml(scheme, map, true);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @POST
     @Path("/mavenCacheDirectory/{name}")
     @ApiOperation(value = "Configures the Maven cache directory to use when downloading artifacts")
     public void mavenCacheDirectory(@ApiParam(value = "The name of the cache directory",
required = true) @PathParam("name") String name) {

http://git-wip-us.apache.org/repos/asf/camel/blob/1dfb7098/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
index e45eb67..ca5f4f6 100644
--- a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
+++ b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
@@ -513,7 +513,7 @@ public interface CamelCatalog {
     String asEndpointUri(String scheme, String json, boolean encode) throws URISyntaxException;
 
     /**
-     * Creates an endpoint uri in XML style (eg escape & as &ampl;) from the information
in the json schema
+     * Creates an endpoint uri in XML style from the information in the json schema
      *
      * @param scheme the endpoint schema
      * @param json the json schema with the endpoint properties
@@ -536,7 +536,7 @@ public interface CamelCatalog {
     String asEndpointUri(String scheme, Map<String, String> properties, boolean encode)
throws URISyntaxException;
 
     /**
-     * Creates an endpoint uri in XML style (eg escape & as &ampl;) from the information
from the properties
+     * Creates an endpoint uri in XML style from the information from the properties
      *
      * @param scheme the endpoint schema
      * @param properties the properties as key value pairs


Mime
View raw message