use of com.microsoft.azure.storage.SendingRequestEvent in project cyberduck by iterate-ch.
the class AzureSession method connect.
@Override
protected CloudBlobClient connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
try {
final StorageCredentials credentials;
if (host.getCredentials().isTokenAuthentication()) {
credentials = new StorageCredentialsSharedAccessSignature(host.getCredentials().getToken());
} else {
credentials = new StorageCredentialsAccountAndKey(host.getCredentials().getUsername(), "null");
}
// Client configured with no credentials
final URI uri = new URI(String.format("%s://%s", Scheme.https, host.getHostname()));
final CloudBlobClient client = new CloudBlobClient(uri, credentials);
client.setDirectoryDelimiter(String.valueOf(Path.DELIMITER));
context.setLoggingEnabled(true);
context.setLogger(LoggerFactory.getLogger(log.getName()));
context.setUserHeaders(new HashMap<>(Collections.singletonMap(HttpHeaders.USER_AGENT, new PreferencesUseragentProvider().get())));
context.getSendingRequestEventHandler().addListener(listener = new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(final SendingRequestEvent event) {
if (event.getConnectionObject() instanceof HttpsURLConnection) {
final HttpsURLConnection connection = (HttpsURLConnection) event.getConnectionObject();
connection.setSSLSocketFactory(new CustomTrustSSLProtocolSocketFactory(trust, key));
connection.setHostnameVerifier(new DisabledX509HostnameVerifier());
}
}
});
switch(proxy.getType()) {
case SOCKS:
{
if (log.isInfoEnabled()) {
log.info(String.format("Configured to use SOCKS proxy %s", proxy));
}
final java.net.Proxy socksProxy = new java.net.Proxy(java.net.Proxy.Type.SOCKS, new InetSocketAddress(proxy.getHostname(), proxy.getPort()));
context.setProxy(socksProxy);
break;
}
case HTTP:
case HTTPS:
{
if (log.isInfoEnabled()) {
log.info(String.format("Configured to use HTTP proxy %s", proxy));
}
final java.net.Proxy httpProxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostname(), proxy.getPort()));
context.setProxy(httpProxy);
break;
}
}
return client;
} catch (URISyntaxException e) {
throw new LoginFailureException(e.getMessage(), e);
}
}
Aggregations