Skip to content

Commit 04f9d5b

Browse files
committed
Merge branch 'feature/v2' into feature/lean-batches
2 parents 2cc9445 + 88d721a commit 04f9d5b

10 files changed

Lines changed: 156 additions & 242 deletions

File tree

‎gradle/dependencies.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dependencies {
44
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
55
testImplementation 'org.mockito:mockito-inline:3.7.7'
66

7-
api 'com.squareup.okhttp3:okhttp:4.9.0'
7+
api 'com.squareup.okhttp3:okhttp:4.9.1'
88

99
implementation 'com.google.guava:guava:30.1-jre'
1010

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<dependency>
2626
<groupId>com.squareup.okhttp3</groupId>
2727
<artifactId>gson</artifactId>
28-
<version>4.9.0</version>
28+
<version>4.9.1</version>
2929
</dependency>
3030
<dependency>
3131
<groupId>com.azure</groupId>

‎src/main/java/com/microsoft/graph/Util.java‎

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎src/main/java/com/microsoft/graph/concurrency/ChunkedUploadResponseHandler.java‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
import com.google.common.io.ByteStreams;
2626

2727
import com.microsoft.graph.core.ClientException;
28-
import com.microsoft.graph.core.Constants;
2928
import com.microsoft.graph.http.GraphServiceException;
3029
import com.microsoft.graph.http.HttpResponseCode;
31-
import com.microsoft.graph.http.HttpResponseHeadersHelper;
3230
import com.microsoft.graph.http.IHttpRequest;
3331
import com.microsoft.graph.http.IStatefulResponseHandler;
3432
import com.microsoft.graph.logger.ILogger;
@@ -37,12 +35,12 @@
3735
import java.io.ByteArrayInputStream;
3836
import java.io.IOException;
3937
import java.io.InputStream;
40-
import java.util.Map;
4138

4239
import javax.annotation.Nonnull;
4340
import javax.annotation.Nullable;
4441

4542
import okhttp3.Response;
43+
import okhttp3.ResponseBody;
4644

4745
import static com.microsoft.graph.http.HttpResponseCode.HTTP_OK;
4846

@@ -53,8 +51,6 @@
5351
*/
5452
public class ChunkedUploadResponseHandler<UploadType>
5553
implements IStatefulResponseHandler<ChunkedUploadResult<UploadType>, UploadType> {
56-
57-
private final static HttpResponseHeadersHelper responseHeadersHelper = new HttpResponseHeadersHelper();
5854
/**
5955
* The expected deserialized upload type
6056
*/
@@ -107,25 +103,24 @@ public ChunkedUploadResult<UploadType> generateResult(
107103
response, logger));
108104
} else if (response.code() >= HTTP_OK
109105
&& response.code() < HttpResponseCode.HTTP_MULTIPLE_CHOICES) {
110-
final Map<String, String> headers = responseHeadersHelper.getResponseHeadersAsMapStringString(response);
111-
final String contentType = headers.get(Constants.CONTENT_TYPE_HEADER_NAME);
112-
final String location = headers.get("Location");
113-
if (contentType != null
114-
&& contentType.contains(Constants.JSON_CONTENT_TYPE)) {
115-
return parseJsonUploadResult(response, serializer, logger);
116-
} else if (location != null) {
117-
logger.logDebug("Upload session is completed (Outlook), uploaded item returned.");
118-
return new ChunkedUploadResult<>(this.deserializeTypeClass.getDeclaredConstructor().newInstance());
119-
} else {
120-
logger.logDebug("Upload session returned an unexpected response");
121-
}
106+
try(final ResponseBody body = response.body()) {
107+
final String location = response.headers().get("Location");
108+
if (body.contentType() != null && body.contentType().subtype().contains("json")) {
109+
return parseJsonUploadResult(body, serializer, logger);
110+
} else if (location != null) {
111+
logger.logDebug("Upload session is completed (Outlook), uploaded item returned.");
112+
return new ChunkedUploadResult<>(this.deserializeTypeClass.getDeclaredConstructor().newInstance());
113+
} else {
114+
logger.logDebug("Upload session returned an unexpected response");
115+
}
116+
}
122117
}
123118
return new ChunkedUploadResult<>(new ClientException("Received an unexpected response from the service, response code: " + response.code(), null));
124119
}
125120

126121
@Nonnull
127-
private ChunkedUploadResult<UploadType> parseJsonUploadResult(@Nonnull Response response, @Nonnull ISerializer serializer, @Nonnull ILogger logger) throws IOException {
128-
try (final InputStream in = response.body().byteStream()) {
122+
private ChunkedUploadResult<UploadType> parseJsonUploadResult(@Nonnull final ResponseBody responseBody, @Nonnull final ISerializer serializer, @Nonnull final ILogger logger) throws IOException {
123+
try (final InputStream in = responseBody.byteStream()) {
129124
final byte[] responseBytes = ByteStreams.toByteArray(in);
130125
final IUploadSession session = serializer.deserializeObject(new ByteArrayInputStream(responseBytes), uploadSessionClass);
131126

‎src/main/java/com/microsoft/graph/core/Constants.java‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎src/main/java/com/microsoft/graph/http/BaseRequest.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@
3434
import com.microsoft.graph.options.FunctionOption;
3535
import com.microsoft.graph.options.QueryOption;
3636
import com.microsoft.graph.core.ClientException;
37-
import com.microsoft.graph.core.Constants;
3837
import com.microsoft.graph.options.HeaderOption;
3938
import com.microsoft.graph.options.Option;
4039

41-
import java.lang.reflect.Field;
4240
import java.net.MalformedURLException;
4341
import java.net.URL;
4442
import java.util.ArrayList;

0 commit comments

Comments
 (0)