/** * Provides HttpTransport. If both proxyUrl and postStr is defined, it provides transport with Proxy. * @param proxyUrl Optional. * @param portStr Optional. String type for port so that user can easily pass null. (e.g: state.getProp(key)) * @return * @throws NumberFormatException * @throws GeneralSecurityException * @throws IOException */ public static HttpTransport newTransport(String proxyUrl, String portStr) throws NumberFormatException, GeneralSecurityException, IOException { if (!StringUtils.isEmpty(proxyUrl) && !StringUtils.isEmpty(portStr)) { return new NetHttpTransport.Builder() .trustCertificates(GoogleUtils.getCertificateTrustStore()) .setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyUrl, Integer.parseInt(portStr)))) .build(); } return GoogleNetHttpTransport.newTrustedTransport(); }
.trustCertificates(GoogleUtils.getCertificateTrustStore()); if (null != builder.proxyHost) { transportBuilder.setProxy(new Proxy(Proxy.Type.HTTP,
/** * Provides HttpTransport. If both proxyUrl and postStr is defined, it provides transport with Proxy. * @param proxyUrl Optional. * @param portStr Optional. String type for port so that user can easily pass null. (e.g: state.getProp(key)) * @return * @throws NumberFormatException * @throws GeneralSecurityException * @throws IOException */ public static HttpTransport newTransport(String proxyUrl, String portStr) throws NumberFormatException, GeneralSecurityException, IOException { if (!StringUtils.isEmpty(proxyUrl) && !StringUtils.isEmpty(portStr)) { return new NetHttpTransport.Builder() .trustCertificates(GoogleUtils.getCertificateTrustStore()) .setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyUrl, Integer.parseInt(portStr)))) .build(); } return GoogleNetHttpTransport.newTrustedTransport(); }
.trustCertificates(GoogleUtils.getCertificateTrustStore()) .setProxy( proxyUri == null
/** * Create an {@link ApacheHttpTransport} for calling Google APIs with an optional HTTP proxy. * * @param proxyUri Optional HTTP proxy URI to use with the transport. * @param proxyCredentials Optional HTTP proxy credentials to authenticate with the transport * proxy. * @return The resulting HttpTransport. * @throws IOException If there is an issue connecting to Google's certification server. * @throws GeneralSecurityException If there is a security issue with the keystore. */ public static ApacheHttpTransport createApacheHttpTransport( @Nullable URI proxyUri, @Nullable Credentials proxyCredentials) throws IOException, GeneralSecurityException { checkArgument( proxyUri != null || proxyCredentials == null, "if proxyUri is null than proxyCredentials should be null too"); ApacheHttpTransport transport = new ApacheHttpTransport.Builder() .trustCertificates(GoogleUtils.getCertificateTrustStore()) .setProxy( proxyUri == null ? null : new HttpHost(proxyUri.getHost(), proxyUri.getPort())) .build(); if (proxyCredentials != null) { ((DefaultHttpClient) transport.getHttpClient()) .getCredentialsProvider() .setCredentials(new AuthScope(proxyUri.getHost(), proxyUri.getPort()), proxyCredentials); } return transport; }
.trustCertificates(GoogleUtils.getCertificateTrustStore()) .setProxy( proxyUri == null
/** * Create an {@link ApacheHttpTransport} for calling Google APIs with an optional HTTP proxy. * * @param proxyUri Optional HTTP proxy URI to use with the transport. * @param proxyCredentials Optional HTTP proxy credentials to authenticate with the transport * proxy. * @return The resulting HttpTransport. * @throws IOException If there is an issue connecting to Google's certification server. * @throws GeneralSecurityException If there is a security issue with the keystore. */ public static ApacheHttpTransport createApacheHttpTransport( @Nullable URI proxyUri, @Nullable Credentials proxyCredentials) throws IOException, GeneralSecurityException { checkArgument( proxyUri != null || proxyCredentials == null, "if proxyUri is null than proxyCredentials should be null too"); ApacheHttpTransport transport = new ApacheHttpTransport.Builder() .trustCertificates(GoogleUtils.getCertificateTrustStore()) .setProxy( proxyUri == null ? null : new HttpHost(proxyUri.getHost(), proxyUri.getPort())) .build(); if (proxyCredentials != null) { ((DefaultHttpClient) transport.getHttpClient()) .getCredentialsProvider() .setCredentials(new AuthScope(proxyUri.getHost(), proxyUri.getPort()), proxyCredentials); } return transport; }
/** Gets an {@link HttpTransport} that contains the proxy configuration. */ public HttpTransport getHttpTransport() throws IOException, GeneralSecurityException { return new NetHttpTransport.Builder() .trustCertificates(GoogleUtils.getCertificateTrustStore()) .setProxy(proxy) .build(); }
/** * Returns a new instance of {@link NetHttpTransport} that uses * {@link GoogleUtils#getCertificateTrustStore()} for the trusted certificates using * {@link com.google.api.client.http.javanet.NetHttpTransport.Builder#trustCertificates(KeyStore)} * . * * <p> * This helper method doesn't provide for customization of the {@link NetHttpTransport}, such as * the ability to specify a proxy. To do use, use * {@link com.google.api.client.http.javanet.NetHttpTransport.Builder}, for example: * </p> * * <pre> static HttpTransport newProxyTransport() throws GeneralSecurityException, IOException { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); builder.trustCertificates(GoogleUtils.getCertificateTrustStore()); builder.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 3128))); return builder.build(); } * </pre> */ public static NetHttpTransport newTrustedTransport() throws GeneralSecurityException, IOException { return new NetHttpTransport.Builder().trustCertificates(GoogleUtils.getCertificateTrustStore()) .build(); }
KeyStore trustStore = GoogleUtils.getCertificateTrustStore(); SSLContext sslContext = SslUtils.getTlsSslContext(); SslUtils.initSslContext(sslContext, trustStore, SslUtils.getPkixTrustManagerFactory());