if ("".equals(path) || path == null) {
path = "/";
}
// 1. prompt for ssl client cert if needed, if cancelled - throw cancellation exception.
ISVNSSLManager sslManager = mySSLManager != null ? mySSLManager : promptSSLClientCertificate(true, false);
String sslRealm = "<" + myHost.getProtocol() + "://" + myHost.getHost() + ":" + myHost.getPort() + ">";
SVNAuthentication httpAuth = myLastValidAuth;
boolean isAuthForced = myRepository.getAuthenticationManager() != null ? myRepository.getAuthenticationManager().isAuthenticationForced() : false;
if (httpAuth == null && isAuthForced) {
httpAuth = myRepository.getAuthenticationManager().getFirstAuthentication(ISVNAuthenticationManager.PASSWORD, sslRealm, null);
myChallengeCredentials = new HTTPBasicAuthentication((SVNPasswordAuthentication)httpAuth, myCharset);
}
String realm = null;
// 2. create request instance.
HTTPRequest request = new HTTPRequest(myCharset);
request.setConnection(this);
request.setKeepAlive(true);
request.setRequestBody(body);
request.setResponseHandler(handler);
request.setResponseStream(dst);
SVNErrorMessage err = null;
while (true) {
HTTPStatus status = null;
try {
err = null;
connect(sslManager);
request.reset();
request.setProxied(myIsProxied);
request.setSecured(myIsSecured);
if (myProxyAuthentication != null) {
request.initCredentials(myProxyAuthentication, method, path);
request.setProxyAuthentication(myProxyAuthentication.authenticate());
}
if (httpAuth != null && myChallengeCredentials != null) {
request.initCredentials(myChallengeCredentials, method, path);
String authResponse = myChallengeCredentials.authenticate();
request.setAuthentication(authResponse);
}
request.dispatch(method, path, header, ok1, ok2, context);
status = request.getStatus();
} catch (SSLHandshakeException ssl) {
myRepository.getDebugLog().info(ssl);
if (ssl.getCause() instanceof CertificateException &&
ssl.getCause().getCause() instanceof SVNCancelException) {
SVNErrorManager.cancel(ssl.getCause().getCause().getMessage());
}
if (sslManager != null) {
close();
SVNSSLAuthentication sslAuth = sslManager.getClientAuthentication();
if (sslAuth != null) {
SVNErrorMessage sslErr = SVNErrorMessage.create(SVNErrorCode.RA_NOT_AUTHORIZED, "SSL handshake failed: ''{0}''", ssl.getMessage());
myRepository.getAuthenticationManager().acknowledgeAuthentication(false, ISVNAuthenticationManager.SSL, sslRealm, sslErr, sslAuth);
}
sslManager = promptSSLClientCertificate(sslAuth == null, true);
continue;
}
err = SVNErrorMessage.create(SVNErrorCode.RA_DAV_REQUEST_FAILED, ssl);
} catch (UnknownHostException ioe) {
myRepository.getDebugLog().info(ioe);
err = SVNErrorMessage.create(SVNErrorCode.RA_DAV_REQUEST_FAILED, ioe);
} catch (SocketTimeoutException timeout) {
myRepository.getDebugLog().info(timeout);
err = SVNErrorMessage.create(SVNErrorCode.RA_DAV_REQUEST_FAILED, "timed out waiting for server");
} catch (SVNCancellableOutputStream.IOCancelException cancel) {
myRepository.getDebugLog().info(cancel);
SVNErrorManager.cancel(cancel.getMessage());
} catch (IOException e) {
myRepository.getDebugLog().info(e);
if (sslManager != null) {
close();
SVNSSLAuthentication sslAuth = sslManager.getClientAuthentication();
if (sslAuth != null) {
SVNErrorMessage sslErr = SVNErrorMessage.create(SVNErrorCode.RA_NOT_AUTHORIZED, "SSL handshake failed: ''{0}''", e.getMessage());
myRepository.getAuthenticationManager().acknowledgeAuthentication(false, ISVNAuthenticationManager.SSL, sslRealm, sslErr, sslAuth);
}
sslManager = promptSSLClientCertificate(sslAuth == null, true);
continue;
}
err = SVNErrorMessage.create(SVNErrorCode.RA_DAV_REQUEST_FAILED, e.getMessage());
} catch (SVNException e) {
myRepository.getDebugLog().info(e);
// force connection close on SVNException
// (could be thrown by user's auth manager methods).
close();
throw e;
} finally {
finishResponse(request);
}
if (err != null) {
close();
if (sslManager != null) {
sslManager.acknowledgeSSLContext(false, err);
}
break;
}
if (sslManager != null) {
sslManager.acknowledgeSSLContext(true, null);
SVNSSLAuthentication sslAuth = sslManager.getClientAuthentication();
if (sslAuth != null) {
mySSLManager = sslManager;
myRepository.getAuthenticationManager().acknowledgeAuthentication(true, ISVNAuthenticationManager.SSL, sslRealm, null, sslAuth);
}
}