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;
}
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);
}
}
}
}
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();
}
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();
}
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"));
}
Aggregations