Search in sources :

Example 11 with HttpConfigurable

use of com.intellij.util.net.HttpConfigurable in project intellij-community by JetBrains.

the class EduStepicClient method getBuilder.

@NotNull
static HttpClientBuilder getBuilder() {
    final HttpClientBuilder builder = HttpClients.custom().setSSLContext(CertificateManager.getInstance().getSslContext()).setMaxConnPerRoute(100000).setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);
    final HttpConfigurable proxyConfigurable = HttpConfigurable.getInstance();
    final List<Proxy> proxies = proxyConfigurable.getOnlyBySettingsSelector().select(URI.create(EduStepicNames.STEPIC_URL));
    final InetSocketAddress address = proxies.size() > 0 ? (InetSocketAddress) proxies.get(0).address() : null;
    if (address != null) {
        builder.setProxy(new HttpHost(address.getHostName(), address.getPort()));
    }
    final ConfirmingTrustManager trustManager = CertificateManager.getInstance().getTrustManager();
    try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, new TrustManager[] { trustManager }, new SecureRandom());
        builder.setSSLContext(sslContext);
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        LOG.error(e.getMessage());
    }
    return builder;
}
Also used : Proxy(java.net.Proxy) ConfirmingTrustManager(com.intellij.util.net.ssl.ConfirmingTrustManager) HttpConfigurable(com.intellij.util.net.HttpConfigurable) InetSocketAddress(java.net.InetSocketAddress) HttpHost(org.apache.http.HttpHost) SecureRandom(java.security.SecureRandom) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with HttpConfigurable

use of com.intellij.util.net.HttpConfigurable in project android by JetBrains.

the class HttpProxySettingsCleanUpTask method doCleanUp.

@Override
void doCleanUp(@NotNull Project project) {
    HttpConfigurable ideHttpProxySettings = HttpConfigurable.getInstance();
    if (!ideHttpProxySettings.USE_HTTP_PROXY || isEmpty(ideHttpProxySettings.PROXY_HOST)) {
        return;
    }
    GradleProperties properties;
    try {
        properties = new GradleProperties(project);
    } catch (IOException e) {
        getLogger().info("Failed to read gradle.properties file", e);
        // Let sync continue, even though it may fail.
        return;
    }
    ProxySettings gradleProxySettings = properties.getHttpProxySettings();
    ProxySettings ideProxySettings = new ProxySettings(ideHttpProxySettings);
    if (!ideProxySettings.equals(gradleProxySettings)) {
        ProxySettingsDialog dialog = new ProxySettingsDialog(project, ideProxySettings);
        if (dialog.showAndGet()) {
            dialog.applyProxySettings(properties.getProperties());
            try {
                properties.save();
            } catch (IOException e) {
                Throwable root = getRootCause(e);
                String cause = root.getMessage();
                String errMsg = "Failed to save HTTP proxy settings to gradle.properties file.";
                if (isNotEmpty(cause)) {
                    if (!cause.endsWith(".")) {
                        cause += ".";
                    }
                    errMsg += String.format("\nCause: %1$s", cause);
                }
                AndroidGradleNotification notification = AndroidGradleNotification.getInstance(project);
                notification.showBalloon("Proxy Settings", errMsg, ERROR);
                getLogger().info("Failed to save changes to gradle.properties file", root);
            }
        }
    }
}
Also used : HttpConfigurable(com.intellij.util.net.HttpConfigurable) GradleProperties(com.android.tools.idea.gradle.util.GradleProperties) ProxySettings(com.android.tools.idea.gradle.util.ProxySettings) AndroidGradleNotification(com.android.tools.idea.gradle.project.AndroidGradleNotification) IOException(java.io.IOException) ProxySettingsDialog(com.android.tools.idea.gradle.project.ProxySettingsDialog)

Example 13 with HttpConfigurable

use of com.intellij.util.net.HttpConfigurable in project android by JetBrains.

the class GradlePreSyncTest method testDoNotShowProxySettingDialog.

@Test
public void testDoNotShowProxySettingDialog() throws IOException {
    guiTest.importSimpleApplication();
    PropertiesComponent.getInstance(guiTest.ideFrame().getProject()).setValue("show.do.not.copy.http.proxy.settings.to.gradle", "true");
    File gradlePropertiesPath = new File(guiTest.ideFrame().getProjectPath(), "gradle.properties");
    createIfNotExists(gradlePropertiesPath);
    HttpConfigurable ideSettings = HttpConfigurable.getInstance();
    ideSettings.USE_HTTP_PROXY = true;
    ideSettings.PROXY_HOST = "myproxy.test.com";
    ideSettings.PROXY_PORT = 443;
    guiTest.ideFrame().requestProjectSync();
    ProxySettingsDialogFixture proxySettingsDialog = ProxySettingsDialogFixture.find(guiTest.robot());
    proxySettingsDialog.setDoNotShowThisDialog(true);
    proxySettingsDialog.clickOk();
    guiTest.ideFrame().waitForGradleProjectSyncToStart().waitForGradleProjectSyncToFinish();
    // Force a change on the proxy, otherwise the project sync may be ignored.
    ideSettings.PROXY_HOST = "myproxy2.test.com";
    // Verifies that the "Do not show this dialog in the future" does not show up. If it does show up the test will timeout and fail.
    guiTest.ideFrame().requestProjectSync().waitForGradleProjectSyncToFinish();
}
Also used : HttpConfigurable(com.intellij.util.net.HttpConfigurable) ProxySettingsDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.ProxySettingsDialogFixture) File(java.io.File) Test(org.junit.Test)

Example 14 with HttpConfigurable

use of com.intellij.util.net.HttpConfigurable in project android by JetBrains.

the class GuiTests method setIdeSettings.

static void setIdeSettings() {
    GradleExperimentalSettings.getInstance().SELECT_MODULES_ON_PROJECT_IMPORT = false;
    GradleExperimentalSettings.getInstance().SKIP_SOURCE_GEN_ON_PROJECT_SYNC = false;
    // Clear HTTP proxy settings, in case a test changed them.
    HttpConfigurable ideSettings = HttpConfigurable.getInstance();
    ideSettings.USE_HTTP_PROXY = false;
    ideSettings.PROXY_HOST = "";
    ideSettings.PROXY_PORT = 80;
    AndroidPlugin.GuiTestSuiteState state = getGuiTestSuiteState();
    state.setSkipSdkMerge(false);
// TODO: setUpDefaultGeneralSettings();
}
Also used : AndroidPlugin(org.jetbrains.android.AndroidPlugin) HttpConfigurable(com.intellij.util.net.HttpConfigurable)

Example 15 with HttpConfigurable

use of com.intellij.util.net.HttpConfigurable in project android by JetBrains.

the class GradlePropertiesTest method testSetProxySettings.

public void testSetProxySettings() {
    String host = "myproxy.test.com";
    int port = 443;
    String user = "johndoe";
    String password = "123456";
    HttpConfigurable ideSettings = HttpConfigurable.getInstance();
    ideSettings.USE_HTTP_PROXY = true;
    ideSettings.PROXY_HOST = host;
    ideSettings.PROXY_PORT = port;
    ideSettings.PROXY_AUTHENTICATION = true;
    ideSettings.setProxyLogin(user);
    ideSettings.setPlainProxyPassword(password);
    ProxySettings ideProxySettings = new ProxySettings(ideSettings);
    // Verify that the proxy settings are stored properly in the actual properties file.
    ideProxySettings.applyProxySettings(myProperties.getProperties());
    assertEquals(host, myProperties.getProperty("systemProp.http.proxyHost"));
    assertEquals(String.valueOf(port), myProperties.getProperty("systemProp.http.proxyPort"));
    assertEquals(user, myProperties.getProperty("systemProp.http.proxyUser"));
    assertEquals(password, myProperties.getProperty("systemProp.http.proxyPassword"));
    ProxySettings gradleProxySetting = myProperties.getHttpProxySettings();
    assertEquals(host, gradleProxySetting.getHost());
    assertEquals(port, gradleProxySetting.getPort());
    // Verify that username and password are removed from properties file, if authentication is disabled in IDE settings.
    ideSettings.PROXY_AUTHENTICATION = false;
    ideProxySettings = new ProxySettings(ideSettings);
    ideProxySettings.applyProxySettings(myProperties.getProperties());
    assertNull(myProperties.getProperty("systemProp.http.proxyUser"));
    assertNull(myProperties.getProperty("systemProp.http.proxyPassword"));
}
Also used : HttpConfigurable(com.intellij.util.net.HttpConfigurable)

Aggregations

HttpConfigurable (com.intellij.util.net.HttpConfigurable)15 GradleProperties (com.android.tools.idea.gradle.util.GradleProperties)3 NotNull (org.jetbrains.annotations.NotNull)3 Test (org.junit.Test)3 ProxySettings (com.android.tools.idea.gradle.util.ProxySettings)2 ProxySettingsDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ProxySettingsDialogFixture)2 File (java.io.File)2 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1 AndroidGradleNotification (com.android.tools.idea.gradle.project.AndroidGradleNotification)1 ProxySettingsDialog (com.android.tools.idea.gradle.project.ProxySettingsDialog)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 LocalProperties (com.android.tools.idea.gradle.util.LocalProperties)1 PropertiesFiles.getProperties (com.android.tools.idea.gradle.util.PropertiesFiles.getProperties)1 Pair (com.intellij.openapi.util.Pair)1 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ConfirmingTrustManager (com.intellij.util.net.ssl.ConfirmingTrustManager)1 CommonProxy (com.intellij.util.proxy.CommonProxy)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1