Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #942 from huadong/master
Browse files Browse the repository at this point in the history
Fix Base64 Error: ArrayIndexOutOfBoundsException
  • Loading branch information
davidxia committed May 20, 2018
2 parents 4ca7426 + 4f5b8c1 commit 70da158
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/com/spotify/docker/client/DefaultDockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -165,6 +166,8 @@
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
Expand All @@ -183,7 +186,6 @@
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.RequestEntityProcessing;
import org.glassfish.jersey.internal.util.Base64;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -2746,9 +2748,9 @@ private String authHeader(final RegistryAuth registryAuth) throws DockerExceptio
return "null";
}
try {
return Base64.encodeAsString(ObjectMapperProvider
return Base64.encodeBase64String(ObjectMapperProvider
.objectMapper()
.writeValueAsString(registryAuth));
.writeValueAsBytes(registryAuth));
} catch (JsonProcessingException ex) {
throw new DockerException("Could not encode X-Registry-Auth header", ex);
}
Expand All @@ -2774,7 +2776,7 @@ private String authRegistryHeader(final RegistryConfigs registryConfigs)
authRegistryJson = "{\"auths\":" + authRegistryJson + "}";
}

return Base64.encodeAsString(authRegistryJson);
return Base64.encodeBase64String(authRegistryJson.getBytes(StandardCharsets.UTF_8));
} catch (JsonProcessingException | InterruptedException ex) {
throw new DockerException("Could not encode X-Registry-Config header", ex);
}
Expand Down

0 comments on commit 70da158

Please sign in to comment.