Skip to content

KNOX-3138 implemented try-with-resources for Closeables #1033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ private long calculateSleepTime(long lowerBound, long upperBound) {
private String acquireKnoxToken(KnoxSession knoxSession) throws IOException {
LOG.acquireKnoxToken();
long getStart = System.currentTimeMillis();
final Get.Response getTokenResponse = Token.get(knoxSession).now();
final long getResponseTime = System.currentTimeMillis() - getStart;
LOG.acquiredKnoxToken();
responseTimeCache.saveAcquireResponseTime(getResponseTime);
final Map<String, String> tokenAsMap = JsonUtils.getMapFromJsonString(getTokenResponse.getString());
return tokenAsMap.get("access_token");
try (Get.Response getTokenResponse = Token.get(knoxSession).now()) {
final long getResponseTime = System.currentTimeMillis() - getStart;
LOG.acquiredKnoxToken();
responseTimeCache.saveAcquireResponseTime(getResponseTime);
final Map<String, String> tokenAsMap = JsonUtils.getMapFromJsonString(getTokenResponse.getString());
return tokenAsMap.get("access_token");
}
}

private void renewKnoxToken(KnoxSession knoxSession) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,8 @@ public void execute() throws Exception {
String username = credentials.get("user").string();
String pass = credentials.get("pass").string();

KnoxSession session = null;
Get.Response response;
try {
session = KnoxSession.login(gateway, username, pass);

response = Token.get( session ).now();
try (KnoxSession session = KnoxSession.login(gateway, username, pass);
Get.Response response = Token.get( session ).now()) {
String text = response.getString();
Map<String, String> json = JsonUtils.getMapFromJsonString(text);

Expand Down Expand Up @@ -248,9 +244,6 @@ public void execute() throws Exception {
}
System.out.println(message);
}
if ( session != null ) {
session.shutdown();
}
}

@Override
Expand Down