camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1384345 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/util/URISupport.java test/java/org/apache/camel/util/URISupportTest.java
Date Thu, 13 Sep 2012 14:30:22 GMT
Author: davsclaus
Date: Thu Sep 13 14:30:22 2012
New Revision: 1384345

URL: http://svn.apache.org/viewvc?rev=1384345&view=rev
Log:
CAMEL-5603: Support using @ sign in user info part of endpoint uri, to make it easier for
people who uses @ in either username/password.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java?rev=1384345&r1=1384344&r2=1384345&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java Thu Sep 13
14:30:22 2012
@@ -284,9 +284,28 @@ public final class URISupport {
         if (idx != -1) {
             path = path.substring(0, idx);
         }
-        
+
         path = UnsafeUriCharactersEncoder.encode(path);
 
+        // okay if we have user info in the path and they use @ in username or password,
+        // then we need to encode them (but leave the last @ sign before the hostname)
+        // this is needed as Camel end users may not encode their user info properly, but
expect
+        // this to work out of the box with Camel, and hence we need to fix it for them
+        String userInfoPath = path;
+        if (userInfoPath.contains("/")) {
+            userInfoPath = userInfoPath.substring(0, userInfoPath.indexOf("/"));
+        }
+        if (StringHelper.countChar(userInfoPath, '@') > 1) {
+            int max = userInfoPath.lastIndexOf('@');
+            String before = userInfoPath.substring(0, max);
+            // after must be from original path
+            String after = path.substring(max);
+
+            // replace the @ with %40
+            before = StringHelper.replaceAll(before, "@", "%40");
+            path = before + after;
+        }
+
         // in case there are parameters we should reorder them
         Map<String, Object> parameters = URISupport.parseParameters(u);
         if (parameters.isEmpty()) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java?rev=1384345&r1=1384344&r2=1384345&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java Thu Sep
13 14:30:22 2012
@@ -22,6 +22,7 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
 
 /**
  * @version
@@ -188,4 +189,23 @@ public class URISupportTest extends Cont
         assertEquals(path, URISupport.sanitizePath(path));
     }
 
-}
+    public void testNormalizeEndpointUriWithUserInfoSpecialSign() throws Exception {
+        String out1 = URISupport.normalizeUri("ftp://us%40r:t%st@localhost:21000/tmp3/camel?foo=us@r");
+        assertEquals("ftp://us%40r:t%25st@localhost:21000/tmp3/camel?foo=us%40r", out1);
+
+        String out2 = URISupport.normalizeUri("ftp://us%40r:t%25st@localhost:21000/tmp3/camel?foo=us@r");
+        assertEquals("ftp://us%40r:t%25st@localhost:21000/tmp3/camel?foo=us%40r", out2);
+
+        String out3 = URISupport.normalizeUri("ftp://us@r:t%st@localhost:21000/tmp3/camel?foo=us@r");
+        assertEquals("ftp://us%40r:t%25st@localhost:21000/tmp3/camel?foo=us%40r", out3);
+
+        String out4 = URISupport.normalizeUri("ftp://us@r:t%25st@localhost:21000/tmp3/camel?foo=us@r");
+        assertEquals("ftp://us%40r:t%25st@localhost:21000/tmp3/camel?foo=us%40r", out4);
+    }
+
+    public void testSpecialUriFromXmppComponent() throws Exception {
+        String out1 = URISupport.normalizeUri("xmpp://camel-user@localhost:123/test-user@localhost?password=secret&serviceName=someCoolChat");
+        assertEquals("xmpp://camel-user@localhost:123/test-user@localhost?password=secret&serviceName=someCoolChat",
out1);
+    }
+
+}
\ No newline at end of file



Mime
View raw message