Use separate library to do base64 encoding in Java

default and jersey2 clients to make it work in both JVM and Android
This commit is contained in:
xhh 2015-11-22 16:27:14 +08:00 committed by Alvin Zeng
parent ff3ba73d18
commit 11d7e44756
7 changed files with 39 additions and 8 deletions

View File

@ -2,11 +2,12 @@ package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import com.migcomponents.migbase64.Base64;
import java.util.Map;
import java.util.List;
import java.io.UnsupportedEncodingException;
import javax.xml.bind.DatatypeConverter;
{{>generatedAnnotation}}
public class HttpBasicAuth implements Authentication {
@ -36,7 +37,7 @@ public class HttpBasicAuth implements Authentication {
}
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}

View File

@ -152,6 +152,13 @@
<version>${jodatime-version}</version>
</dependency>
<!-- Base64 encoding that works in both JVM and Android -->
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>

View File

@ -148,6 +148,13 @@
<version>${jodatime-version}</version>
</dependency>
<!-- Base64 encoding that works in both JVM and Android -->
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>

View File

@ -148,6 +148,13 @@
<version>${jodatime-version}</version>
</dependency>
<!-- Base64 encoding that works in both JVM and Android -->
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>

View File

@ -2,13 +2,14 @@ package io.swagger.client.auth;
import io.swagger.client.Pair;
import com.migcomponents.migbase64.Base64;
import java.util.Map;
import java.util.List;
import java.io.UnsupportedEncodingException;
import javax.xml.bind.DatatypeConverter;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:23.285+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-22T13:15:32.345+08:00")
public class HttpBasicAuth implements Authentication {
private String username;
private String password;
@ -36,7 +37,7 @@ public class HttpBasicAuth implements Authentication {
}
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}

View File

@ -152,6 +152,13 @@
<version>${jodatime-version}</version>
</dependency>
<!-- Base64 encoding that works in both JVM and Android -->
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>

View File

@ -2,13 +2,14 @@ package io.swagger.client.auth;
import io.swagger.client.Pair;
import com.migcomponents.migbase64.Base64;
import java.util.Map;
import java.util.List;
import java.io.UnsupportedEncodingException;
import javax.xml.bind.DatatypeConverter;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:47.318+08:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-22T13:15:27.225+08:00")
public class HttpBasicAuth implements Authentication {
private String username;
private String password;
@ -36,7 +37,7 @@ public class HttpBasicAuth implements Authentication {
}
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}