Skip to content

Commit

Permalink
SLING-9327 - switch to commons-code base64 encoder, suspecting it's j…
Browse files Browse the repository at this point in the history
…ava.util.Base64 which uses DatatypeConverter
  • Loading branch information
bdelacretaz committed Apr 2, 2020
1 parent dd456c3 commit 7281da1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
<artifactId>commons-lang3</artifactId>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
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;
Expand All @@ -43,16 +43,18 @@
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;
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());
Expand All @@ -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;
Expand All @@ -72,14 +74,16 @@ public SimpleHttpResponse(int status, String body) {
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);
}
Expand All @@ -102,7 +106,11 @@ int getHttpTimeoutSeconds() {
}

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) {
Expand Down

0 comments on commit 7281da1

Please sign in to comment.