com.intellij.util.net.ssl.CertificateManager Java Examples
The following examples show how to use
com.intellij.util.net.ssl.CertificateManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpRequests.java From leetcode-editor with Apache License 2.0 | 6 votes |
private static void configureSslConnection(@NotNull String url, @NotNull HttpsURLConnection connection) { if (ApplicationManager.getApplication() == null) { LOG.info("Application is not initialized yet; Using default SSL configuration to connect to " + url); return; } try { SSLSocketFactory factory = CertificateManager.getInstance().getSslContext().getSocketFactory(); if (factory == null) { LOG.info("SSLSocketFactory is not defined by the IDE Certificate Manager; Using default SSL configuration to connect to " + url); } else { connection.setSSLSocketFactory(factory); } } catch (Throwable e) { LOG.info("Problems configuring SSL connection to " + url, e); } }
Example #2
Source File: HttpRequestBuilder.java From review-board-idea-plugin with Apache License 2.0 | 6 votes |
public <T> T asJson(Class<T> clazz) throws IOException, URISyntaxException { try (CloseableHttpClient client = HttpClientBuilder.create() .setDefaultRequestConfig(requestConfig) .setSslcontext(CertificateManager.getInstance().getSslContext()) .build()) { HttpRequestBase request = getHttpRequest(); CloseableHttpResponse response = client.execute(request); String content = CharStreams.toString(new InputStreamReader(response.getEntity().getContent())); try { if (StringUtils.isEmpty(content)) throw new Exception("Empty response recieved"); return new Gson().fromJson(content, clazz); } catch (Exception e) { throw new UnexpectedResponseException("Status: " + response.getStatusLine(), e); } } }
Example #3
Source File: ReviewBoardClient.java From review-board-idea-plugin with Apache License 2.0 | 6 votes |
public String contents(String href) { try { HttpRequestBase request = HttpRequestBuilder.get(href) .header(AUTHORIZATION, getAuthorizationHeader()) .request(); try (CloseableHttpClient client = HttpClientBuilder.create().setSslcontext(CertificateManager.getInstance().getSslContext()).build()) { CloseableHttpResponse response = client.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { return null; } else { return CharStreams.toString(new InputStreamReader(response.getEntity().getContent())); } } } catch (Exception e) { throw new RuntimeException(e); } }
Example #4
Source File: HttpRequestBuilder.java From review-board-idea-plugin with Apache License 2.0 | 5 votes |
public String asString() throws IOException, URISyntaxException { try (CloseableHttpClient client = HttpClientBuilder.create() .setSslcontext(CertificateManager.getInstance().getSslContext()) .setDefaultRequestConfig(requestConfig) .build()) { HttpRequestBase request = getHttpRequest(); CloseableHttpResponse response = client.execute(request); return CharStreams.toString(new InputStreamReader(response.getEntity().getContent())); } }
Example #5
Source File: IdeaCertificateService.java From azure-devops-intellij with MIT License | 4 votes |
@Override public SSLContext getSSLContext() { return CertificateManager.getInstance().getSslContext(); }
Example #6
Source File: HttpRequests.java From consulo with Apache License 2.0 | 4 votes |
private static URLConnection openConnection(RequestBuilderImpl builder) throws IOException { String url = builder.myUrl; for (int i = 0; i < builder.myRedirectLimit; i++) { if (builder.myForceHttps && StringUtil.startsWith(url, "http:")) { url = "https:" + url.substring(5); } if (url.startsWith("https:") && ApplicationManager.getApplication() != null) { CertificateManager.getInstance(); } URLConnection connection; if (!builder.myUseProxy) { connection = new URL(url).openConnection(Proxy.NO_PROXY); } else if (ApplicationManager.getApplication() == null) { connection = new URL(url).openConnection(); } else { connection = HttpConfigurable.getInstance().openConnection(url); } connection.setConnectTimeout(builder.myConnectTimeout); connection.setReadTimeout(builder.myTimeout); if (builder.myUserAgent != null) { connection.setRequestProperty("User-Agent", builder.myUserAgent); } if (builder.myHostnameVerifier != null && connection instanceof HttpsURLConnection) { ((HttpsURLConnection)connection).setHostnameVerifier(builder.myHostnameVerifier); } if (builder.myGzip) { connection.setRequestProperty("Accept-Encoding", "gzip"); } if (builder.myAccept != null) { connection.setRequestProperty("Accept", builder.myAccept); } connection.setUseCaches(false); if (builder.myTuner != null) { builder.myTuner.tune(connection); } if (connection instanceof HttpURLConnection) { int responseCode = ((HttpURLConnection)connection).getResponseCode(); if (responseCode < 200 || responseCode >= 300 && responseCode != HttpURLConnection.HTTP_NOT_MODIFIED) { ((HttpURLConnection)connection).disconnect(); if (responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP) { url = connection.getHeaderField("Location"); if (url != null) { continue; } } String message = IdeBundle.message("error.connection.failed.with.http.code.N", responseCode); throw new HttpStatusException(message, responseCode, StringUtil.notNullize(url, "Empty URL")); } } return connection; } throw new IOException(IdeBundle.message("error.connection.failed.redirects")); }