camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/4] camel git commit: Camel catalog - Fixed validator/endpoint parser when uris have authority and port number is a placeholder and not a number.
Date Thu, 07 Jan 2016 20:02:54 GMT
Camel catalog - Fixed validator/endpoint parser when uris have authority and port number is
a placeholder and not a number.


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

Branch: refs/heads/camel-2.16.x
Commit: e8b1ba6e035a6250eaddcb1e297e319f885d73d3
Parents: bf0e1d5
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Jan 7 21:02:16 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Jan 7 21:02:43 2016 +0100

----------------------------------------------------------------------
 .../camel/catalog/DefaultCamelCatalog.java      | 75 +++++++++++---------
 .../apache/camel/catalog/CamelCatalogTest.java  |  7 ++
 2 files changed, 47 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e8b1ba6e/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index 028a43b..24baa69 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -942,24 +942,6 @@ public class DefaultCamelCatalog implements CamelCatalog {
             throw new IllegalArgumentException("Cannot find endpoint with scheme " + scheme);
         }
 
-        Map<String, String> userInfoOptions = new LinkedHashMap<String, String>();
-
-        // do we have user info in authority?
-        boolean userInfo = false;
-        String username = null;
-        String password = null;
-        if (u.getUserInfo() != null) {
-            userInfo = true;
-            String[] parts = u.getUserInfo().split(":");
-            if (parts.length == 2) {
-                username = parts[0];
-                password = parts[1];
-            } else {
-                // only username
-                username = u.getUserInfo();
-            }
-        }
-
         // grab the syntax
         String syntax = null;
         String alternativeSyntax = null;
@@ -976,31 +958,54 @@ public class DefaultCamelCatalog implements CamelCatalog {
             throw new IllegalArgumentException("Endpoint with scheme " + scheme + " has no
syntax defined in the json schema");
         }
 
-        // clip the scheme from the syntax
-        syntax = after(syntax, ":");
-        if (alternativeSyntax != null) {
-            alternativeSyntax = after(alternativeSyntax, ":");
-        }
-
-        // clip the scheme from the uri
-        uri = after(uri, ":");
-        String uriPath = stripQuery(uri);
-
-        // do the component support userinfo?
+        // only if we support alternative syntax, and the uri contains the username and password
in the authority
+        // part of the uri, then we would need some special logic to capture that information
and strip those
+        // details from the uri, so we can continue parsing the uri using the normal syntax
+        Map<String, String> userInfoOptions = new LinkedHashMap<String, String>();
         if (alternativeSyntax != null && alternativeSyntax.contains("@")) {
+            // clip the scheme from the syntax
+            alternativeSyntax = after(alternativeSyntax, ":");
+            // trim so only userinfo
             int idx = alternativeSyntax.indexOf("@");
             String fields = alternativeSyntax.substring(0, idx);
             String[] names = fields.split(":");
-            if (userInfo && names.length == 2) {
-                userInfoOptions.put(names[0], username);
-                if (password != null) {
-                    // password is optional
-                    userInfoOptions.put(names[1], password);
+
+            // grab authority part and grab username and/or password
+            String authority = u.getAuthority();
+            if (authority != null && authority.contains("@")) {
+                String username = null;
+                String password = null;
+
+                // grab unserinfo part before @
+                String userInfo = authority.substring(0, authority.indexOf("@"));
+                String[] parts = userInfo.split(":");
+                if (parts.length == 2) {
+                    username = parts[0];
+                    password = parts[1];
+                } else {
+                    // only username
+                    username = userInfo;
+                }
+
+                // remember the username and/or password which we add later to the options
+                if (names.length == 2) {
+                    userInfoOptions.put(names[0], username);
+                    if (password != null) {
+                        // password is optional
+                        userInfoOptions.put(names[1], password);
+                    }
                 }
             }
         }
+
+        // clip the scheme from the syntax
+        syntax = after(syntax, ":");
+        // clip the scheme from the uri
+        uri = after(uri, ":");
+        String uriPath = stripQuery(uri);
+
         // strip user info from uri path
-        if (userInfo) {
+        if (!userInfoOptions.isEmpty()) {
             int idx = uriPath.indexOf('@');
             if (idx > -1) {
                 uriPath = uriPath.substring(idx + 1);

http://git-wip-us.apache.org/repos/asf/camel/blob/e8b1ba6e/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index ded4da0..b764e1b 100644
--- a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -533,6 +533,13 @@ public class CamelCatalogTest {
         result = catalog.validateEndpointProperties("ssh://scott@localhost:8101?certResource=classpath:test_rsa&useFixedDelay=true&delay=5000&pollCommand=features:list%0A");
         assertTrue(result.isSuccess());
 
+        // userinfo with both user and password and placeholder
+        result = catalog.validateEndpointProperties("ssh://smx:smx@localhost:8181?timeout=3000");
+        assertTrue(result.isSuccess());
+        // and should also work when port is using a placeholder
+        result = catalog.validateEndpointProperties("ssh://smx:smx@localhost:{{port}}?timeout=3000");
+        assertTrue(result.isSuccess());
+
         // placeholder for a bunch of optional options
         result = catalog.validateEndpointProperties("aws-swf://activity?{{options}}");
         assertTrue(result.isSuccess());


Mime
View raw message