com.google.cloud.http.HttpTransportOptions Java Examples
The following examples show how to use
com.google.cloud.http.HttpTransportOptions.
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: AbstractGCPProcessor.java From nifi with Apache License 2.0 | 6 votes |
/** * Builds the Transport Options containing the proxy configuration * @param context Context to get properties * @return Transport options object with proxy configuration */ protected TransportOptions getTransportOptions(ProcessContext context) { final ProxyConfiguration proxyConfiguration = ProxyConfiguration.getConfiguration(context, () -> { final String proxyHost = context.getProperty(PROXY_HOST).evaluateAttributeExpressions().getValue(); final Integer proxyPort = context.getProperty(PROXY_PORT).evaluateAttributeExpressions().asInteger(); if (proxyHost != null && proxyPort != null && proxyPort > 0) { final ProxyConfiguration componentProxyConfig = new ProxyConfiguration(); final String proxyUser = context.getProperty(HTTP_PROXY_USERNAME).evaluateAttributeExpressions().getValue(); final String proxyPassword = context.getProperty(HTTP_PROXY_PASSWORD).evaluateAttributeExpressions().getValue(); componentProxyConfig.setProxyType(Proxy.Type.HTTP); componentProxyConfig.setProxyServerHost(proxyHost); componentProxyConfig.setProxyServerPort(proxyPort); componentProxyConfig.setProxyUserName(proxyUser); componentProxyConfig.setProxyUserPassword(proxyPassword); return componentProxyConfig; } return ProxyConfiguration.DIRECT_CONFIGURATION; }); final ProxyAwareTransportFactory transportFactory = new ProxyAwareTransportFactory(proxyConfiguration); return HttpTransportOptions.newBuilder().setHttpTransportFactory(transportFactory).build(); }
Example #2
Source File: EntityManagerFactory.java From catatumbo with Apache License 2.0 | 5 votes |
/** * Creates and returns HttpTransportOptions from the given connection parameters. * * @param parameters * the connection parameters * @return the HttpTransportOptions */ private static HttpTransportOptions getHttpTransportOptions(ConnectionParameters parameters) { HttpTransportOptions.Builder httpOptionsBuilder = HttpTransportOptions.newBuilder(); httpOptionsBuilder.setConnectTimeout(parameters.getConnectionTimeout()); httpOptionsBuilder.setReadTimeout(parameters.getReadTimeout()); HttpTransportFactory httpTransportFactory = parameters.getHttpTransportFactory(); if (httpTransportFactory != null) { httpOptionsBuilder.setHttpTransportFactory(httpTransportFactory); } return httpOptionsBuilder.build(); }
Example #3
Source File: TestUtils.java From catatumbo with Apache License 2.0 | 4 votes |
public static EntityManager getEntityManager() throws FileNotFoundException { EntityManager em; if (isCI()) { em = getCIEntityManager(); } else { ConnectionParameters parameters = new ConnectionParameters(); parameters.setServiceURL(System.getenv(ENV_SERVICE_URL)); parameters.setProjectId(System.getenv(ENV_PROJECT_ID)); parameters.setNamespace(System.getenv(ENV_NAMESPACE)); String jsonCredentialsPath = System.getenv(ENV_CREDENTIALS); if (!Utility.isNullOrEmpty(jsonCredentialsPath)) { parameters.setJsonCredentialsFile(jsonCredentialsPath); } String connectionTimeout = System.getenv(ENV_CONNECTION_TIMEOUT); if (!Utility.isNullOrEmpty(connectionTimeout)) { parameters.setConnectionTimeout(Integer.parseInt(connectionTimeout)); } String readTimeout = System.getenv(ENV_READ_TIMEOUT); if (!Utility.isNullOrEmpty(readTimeout)) { parameters.setReadTimeout(Integer.parseInt(readTimeout)); } System.out.println(parameters); em = EntityManagerFactory.getInstance().createEntityManager(parameters); } Datastore ds = ((DefaultEntityManager) em).getDatastore(); DatastoreOptions options = ds.getOptions(); HttpTransportOptions httpTransportOptions = (HttpTransportOptions) options .getTransportOptions(); System.out.println("***************************"); System.out.println("DATASTORE INFORMATION"); System.out.printf("Host: %s%n", options.getHost()); System.out.printf("Project Id: %s%n", options.getProjectId()); System.out.printf("Namespace: %s%n", options.getNamespace()); System.out.printf("Credentials: %s%n", options.getCredentials()); System.out.printf("Connection Timeout: %d%n", httpTransportOptions.getConnectTimeout()); System.out.printf("Read Timeout: %d%n", httpTransportOptions.getReadTimeout()); System.out.println("***************************"); return em; }
Example #4
Source File: TestApp.java From gcpsamples with Apache License 2.0 | 4 votes |
public TestApp() { try { /* JacksonFactory jsonFactory = new JacksonFactory(); Authenticator.setDefault( new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( "user1", "user1".toCharArray()); } } ); Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 3128)); NetHttpTransport mHttpTransport = new NetHttpTransport.Builder().setProxy(proxy).build(); */ HttpHost proxy = new HttpHost("127.0.0.1",3128); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); httpClient.addRequestInterceptor(new HttpRequestInterceptor(){ @Override public void process(org.apache.http.HttpRequest request, HttpContext context) throws HttpException, IOException { //if (request.getRequestLine().getMethod().equals("CONNECT")) // request.addHeader(new BasicHeader("Proxy-Authorization","Basic dXNlcjE6dXNlcjE=")); } }); mHttpTransport = new ApacheHttpTransport(httpClient); /* com.google.api.client.googleapis.auth.oauth2.GoogleCredential credential = com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(mHttpTransport,jsonFactory); if (credential.createScopedRequired()) credential = credential.createScoped(Arrays.asList(StorageScopes.DEVSTORAGE_READ_ONLY)); com.google.api.services.storage.Storage service = new com.google.api.services.storage.Storage.Builder(mHttpTransport, jsonFactory, credential) .setApplicationName("oauth client") .build(); com.google.api.services.storage.model.Buckets dl = service.buckets().list("mineral-minutia-820").execute(); for (com.google.api.services.storage.model.Bucket bucket: dl.getItems()) System.out.println(bucket.getName()); */ // System.setProperty("https.proxyHost", "localhost"); // System.setProperty("https.proxyPort", "3128"); /* Authenticator.setDefault( new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( "user1", "user1".toCharArray()); } } ); */ HttpTransportFactory hf = new HttpTransportFactory(){ @Override public HttpTransport create() { return mHttpTransport; } }; com.google.auth.oauth2.GoogleCredentials credential = com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(hf); if (credential.createScopedRequired()) credential = credential.createScoped(Arrays.asList("https://www.googleapis.com/auth/devstorage.read_write")); TransportOptions options = HttpTransportOptions.newBuilder().setHttpTransportFactory(hf).build(); com.google.cloud.storage.Storage storage = com.google.cloud.storage.StorageOptions.newBuilder() .setCredentials(credential) .setProjectId("mineral-minutia-820") .setTransportOptions(options) .build().getService(); System.out.println("My buckets:"); for (com.google.cloud.storage.Bucket bucket : storage.list().iterateAll()) System.out.println(bucket); } catch (Exception ex) { System.out.println("Error: " + ex); } }
Example #5
Source File: AbstractGoogleClientFactory.java From nexus-blobstore-google-cloud with Eclipse Public License 1.0 | 2 votes |
/** * Provide a {@link TransportOptions} backed by Apache HTTP Client. * * @see ApacheHttpTransport * @return customized {@link TransportOptions} to use for our Google client instances */ TransportOptions transportOptions() { return HttpTransportOptions.newBuilder() .setHttpTransportFactory(() -> new ApacheHttpTransport(newHttpClient())) .build(); }