Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spotBugsExcludeFilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubu
<Bug code="NP" />
</Match>
<Match>
<Class name="com.microsoft.graph.concurrency.ChunkedUploadRequest" />
<Class name="com.microsoft.graph.tasks.LargeFileUploadRequest" />
<Bug code="Dm" />
</Match>
<Match>
<Class name="com.microsoft.graph.concurrency.ChunkedUploadResponseHandler" />
<Class name="com.microsoft.graph.tasks.LargeFileUploadResponseHandler" />
<Method name="generateResult" />
<Bug code="RCN,NP" />
</Match>
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/microsoft/graph/http/CoreHttpProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,6 @@ private <Result, Body, DeserializeType> Result processResponse(final Response re

// Call being executed


if (handler != null) {
handler.configConnection(response);
}

logger.logDebug(String.format(Locale.ROOT, "Response code %d, %s",
response.code(),
response.message()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import javax.annotation.Nullable;
import javax.annotation.Nonnull;

import okhttp3.Response;

/**
* The handler interface for requests having stateful response from server.
* The handler will custom the HTTP connection if needed and generate request
Expand All @@ -40,26 +38,20 @@
* @param <DeserializedType> the deserialize type for serializer
*/
public interface IStatefulResponseHandler<ResultType, DeserializedType> {
/**
* Configure the response
*
* @param response the HTTP response
*/
void configConnection(@Nonnull final Response response);

/**
* Generate result after receiving response
*
* @param request the HTTP request
* @param response the HTTP connection
* @param serializer the serializer for parsing response
* @param logger the logger
* @param <ResponseType> the native http client response type
* @return the result generated by this handler
* @throws Exception an exception occurs if the request was unable to complete for any reason
*/
@Nullable
ResultType generateResult(@Nonnull final IHttpRequest request,
@Nonnull final Response response,
<ResponseType> ResultType generateResult(@Nonnull final IHttpRequest request,
@Nonnull final ResponseType response,
@Nonnull final ISerializer serializer,
@Nonnull final ILogger logger) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// THE SOFTWARE.
// ------------------------------------------------------------------------------

package com.microsoft.graph.concurrency;
package com.microsoft.graph.tasks;

/**
* A callback that describes how to deal with success, failure, and progress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// THE SOFTWARE.
// ------------------------------------------------------------------------------

package com.microsoft.graph.concurrency;
package com.microsoft.graph.tasks;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

package com.microsoft.graph.concurrency;
package com.microsoft.graph.tasks;

import java.util.List;
import java.util.Locale;
Expand All @@ -21,7 +21,7 @@
* The chunk upload request.
* @param <UploadType> The upload item type.
*/
public class ChunkedUploadRequest<UploadType> {
class LargeFileUploadRequest<UploadType> {

/**
* Content Range header name.
Expand All @@ -41,7 +41,7 @@ public class ChunkedUploadRequest<UploadType> {
/**
* The base request.
*/
private final BaseRequest<ChunkedUploadResult<UploadType>> baseRequest;
private final BaseRequest<LargeFileUploadResponse<UploadType>> baseRequest;

/**
* Construct the ChunkedUploadRequest
Expand All @@ -55,7 +55,7 @@ public class ChunkedUploadRequest<UploadType> {
* @param totalLength The total length of the input stream.
*/
@SuppressWarnings("unchecked")
protected ChunkedUploadRequest(@Nonnull final String requestUrl,
protected LargeFileUploadRequest(@Nonnull final String requestUrl,
@Nonnull final IBaseClient<?> client,
@Nullable final List<? extends Option> options,
@Nonnull final byte[] chunk,
Expand All @@ -67,7 +67,7 @@ protected ChunkedUploadRequest(@Nonnull final String requestUrl,
Objects.requireNonNull(chunk, "parameter chunk cannot be null");
this.data = new byte[chunkSize];
System.arraycopy(chunk, 0, this.data, 0, chunkSize);
this.baseRequest = new BaseRequest<ChunkedUploadResult<UploadType>>(requestUrl, client, options, (Class<? extends ChunkedUploadResult<UploadType>>)(new ChunkedUploadResult<>((UploadType)null)).getClass()) {
this.baseRequest = new BaseRequest<LargeFileUploadResponse<UploadType>>(requestUrl, client, options, (Class<? extends LargeFileUploadResponse<UploadType>>)(new LargeFileUploadResponse<>((UploadType)null)).getClass()) {
};
this.baseRequest.setHttpMethod(HttpMethod.PUT);
this.baseRequest.addHeader(CONTENT_RANGE_HEADER_NAME,
Expand All @@ -86,24 +86,24 @@ protected ChunkedUploadRequest(@Nonnull final String requestUrl,
*/
@SuppressWarnings("unchecked")
@Nonnull
public ChunkedUploadResult<UploadType> upload(
@Nonnull final ChunkedUploadResponseHandler<UploadType> responseHandler) {
public LargeFileUploadResponse<UploadType> upload(
@Nonnull final LargeFileUploadResponseHandler<UploadType> responseHandler) {
Objects.requireNonNull(responseHandler, "parameter responseHandler cannot be null");
ChunkedUploadResult<UploadType> result = null;
LargeFileUploadResponse<UploadType> result = null;

try {
result = this.baseRequest
.getClient()
.getHttpProvider()
.send(baseRequest, (Class<ChunkedUploadResult<UploadType>>)(Class<?>) ChunkedUploadResult.class, this.data, responseHandler);
.send(baseRequest, (Class<LargeFileUploadResponse<UploadType>>)(Class<?>) LargeFileUploadResponse.class, this.data, responseHandler);
} catch (final ClientException e) {
throw new ClientException("Request failed with error, retry if necessary.", e);
}

if (result != null && result.chunkCompleted()) {
return result;
} else
return new ChunkedUploadResult<UploadType>(
return new LargeFileUploadResponse<UploadType>(
new ClientException("Upload session failed.", result == null ? null : result.getError()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

package com.microsoft.graph.concurrency;
package com.microsoft.graph.tasks;

import com.microsoft.graph.core.ClientException;
import com.microsoft.graph.http.GraphServiceException;
Expand All @@ -16,7 +16,11 @@
/**
* Wrapper class for different upload response from server.
*/
public class ChunkedUploadResult<UploadType> {
class LargeFileUploadResponse<UploadType> {
/**
* The location header from the response if provided
*/
private final String location;
/**
* The uploaded item response.
*/
Expand All @@ -33,54 +37,69 @@ public class ChunkedUploadResult<UploadType> {
private final ClientException error;

/**
* Construct result with item created.
* Constructs response with the location header.
*
* @param location The location returned by the response
*/
protected LargeFileUploadResponse(@Nullable final String location) {
this.location = location;
this.error = null;
this.session = null;
this.uploadedItem = null;
}

/**
* Construct response with item created.
*
* @param uploaded The created item.
*/
protected ChunkedUploadResult(@Nullable final UploadType uploaded) {
protected LargeFileUploadResponse(@Nullable final UploadType uploaded) {
this.uploadedItem = uploaded;
this.session = null;
this.error = null;
this.location = null;
}

/**
* Construct result with next session.
* Construct response with next session.
*
* @param session The next session.
*/
protected ChunkedUploadResult(@Nullable final IUploadSession session) {
protected LargeFileUploadResponse(@Nullable final IUploadSession session) {
this.session = session;
this.uploadedItem = null;
this.error = null;
this.location = null;
}

/**
* Construct result with error.
* Construct response with error.
*
* @param error The error occurred during uploading.
*/
protected ChunkedUploadResult(@Nullable final ClientException error) {
protected LargeFileUploadResponse(@Nullable final ClientException error) {
this.error = error;
this.uploadedItem = null;
this.session = null;
this.location = null;
}

/**
* Construct result with server exception.
* Construct response with server exception.
*
* @param exception The exception received from server.
*/
protected ChunkedUploadResult(@Nonnull final GraphServiceException exception) {
protected LargeFileUploadResponse(@Nonnull final GraphServiceException exception) {
this(new ClientException(Objects
.requireNonNull(exception, "parameter exception cannot be null")
.getMessage(/* verbose */ true),
exception));
}

/**
* Checks the chunk upload is completed.
* Checks the large upload range is completed.
*
* @return true if current chunk upload is completed.
* @return true if current large upload range is completed.
*/
public boolean chunkCompleted() {
return this.uploadedItem != null || this.session != null;
Expand All @@ -92,7 +111,7 @@ public boolean chunkCompleted() {
* @return true if the response is an item.
*/
public boolean uploadCompleted() {
return this.uploadedItem != null;
return this.uploadedItem != null || this.location != null;
}

/**
Expand Down Expand Up @@ -133,4 +152,12 @@ public IUploadSession getSession() {
public ClientException getError() {
return this.error;
}
/**
* Get the location.
* @return The location.
*/
@Nullable
public String getLocation () {
return this.location;
}
}
Loading