Search in sources :

Example 1 with HttpURLConnectionBuilder

use of org.ovirt.engine.core.uutils.net.HttpURLConnectionBuilder in project ovirt-engine by oVirt.

the class TransferImageCommand method getProxyConnection.

private HttpURLConnection getProxyConnection(String url) {
    try {
        HttpURLConnectionBuilder builder = new HttpURLConnectionBuilder().setURL(url);
        // Set SSL details
        builder.setTrustStore(EngineLocalConfig.getInstance().getPKITrustStore().getAbsolutePath()).setTrustStorePassword(EngineLocalConfig.getInstance().getPKITrustStorePassword()).setTrustStoreType(EngineLocalConfig.getInstance().getPKITrustStoreType()).setHttpsProtocol(Config.getValue(ConfigValues.ExternalCommunicationProtocol));
        HttpURLConnection connection = builder.create();
        connection.setDoOutput(true);
        return connection;
    } catch (Exception ex) {
        throw new RuntimeException(String.format("Failed to communicate with ovirt-imageio-proxy: %s", ex.getMessage()));
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HttpURLConnectionBuilder(org.ovirt.engine.core.uutils.net.HttpURLConnectionBuilder) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 2 with HttpURLConnectionBuilder

use of org.ovirt.engine.core.uutils.net.HttpURLConnectionBuilder in project ovirt-engine by oVirt.

the class BaseProviderProxy method createConnection.

protected HttpURLConnection createConnection(String relativePath) {
    URL hostUrl = getUrl();
    HttpURLConnectionBuilder builder;
    HttpURLConnection result;
    try {
        builder = new HttpURLConnectionBuilder().appendRelativePath(hostUrl, relativePath);
        if (new File(EngineLocalConfig.getInstance().getExternalProvidersTrustStore().getAbsolutePath()).exists()) {
            builder.setTrustStore(EngineLocalConfig.getInstance().getExternalProvidersTrustStore().getAbsolutePath()).setTrustStorePassword(EngineLocalConfig.getInstance().getExternalProvidersTrustStorePassword()).setTrustStoreType(EngineLocalConfig.getInstance().getExternalProvidersTrustStoreType()).setHttpsProtocol(Config.getValue(ConfigValues.ExternalCommunicationProtocol));
        }
        result = builder.create();
        handleCredentials(result);
    } catch (Exception ex) {
        log.error("Cannot communicate with provider", ex);
        throw new EngineException(EngineError.PROVIDER_FAILURE);
    }
    return result;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HttpURLConnectionBuilder(org.ovirt.engine.core.uutils.net.HttpURLConnectionBuilder) EngineException(org.ovirt.engine.core.common.errors.EngineException) File(java.io.File) URL(java.net.URL) EngineException(org.ovirt.engine.core.common.errors.EngineException) GeneralSecurityException(java.security.GeneralSecurityException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SSLException(javax.net.ssl.SSLException)

Aggregations

HttpURLConnection (java.net.HttpURLConnection)2 EngineException (org.ovirt.engine.core.common.errors.EngineException)2 HttpURLConnectionBuilder (org.ovirt.engine.core.uutils.net.HttpURLConnectionBuilder)2 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 GeneralSecurityException (java.security.GeneralSecurityException)1 SSLException (javax.net.ssl.SSLException)1