Skip to content

Commit

Permalink
Make sure connection is always closed
Browse files Browse the repository at this point in the history
When an exception is thrown, the connection is currently
not closed, leading to Invalid State exceptions when the
next connection is attempted.  This resolves this issue.

Change-Id: I531881434a73affb1c6536dfbb05bce151c854fb
  • Loading branch information
vakwetu committed Apr 19, 2017
1 parent b9dc595 commit 316e20d
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions base/common/src/com/netscape/certsrv/client/PKIConnection.java
Expand Up @@ -429,23 +429,33 @@ public <T> T createProxy(URI uri, Class<T> clazz) throws URISyntaxException {
}

public <T> T getEntity(Response response, Class<T> clazz) {
Family family = response.getStatusInfo().getFamily();
if (!family.equals(Family.CLIENT_ERROR) && !family.equals(Family.SERVER_ERROR)) {
if (response.hasEntity()) return response.readEntity(clazz);
try {
Family family = response.getStatusInfo().getFamily();
if (!family.equals(Family.CLIENT_ERROR) && !family.equals(Family.SERVER_ERROR)) {
if (response.hasEntity())
return response.readEntity(clazz);
return null;
}
handleErrorResponse(response);
return null;
} finally {
response.close();
}
handleErrorResponse(response);
return null;
}

public <T> T getEntity(Response response, GenericType<T> clazz) {
Family family = response.getStatusInfo().getFamily();
if (!family.equals(Family.CLIENT_ERROR) && !family.equals(Family.SERVER_ERROR)) {
if (response.hasEntity()) return response.readEntity(clazz);
try {
Family family = response.getStatusInfo().getFamily();
if (!family.equals(Family.CLIENT_ERROR) && !family.equals(Family.SERVER_ERROR)) {
if (response.hasEntity())
return response.readEntity(clazz);
return null;
}
handleErrorResponse(response);
return null;
} finally {
response.close();
}
handleErrorResponse(response);
return null;
}

private void handleErrorResponse(Response response) {
Expand Down

0 comments on commit 316e20d

Please sign in to comment.