final EXistResult result;
if(parser.getSendAuth()) {
result = sendOnceWithAuth(uri, request, parser.getCredentials());
} else {
HttpConnection conn = null;
try {
conn = new ApacheHttpConnection(uri);
final EXistResult firstResult = new EXistResult(context);
final HttpResponse response = request.send(firstResult, conn, null);
if(response.getStatus() == 401) {
conn.disconnect();
result = sendOnceWithAuth(uri, request, parser.getCredentials());
} else {
result = firstResult;
registerConnectionWithContext(conn);
}
} catch(final HttpClientException hce) {
if(conn != null) {
try {
conn.disconnect();
} catch(final HttpClientException hcee) {
logger.warn(hcee.getMessage(), hcee);
}
}
throw hce;