diff --git a/src/main/java/com/box/sdk/BoxAPIRequest.java b/src/main/java/com/box/sdk/BoxAPIRequest.java index 1d1d91a97..4ea97a00e 100644 --- a/src/main/java/com/box/sdk/BoxAPIRequest.java +++ b/src/main/java/com/box/sdk/BoxAPIRequest.java @@ -585,9 +585,27 @@ private BoxAPIResponse trySend(ProgressListener listener) { } } } + long start = System.currentTimeMillis(); + Request request = composeRequest(listener); + Response response; + if (this.followRedirects) { + response = api.execute(request); + } else { + response = api.executeWithoutRedirect(request); + } + logDebug(format("[trySend] connection.connect() took %dms%n", (System.currentTimeMillis() - start))); - Request.Builder requestBuilder = new Request.Builder().url(getUrl()); + BoxAPIResponse result = BoxAPIResponse.toBoxResponse(response); + this.logRequest(); + long getResponseStart = System.currentTimeMillis(); + logDebug(format( + "[trySend] Get Response (read network) took %dms%n", System.currentTimeMillis() - getResponseStart + )); + return result; + } + private Request composeRequest(ProgressListener listener) { + Request.Builder requestBuilder = new Request.Builder().url(getUrl()); if (this.shouldAuthenticate) { requestBuilder.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + this.api.lockAccessToken()); } @@ -608,31 +626,14 @@ private BoxAPIResponse trySend(ProgressListener listener) { requestBuilder.addHeader("BoxApi", boxAPIValue); } - long start = System.currentTimeMillis(); - writeMethodWithBody(requestBuilder, listener); - Request request = requestBuilder.build(); - Response response; - if (this.followRedirects) { - response = api.execute(request); - } else { - response = api.executeWithoutRedirect(request); - } - logDebug(format("[trySend] connection.connect() took %dms%n", (System.currentTimeMillis() - start))); - - BoxAPIResponse result = BoxAPIResponse.toBoxResponse(response); - this.logRequest(); - long getResponseStart = System.currentTimeMillis(); - logDebug(format( - "[trySend] Get Response (read network) took %dms%n", System.currentTimeMillis() - getResponseStart - )); - return result; + writeMethodWithBody(requestBuilder, listener); + return requestBuilder.build(); } finally { if (this.shouldAuthenticate) { this.api.unlockAccessToken(); } } - } protected void writeMethodWithBody(Request.Builder requestBuilder, ProgressListener listener) {