private Response execute(final HttpRequestBase method) throws IOException {
try {
method.setHeader(Constants.X_AUTH_TOKEN, authenticationResponse.getAuthToken());
try {
return new DefaultResponseHandler().handleResponse(client.execute(method));
}
catch(AuthorizationException e) {
method.abort();
// Re-authenticate with previous authentication request
authenticationResponse = this.authenticate(authenticationRequest);
method.reset();
// Add new auth token retrieved
method.setHeader(Constants.X_AUTH_TOKEN, authenticationResponse.getAuthToken());
// Retry
return new DefaultResponseHandler().handleResponse(client.execute(method));
}
}
catch(IOException e) {
// In case of an IOException the connection will be released back to the connection manager automatically
method.abort();