/** * 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(); }
NetHttpTransport.Builder transportBuilder = new NetHttpTransport.Builder() .trustCertificates(GoogleUtils.getCertificateTrustStore()); if (null != builder.proxyHost) {
return new NetHttpTransport.Builder().setProxy(proxy).build();
/** * Create a new TestNet account as described in the TestNet main page * (https://testnet.steem.vc). * * @param username * The account to create. * @param password * The password to set for the <code>username</code>. * @throws IOException * In case something went wrong. * @throws GeneralSecurityException * In case something went wrong. */ private static void createTestNetAccount(String username, String password) throws IOException, GeneralSecurityException { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); // Disable SSL verification: builder.doNotValidateCertificate(); HttpRequest httpRequest = builder.build().createRequestFactory(new HttpClientRequestInitializer()) .buildPostRequest(new GenericUrl("https://testnet.steem.vc/create"), ByteArrayContent.fromString( "application/x-www-form-urlencoded", "username=" + username + "&password=" + password)); try { httpRequest.execute(); } catch (HttpResponseException e) { if (e.getStatusCode() != 409) { LOGGER.info("Account already existed."); } } } }
public NetHttpTransport getHttpTransport() throws GeneralSecurityException, IOException { if (httpTransport == null) { GoogleDriveConnectionProperties conn = getConnectionProperties(); if (conn.useSSL.getValue() || conn.useProxy.getValue()) { Builder tmpBuilder = new NetHttpTransport.Builder(); if (conn.useProxy.getValue()) { Proxy proxy = new Proxy(HTTP, createUnresolved(conn.proxyHost.getValue(), conn.proxyPort.getValue())); tmpBuilder.setProxy(proxy); } if (conn.useSSL.getValue()) { TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); FileInputStream fi = new FileInputStream(conn.sslTrustStore.getValue()); KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(fi, conn.sslTrustStorePassword.getValue().toCharArray()); fi.close(); tmf.init(ks); SSLContext sslContext = SSLContext.getInstance(conn.sslAlgorithm.getValue()); sslContext.init(null, tmf.getTrustManagers(), new java.security.SecureRandom()); tmpBuilder.setSslSocketFactory(sslContext.getSocketFactory()); } httpTransport = tmpBuilder.build(); } else { httpTransport = GoogleNetHttpTransport.newTrustedTransport(); } } return httpTransport; }
@Override public JsonRPCResponse invokeAndReadResponse(JsonRPCRequest requestObject, URI endpointUri, boolean sslVerificationDisabled) throws SteemCommunicationException { try { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); // Disable SSL verification if needed if (sslVerificationDisabled && endpointUri.getScheme().equals("https")) { builder.doNotValidateCertificate(); } String requestPayload = requestObject.toJson(); HttpRequest httpRequest = builder.build().createRequestFactory(new HttpClientRequestInitializer()) .buildPostRequest(new GenericUrl(endpointUri), ByteArrayContent.fromString("application/json", requestPayload)); LOGGER.debug("Sending {}.", requestPayload); HttpResponse httpResponse = httpRequest.execute(); int status = httpResponse.getStatusCode(); String responsePayload = httpResponse.parseAsString(); if (status >= 200 && status < 300 && responsePayload != null) { return new JsonRPCResponse(CommunicationHandler.getObjectMapper().readTree(responsePayload)); } else { throw new ClientProtocolException("Unexpected response status: " + status); } } catch (GeneralSecurityException | IOException e) { throw new SteemCommunicationException("A problem occured while processing the request.", e); } }
@Override public JsonRPCResponse invokeAndReadResponse(JsonRPCRequest requestObject, URI endpointUri, boolean sslVerificationDisabled) throws SteemCommunicationException { try { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); // Disable SSL verification if needed if (sslVerificationDisabled && endpointUri.getScheme().equals("https")) { builder.doNotValidateCertificate(); } String requestPayload = requestObject.toJson(); HttpRequest httpRequest = builder.build().createRequestFactory(new HttpClientRequestInitializer()) .buildPostRequest(new GenericUrl(endpointUri), ByteArrayContent.fromString("application/json", requestPayload)); LOGGER.debug("Sending {}.", requestPayload); HttpResponse httpResponse = httpRequest.execute(); int status = httpResponse.getStatusCode(); String responsePayload = httpResponse.parseAsString(); if (status >= 200 && status < 300 && responsePayload != null) { return new JsonRPCResponse(CommunicationHandler.getObjectMapper().readTree(responsePayload)); } else { throw new ClientProtocolException("Unexpected response status: " + status); } } catch (GeneralSecurityException | IOException e) { throw new SteemCommunicationException("A problem occured while processing the request.", e); } }
/** * 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(); }
/** * Constructor for instantiating the Google Calendars data source. * @param settings the application settings * @throws Exception if an error occurs */ public GoogleCalendarSourceImpl(final Settings settings) throws Exception { if (settings.getUserSettings().needInternetProxy()) { Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(settings.getUserSettings().internetProxyHost(), settings .getUserSettings().internetProxyPort())); httpTransport = new NetHttpTransport.Builder().setProxy(proxy).build(); } else { httpTransport = new NetHttpTransport.Builder().build(); } obfuscateEmails = settings.getUserSettings().obfuscateAttendeeEmails(); syncOrganizerAndAttendees = settings.getUserSettings().googleSyncOrganizerAndAttendees(); LOG.info("Connecting to Google Calendar..."); final Credential credential = authorize(); client = new Calendar.Builder(httpTransport, jsonFactory, credential).setApplicationName(APPLICATION_NAME).build(); calendarId = getCalendarId(settings.getUserSettings().googleCalendarName()); calendarTimeZone = getCalendarTimeZone(calendarId); LOG.info("Connected to Google Calendar."); }
/** * 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(); }
public APIKeyClient(String cloudURL, String apiKey, boolean skipCheckCertificate) { NetHttpTransport.Builder netHttpBuilder; if (skipCheckCertificate) { try { netHttpBuilder = new NetHttpTransport.Builder().doNotValidateCertificate(); } catch (GeneralSecurityException ex) { LOGGER.warn("Cannot set not-validating certificate. Certificate will be validating.", ex); netHttpBuilder = new NetHttpTransport.Builder(); } } else { netHttpBuilder = new NetHttpTransport.Builder(); } httpTransport = netHttpBuilder.build(); initializeDefaultAPIClient(cloudURL, apiKey); }
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, PROXY_PORT)); HttpTransport httpTransport = new NetHttpTransport.Builder().setProxy(proxy).build();
final Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("your address", port)); final HttpTransport httpTransport = new NetHttpTransport.Builder().setProxy(proxy).build(); // Build flow and trigger user authorization request. GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, SCOPES) .setDataStoreFactory(DATA_STORE_FACTORY) .setAccessType("offline") .build();
public SlackService(Proxy proxy) { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); builder.setProxy(proxy); requestFactory = builder.build().createRequestFactory(); }
static HttpTransport transport(Optional<ProxyConfig> proxyConfig) { return new NetHttpTransport.Builder() .setProxy(proxy(proxyConfig)) .build(); }
/** 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(); }
public SlackService(Proxy proxy) { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); builder.setProxy(proxy); requestFactory = builder.build().createRequestFactory(); }
public static void main(String[] args) throws Exception { Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("YOUR PROXY IP", 80)); HttpTransport transport = new NetHttpTransport.Builder().setProxy(proxy).build(); JsonFactory jsonFactory = new GsonFactory(); // This request initializer will ensure the API key is sent with every HTTP request. MapsEngineRequestInitializer apiKeyInitializer = new MapsEngineRequestInitializer(PUBLIC_API_KEY); }
private static HttpTransport _createHttpTransport() throws GeneralSecurityException, IOException { HttpTransport httpTransport = new NetHttpTransport.Builder() .trustCertificates(GoogleUtils.getCertificateTrustStore()) .build(); return httpTransport; }
/** Logs in in via WebTls and return the auth cookie to use**/ public String loginViaCertificate() throws GeneralSecurityException, IOException { SSLSocketFactory sslSocketFactory = getSocketFactory(); HttpTransport transport = new NetHttpTransport.Builder() .setSslSocketFactory(sslSocketFactory) .build(); return makeCall(transport); }