Skip to content

Commit

Permalink
Release lock before executing request
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsocha2 committed Nov 6, 2024
1 parent 48c2ae4 commit b4dbd28
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/main/java/com/box/sdk/BoxAPIRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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) {
Expand Down

0 comments on commit b4dbd28

Please sign in to comment.