Skip to content

Commit 3f64dd8

Browse files
author
Caitlin Bales (MSFT)
authored
Merge branch 'master' into custom-request-fixes
2 parents 6ebf1d1 + e872cb3 commit 3f64dd8

File tree

546 files changed

+1071
-1815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

546 files changed

+1071
-1815
lines changed

src/main/java/com/microsoft/graph/concurrency/ChunkedUploadProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void upload(final List<Option> options,
177177
ChunkedUploadRequest request =
178178
new ChunkedUploadRequest(this.uploadUrl, this.client, options, buffer, read,
179179
maxRetry, this.readSoFar, this.streamSize);
180-
ChunkedUploadResult result = request.upload(this.responseHandler);
180+
ChunkedUploadResult<UploadType> result = request.upload(this.responseHandler);
181181

182182
if (result.uploadCompleted()) {
183183
callback.progress(this.streamSize, this.streamSize);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void configConnection(final IConnection connection) {
7878
* @throws Exception An exception occurs if the request was unable to complete for any reason.
7979
*/
8080
@Override
81-
public ChunkedUploadResult generateResult(
81+
public ChunkedUploadResult<UploadType> generateResult(
8282
final IHttpRequest request,
8383
final IConnection connection,
8484
final ISerializer serializer,
@@ -89,10 +89,10 @@ public ChunkedUploadResult generateResult(
8989
if (connection.getResponseCode() == HttpResponseCode.HTTP_ACCEPTED) {
9090
logger.logDebug("Chunk bytes has been accepted by the server.");
9191
in = new BufferedInputStream(connection.getInputStream());
92-
final UploadSession seesion = serializer.deserializeObject(
92+
final UploadSession session = serializer.deserializeObject(
9393
DefaultHttpProvider.streamToString(in), UploadSession.class);
9494

95-
return new ChunkedUploadResult(seesion);
95+
return new ChunkedUploadResult<UploadType>(session);
9696

9797
} else if (connection.getResponseCode() == HttpResponseCode.HTTP_CREATED
9898
|| connection.getResponseCode() == HttpResponseCode.HTTP_OK) {
@@ -102,11 +102,11 @@ public ChunkedUploadResult generateResult(
102102
UploadType uploadedItem = serializer.deserializeObject(rawJson,
103103
this.deserializeTypeClass);
104104

105-
return new ChunkedUploadResult(uploadedItem);
105+
return new ChunkedUploadResult<UploadType>(uploadedItem);
106106
} else if (connection.getResponseCode() >= HttpResponseCode.HTTP_CLIENT_ERROR) {
107107
logger.logDebug("Receiving error during upload, see detail on result error");
108108

109-
return new ChunkedUploadResult(
109+
return new ChunkedUploadResult<UploadType>(
110110
GraphServiceException.createFromConnection(request, null, serializer,
111111
connection, logger));
112112
}

src/main/java/com/microsoft/graph/concurrency/SimpleWaiter.java

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

src/main/java/com/microsoft/graph/core/BaseActionRequestBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ protected boolean hasParameter(final String name) {
5353
* @param <T> The type to which this object should be cast
5454
* @return The stored instance of T, otherwise null
5555
*/
56+
@SuppressWarnings("unchecked")
5657
protected <T> T getParameter(final String name) {
5758
return (T) bodyParams.get(name);
5859
}

src/main/java/com/microsoft/graph/core/ClientException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
public class ClientException extends RuntimeException {
2929

30+
private static final long serialVersionUID = -1066560879567392559L;
31+
3032
/**
3133
* Creates the client exception.
3234
* @param message The message to display.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public abstract class BaseRequest implements IHttpRequest {
107107
public BaseRequest(final String requestUrl,
108108
final IBaseClient client,
109109
final List<? extends Option> options,
110-
final Class responseClass) {
110+
final Class<?> responseClass) {
111111
this.requestUrl = requestUrl;
112112
this.client = client;
113113
this.responseClass = responseClass;
@@ -349,7 +349,8 @@ public IBaseClient getClient() {
349349
*
350350
* @return The response type.
351351
*/
352-
public Class getResponseType() {
353-
return responseClass;
352+
@SuppressWarnings("unchecked")
353+
public <T> Class<T> getResponseType() {
354+
return (Class<T>) responseClass;
354355
}
355356
}

src/main/java/com/microsoft/graph/http/BaseRequestBuilder.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public abstract class BaseRequestBuilder implements IRequestBuilder {
5050
*/
5151
private final List<Option> options = new ArrayList<>();
5252

53-
private final IJsonBackedObject body;
54-
5553
/**
5654
* Creates the request builder.
5755
*
@@ -66,23 +64,6 @@ public BaseRequestBuilder(
6664
) {
6765
this.requestUrl = requestUrl;
6866
this.client = client;
69-
this.body = null;
70-
71-
if (options != null) {
72-
this.options.addAll(options);
73-
}
74-
}
75-
76-
public BaseRequestBuilder(
77-
final String requestUrl,
78-
final IJsonBackedObject body,
79-
final IBaseClient client,
80-
final List<? extends Option> options
81-
) {
82-
this.requestUrl = requestUrl;
83-
this.client = client;
84-
this.body = body;
85-
8667
if (options != null) {
8768
this.options.addAll(options);
8869
}

src/main/java/com/microsoft/graph/http/CustomRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ public void patch(final ICallback<T> callback) {
7373
}
7474

7575
/**
76-
* Patches this with a source
76+
* Patches this item with a source
7777
* @param sourceAttachment The source object with updates
78-
* @return The updated Attachment
78+
* @return The updated item
7979
* @throws ClientException This exception occurs if the request was unable to complete for any reason.
8080
*/
8181
public T patch(final T sourceObject) throws ClientException {

src/main/java/com/microsoft/graph/http/DefaultHttpProvider.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ private <Result, Body, DeserializeType> Result sendRequestInternal(final IHttpRe
212212
final IStatefulResponseHandler<Result, DeserializeType> handler)
213213
throws ClientException {
214214
final int defaultBufferSize = 4096;
215-
final String contentLengthHeaderName = "Content-Length";
216215
final String binaryContentType = "application/octet-stream";
217216

218217
try {
@@ -234,7 +233,14 @@ private <Result, Body, DeserializeType> Result sendRequestInternal(final IHttpRe
234233
final byte[] bytesToWrite;
235234
connection.addRequestHeader("Accept", "*/*");
236235
if (serializable == null) {
237-
bytesToWrite = null;
236+
// Send an empty body through with a POST request
237+
// This ensures that the Content-Length header is properly set
238+
if (request.getHttpMethod() == HttpMethod.POST) {
239+
bytesToWrite = new byte[0];
240+
}
241+
else {
242+
bytesToWrite = null;
243+
}
238244
} else if (serializable instanceof byte[]) {
239245
logger.logDebug("Sending byte[] as request body");
240246
bytesToWrite = (byte[]) serializable;
@@ -419,8 +425,14 @@ void setConnectionFactory(final IConnectionFactory factory) {
419425
public static String streamToString(final InputStream input) {
420426
final String httpStreamEncoding = "UTF-8";
421427
final String endOfFile = "\\A";
422-
final Scanner scanner = new Scanner(input, httpStreamEncoding).useDelimiter(endOfFile);
423-
return scanner.next();
428+
final Scanner scanner = new Scanner(input, httpStreamEncoding);
429+
try {
430+
scanner.useDelimiter(endOfFile);
431+
String scannerString = scanner.next();
432+
return scannerString;
433+
} finally {
434+
scanner.close();
435+
}
424436
}
425437

426438
/**

src/main/java/com/microsoft/graph/http/GraphFatalServiceException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030
public class GraphFatalServiceException extends GraphServiceException {
3131

32+
private static final long serialVersionUID = -4974392424026672738L;
33+
3234
/**
3335
* Create a fatal Graph service exception.
3436
* @param method The method that caused the exception.

0 commit comments

Comments
 (0)