You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/04/02 11:00:41 UTC

[sling-org-apache-sling-junit-teleporter] 04/05: SLING-9327 - switch to commons-code base64 encoder, suspecting it's java.util.Base64 which uses DatatypeConverter

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

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-junit-teleporter.git

commit 7281da17f0f73f275d02adc9bc0eb5a443ca3250
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Apr 2 12:55:31 2020 +0200

    SLING-9327 - switch to commons-code base64 encoder, suspecting it's java.util.Base64 which uses DatatypeConverter
---
 pom.xml                                            |  5 +++++
 .../teleporter/client/TeleporterHttpClient.java    | 22 +++++++++++++++-------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/pom.xml b/pom.xml
index 10cb6bc..19f6ed8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -116,6 +116,11 @@
       <version>3.4</version>
     </dependency>
     <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <version>1.14</version>
+    </dependency>
+    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>
diff --git a/src/main/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClient.java b/src/main/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClient.java
index 2966335..abad021 100644
--- a/src/main/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClient.java
+++ b/src/main/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClient.java
@@ -23,13 +23,13 @@ import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
-import java.util.Base64;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -43,6 +43,7 @@ import javax.json.JsonString;
 import javax.json.JsonValue;
 import javax.json.JsonValue.ValueType;
 
+import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.io.IOUtils;
 import org.junit.runner.Result;
 import org.junit.runner.notification.Failure;
@@ -50,9 +51,10 @@ import org.junit.runners.model.MultipleFailureException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** Barebones HTTP client that supports just what the teleporter needs,
- *  with no dependencies outside of java.* and org.junit. Prevents us 
- *  from imposing a particular HTTP client version. 
+/**
+ * Barebones HTTP client that supports just what the teleporter needs, with no
+ * dependencies outside of java.* and org.junit. Prevents us from imposing a
+ * particular HTTP client version.
  */
 class TeleporterHttpClient {
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -62,7 +64,7 @@ class TeleporterHttpClient {
     private String credentials = null;
     private final String testServletPath;
     private final int httpTimeoutSeconds;
-    
+
     static final class SimpleHttpResponse {
         private final int status;
         private final String body;
@@ -72,14 +74,16 @@ class TeleporterHttpClient {
             this.status = status;
             this.body = body;
         }
+
         public int getStatus() {
             return status;
         }
+
         public String getBody() {
             return body;
         }
     }
-    
+
     TeleporterHttpClient(String baseUrl, String testServletPath) {
         this(baseUrl, testServletPath, ClientSideTeleporter.DEFAULT_TEST_READY_TIMEOUT_SECONDS);
     }
@@ -102,7 +106,11 @@ class TeleporterHttpClient {
     }
 
     static String encodeBase64(String data) {
-        return Base64.getEncoder().encodeToString(data.getBytes());
+        try {
+            return Base64.encodeBase64String(data.getBytes("UTF-8"));
+        } catch(UnsupportedEncodingException uee) {
+            throw new RuntimeException(uee);
+        }
     }
     
     public void setConnectionCredentials(URLConnection c) {