You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/05/25 04:28:17 UTC

[camel] branch main updated (972d6fc3e15 -> 27dfd5ce22f)

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from 972d6fc3e15 camel-elasticsearch: Downgrade the jackson version to 2.14.3 (#10203)
     new ca2c6815881 (chores) camel-util: return an empty map if there's no parameters
     new 44d0d0421bf (chores) camel-util: rework the createQueryString to use an array of Strings
     new 27dfd5ce22f (chores) camel-util: skip replacing percent unless it is present

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/camel/util/URIScanner.java     | 11 ++++++-
 .../java/org/apache/camel/util/URISupport.java     | 38 ++++++++++++++--------
 2 files changed, 35 insertions(+), 14 deletions(-)


[camel] 02/03: (chores) camel-util: rework the createQueryString to use an array of Strings

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 44d0d0421bf0a9d42f0619424a283c97d832e474
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed May 24 18:00:48 2023 +0200

    (chores) camel-util: rework the createQueryString to use an array of Strings
---
 .../java/org/apache/camel/util/URISupport.java     | 33 ++++++++++++++--------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
index 06dd4d72f9b..6ba36cac9c4 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
@@ -22,13 +22,14 @@ import java.net.URISyntaxException;
 import java.net.URLEncoder;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.regex.Pattern;
 
 import static org.apache.camel.util.CamelURIParser.URI_ALREADY_NORMALIZED;
@@ -436,7 +437,8 @@ public final class URISupport {
      *                 options.
      */
     public static String createQueryString(Map<String, Object> options) {
-        return createQueryString(options.keySet(), options, true);
+        final Set<String> keySet = options.keySet();
+        return createQueryString(keySet.toArray(new String[keySet.size()]), options, true);
     }
 
     /**
@@ -451,7 +453,7 @@ public final class URISupport {
         return createQueryString(options.keySet(), options, encode);
     }
 
-    public static String createQueryString(Collection<String> sortedKeys, Map<String, Object> options, boolean encode) {
+    private static String createQueryString(String[] sortedKeys, Map<String, Object> options, boolean encode) {
         if (options.isEmpty()) {
             return EMPTY_QUERY_STRING;
         }
@@ -489,6 +491,11 @@ public final class URISupport {
         return rc.toString();
     }
 
+    @Deprecated
+    public static String createQueryString(Collection<String> sortedKeys, Map<String, Object> options, boolean encode) {
+        return createQueryString(sortedKeys.toArray(new String[sortedKeys.size()]), options, encode);
+    }
+
     private static void appendQueryStringParameter(String key, String value, StringBuilder rc, boolean encode) {
         if (encode) {
             String encoded = URLEncoder.encode(key, CHARSET);
@@ -646,11 +653,12 @@ public final class URISupport {
                 return buildUri(scheme, path, query);
             } else {
                 // reorder parameters a..z
-                List<String> keys = new ArrayList<>(parameters.keySet());
-                keys.sort(null);
+                final Set<String> keySet = parameters.keySet();
+                final String[] parametersArray = keySet.toArray(new String[keySet.size()]);
+                Arrays.sort(parametersArray);
 
                 // build uri object with sorted parameters
-                query = URISupport.createQueryString(keys, parameters, true);
+                query = URISupport.createQueryString(parametersArray, parameters, true);
                 return buildUri(scheme, path, query);
             }
         }
@@ -680,14 +688,17 @@ public final class URISupport {
             // only parse if there are parameters
             parameters = URISupport.parseQuery(query, false, false);
         }
+
         if (parameters == null || parameters.size() == 1) {
             return buildUri(scheme, path, query);
         } else {
+            final Set<String> entries = parameters.keySet();
+
             // reorder parameters a..z
             // optimize and only build new query if the keys was resorted
             boolean sort = false;
             String prev = null;
-            for (String key : parameters.keySet()) {
+            for (String key : entries) {
                 if (prev == null) {
                     prev = key;
                 } else {
@@ -700,10 +711,10 @@ public final class URISupport {
                 }
             }
             if (sort) {
-                List<String> keys = new ArrayList<>(parameters.keySet());
-                keys.sort(null);
-                // rebuild query with sorted parameters
-                query = URISupport.createQueryString(keys, parameters, true);
+                final String[] array = entries.toArray(new String[entries.size()]);
+                Arrays.sort(array);
+
+                query = URISupport.createQueryString(array, parameters, true);
             }
 
             return buildUri(scheme, path, query);


[camel] 01/03: (chores) camel-util: return an empty map if there's no parameters

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ca2c6815881c9617797566c965ef120d8ca5e8be
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed May 24 15:24:03 2023 +0200

    (chores) camel-util: return an empty map if there's no parameters
---
 core/camel-util/src/main/java/org/apache/camel/util/URISupport.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
index 3a0a124d881..06dd4d72f9b 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
@@ -24,6 +24,7 @@ import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -210,7 +211,7 @@ public final class URISupport {
     public static Map<String, Object> parseQuery(String uri, boolean useRaw, boolean lenient) throws URISyntaxException {
         if (uri == null || uri.isEmpty()) {
             // return an empty map
-            return new LinkedHashMap<>(0);
+            return Collections.emptyMap();
         }
 
         // must check for trailing & as the uri.split("&") will ignore those


[camel] 03/03: (chores) camel-util: skip replacing percent unless it is present

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 27dfd5ce22f6ebb6deac30500d649a57827cdde1
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed May 24 18:37:03 2023 +0200

    (chores) camel-util: skip replacing percent unless it is present
---
 .../src/main/java/org/apache/camel/util/URIScanner.java       | 11 ++++++++++-
 .../src/main/java/org/apache/camel/util/URISupport.java       |  2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java b/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java
index c387e89c985..9753dda63fe 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java
@@ -161,7 +161,8 @@ class URIScanner {
             text = value.toString();
         } else {
             // need to replace % with %25 to avoid losing "%" when decoding
-            String s = value.toString().replace("%", "%25");
+            final String s = replacePercent(value.toString());
+
             text = URLDecoder.decode(s, CHARSET);
         }
 
@@ -259,4 +260,12 @@ class URIScanner {
         return null;
     }
 
+    public static String replacePercent(String input) {
+        if (input.contains("%")) {
+            return input.replace("%", "%25");
+        }
+
+        return input;
+    }
+
 }
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
index 6ba36cac9c4..2d3b16fd911 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
@@ -512,7 +512,7 @@ public final class URISupport {
         if (raw != null) {
             // do not encode RAW parameters unless it has %
             // need to replace % with %25 to avoid losing "%" when decoding
-            String s = value.replace("%", "%25");
+            final String s = URIScanner.replacePercent(value);
             rc.append(s);
         } else {
             if (encode) {