Skip to content

Commit 8fbe3cb

Browse files
authored
Merge pull request Azure#26 from Azure/revert-24-revert-23-master
Revert "Revert "Changes from AutoRest & SDK""
2 parents d67a862 + 7ad505c commit 8fbe3cb

File tree

8 files changed

+148
-13
lines changed

8 files changed

+148
-13
lines changed

azure-client-authentication/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ version = '1.0.0-SNAPSHOT'
1414

1515
checkstyle {
1616
toolVersion = "6.18"
17-
configFile = new File("$rootDir/ClientRuntimes/Java/build-tools/src/main/resources/checkstyle.xml")
18-
configProperties = [samedir: "$rootDir/ClientRuntimes/Java/build-tools/src/main/resources"]
19-
reportsDir = new File("$rootDir/ClientRuntimes/Java/build-tools/reports")
17+
configFile = new File("$rootDir/src/client/Java/build-tools/src/main/resources/checkstyle.xml")
18+
configProperties = [samedir: "$rootDir/src/client/Java/build-tools/src/main/resources"]
19+
reportsDir = new File("$rootDir/src/client/Java/build-tools/reports")
2020
}
2121

2222
dependencies {
@@ -92,7 +92,7 @@ artifacts {
9292

9393
test {
9494
reports.getHtml()
95-
reports.html.destination = file("${projectDir}/../../../TestResults/JavaAzureRuntime")
95+
reports.html.destination = file("$rootDir/TestResults/JavaAzureRuntime")
9696
}
9797

9898
tasks.compileJava.dependsOn 'clean'

azure-client-runtime/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ version = '1.0.0-SNAPSHOT'
1414

1515
checkstyle {
1616
toolVersion = "6.18"
17-
configFile = new File("$rootDir/ClientRuntimes/Java/build-tools/src/main/resources/checkstyle.xml")
18-
configProperties = [samedir: "$rootDir/ClientRuntimes/Java/build-tools/src/main/resources"]
19-
reportsDir = new File("$rootDir/ClientRuntimes/Java/build-tools/reports")
17+
configFile = new File("$rootDir/src/client/Java/build-tools/src/main/resources/checkstyle.xml")
18+
configProperties = [samedir: "$rootDir/src/client/Java/build-tools/src/main/resources"]
19+
reportsDir = new File("$rootDir/src/client/Java/build-tools/reports")
2020
}
2121

2222
dependencies {
@@ -90,7 +90,7 @@ artifacts {
9090

9191
test {
9292
reports.getHtml()
93-
reports.html.destination = file("${projectDir}/../../../TestResults/JavaAzureRuntime")
93+
reports.html.destination = file("$rootDir/TestResults/JavaAzureRuntime")
9494
}
9595

9696
tasks.compileJava.dependsOn 'clean'

build-tools/src/main/resources/checkstyle.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@
231231
-->
232232

233233
<module name="FinalClass"/>
234-
<module name="HideUtilityClassConstructor"/>
235234
<module name="InterfaceIsType"/>
236235
<module name="VisibilityModifier">
237236
<property name="protectedAllowed" value="true"/>

client-runtime/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ version = '1.0.0-SNAPSHOT'
1616

1717
checkstyle {
1818
toolVersion = "6.18"
19-
configFile = new File("$rootDir/ClientRuntimes/Java/build-tools/src/main/resources/checkstyle.xml")
20-
configProperties = [samedir: "$rootDir/ClientRuntimes/Java/build-tools/src/main/resources"]
21-
reportsDir = new File("$rootDir/ClientRuntimes/Java/build-tools/reports")
19+
configFile = new File("$rootDir/src/client/Java/build-tools/src/main/resources/checkstyle.xml")
20+
configProperties = [samedir: "$rootDir/src/client/Java/build-tools/src/main/resources"]
21+
reportsDir = new File("$rootDir/src/client/Java/build-tools/reports")
2222
}
2323

2424
dependencies {
@@ -99,7 +99,7 @@ artifacts {
9999

100100
test {
101101
reports.getHtml()
102-
reports.html.destination = file("${projectDir}/../../../TestResults/JavaRuntime")
102+
reports.html.destination = file("$rootDir/TestResults/JavaRuntime")
103103
}
104104

105105
tasks.compileJava.dependsOn 'clean'
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
*
3+
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*
6+
*/
7+
8+
package com.microsoft.rest;
9+
10+
import com.google.common.io.BaseEncoding;
11+
12+
import java.util.Arrays;
13+
14+
/**
15+
* Simple wrapper over Base64Url encoded byte array used during serialization/deserialization.
16+
*/
17+
public final class Base64Url {
18+
/**
19+
* The Base64Url encoded bytes.
20+
*/
21+
private final byte[] bytes;
22+
23+
/**
24+
* Creates a new Base64Url object with the specified encoded string.
25+
*
26+
* @param string The encoded string.
27+
*/
28+
private Base64Url(String string) {
29+
if (string == null) {
30+
this.bytes = null;
31+
} else {
32+
this.bytes = string.getBytes();
33+
}
34+
}
35+
36+
/**
37+
* Encode a byte array into Base64Url encoded bytes.
38+
*
39+
* @param bytes The byte array to encode.
40+
* @return a Base64Url instance
41+
*/
42+
public static Base64Url encode(byte[] bytes) {
43+
if (bytes == null) {
44+
return new Base64Url(null);
45+
} else {
46+
return new Base64Url(BaseEncoding.base64Url().omitPadding().encode(bytes));
47+
}
48+
}
49+
50+
/**
51+
* Returns the underlying encoded byte array.
52+
*
53+
* @return The underlying encoded byte array.
54+
*/
55+
public byte[] getEncodedBytes() {
56+
return bytes;
57+
}
58+
59+
/**
60+
* Decode the bytes and return.
61+
*
62+
* @return The decoded byte array.
63+
*/
64+
public byte[] getDecodedBytes() {
65+
if (this.bytes == null) {
66+
return null;
67+
}
68+
return BaseEncoding.base64Url().decode(new String(bytes));
69+
}
70+
71+
@Override
72+
public String toString() {
73+
return new String(bytes);
74+
}
75+
76+
@Override
77+
public int hashCode() {
78+
return Arrays.hashCode(bytes);
79+
}
80+
81+
@Override
82+
public boolean equals(Object obj) {
83+
if (obj == null) {
84+
return false;
85+
}
86+
87+
if (!(obj instanceof Base64Url)) {
88+
return false;
89+
}
90+
91+
Base64Url rhs = (Base64Url) obj;
92+
return Arrays.equals(this.bytes, rhs.getEncodedBytes());
93+
}
94+
}

client-runtime/src/main/java/com/microsoft/rest/ServiceClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ protected ServiceClient(String baseUrl) {
4040
/**
4141
* Initializes a new instance of the ServiceClient class.
4242
*
43+
* @param baseUrl the service base uri
44+
* @param clientBuilder the http client builder
45+
* @param restBuilder the retrofit rest client builder
4346
*/
4447
protected ServiceClient(String baseUrl, OkHttpClient.Builder clientBuilder, Retrofit.Builder restBuilder) {
4548
if (clientBuilder == null) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
*
3+
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*
6+
*/
7+
8+
package com.microsoft.rest.serializer;
9+
10+
import com.fasterxml.jackson.core.JsonGenerator;
11+
import com.fasterxml.jackson.databind.JsonSerializer;
12+
import com.fasterxml.jackson.databind.SerializerProvider;
13+
import com.fasterxml.jackson.databind.module.SimpleModule;
14+
import com.microsoft.rest.Base64Url;
15+
16+
import java.io.IOException;
17+
18+
/**
19+
* Custom serializer for serializing {@link Byte[]} objects into Base64 strings.
20+
*/
21+
public class Base64UrlSerializer extends JsonSerializer<Base64Url> {
22+
/**
23+
* Gets a module wrapping this serializer as an adapter for the Jackson
24+
* ObjectMapper.
25+
*
26+
* @return a simple module to be plugged onto Jackson ObjectMapper.
27+
*/
28+
public static SimpleModule getModule() {
29+
SimpleModule module = new SimpleModule();
30+
module.addSerializer(Base64Url.class, new Base64UrlSerializer());
31+
return module;
32+
}
33+
34+
@Override
35+
public void serialize(Base64Url value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
36+
jgen.writeString(value.toString());
37+
}
38+
}

client-runtime/src/main/java/com/microsoft/rest/serializer/JacksonMapperAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ protected void initializeObjectMapper(ObjectMapper mapper) {
5656
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
5757
.registerModule(new JodaModule())
5858
.registerModule(ByteArraySerializer.getModule())
59+
.registerModule(Base64UrlSerializer.getModule())
5960
.registerModule(DateTimeSerializer.getModule())
6061
.registerModule(DateTimeRfc1123Serializer.getModule())
6162
.registerModule(HeadersSerializer.getModule());

0 commit comments

Comments
 (0)