Search in sources :

Example 86 with HttpTransport

use of com.google.api.client.http.HttpTransport in project endpoints-java by cloudendpoints.

the class GoogleAuthTest method constructHttpRequest.

private HttpRequest constructHttpRequest(final String content) throws IOException {
    HttpTransport transport = new MockHttpTransport() {

        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
            return new MockLowLevelHttpRequest() {

                @Override
                public LowLevelHttpResponse execute() throws IOException {
                    MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
                    result.setContentType("application/json");
                    result.setContent(content);
                    return result;
                }
            };
        }
    };
    return transport.createRequestFactory().buildGetRequest(new GenericUrl("https://google.com")).setParser(new JsonObjectParser(new JacksonFactory()));
}
Also used : MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) JsonObjectParser(com.google.api.client.json.JsonObjectParser) GenericUrl(com.google.api.client.http.GenericUrl) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest)

Example 87 with HttpTransport

use of com.google.api.client.http.HttpTransport in project ddf by codice.

the class MetadataConfigurationParser method retrieveEntityDescriptorViaHttp.

private void retrieveEntityDescriptorViaHttp(String entityDescriptorString) throws IOException {
    if (entityDescriptorString.startsWith(HTTP)) {
        LOGGER.warn("Retrieving metadata via HTTP instead of HTTPS. The metadata configuration is unsafe!!!");
    }
    PropertyResolver propertyResolver = new PropertyResolver(entityDescriptorString);
    HttpTransport httpTransport = new NetHttpTransport();
    ExecutorService executor = Executors.newSingleThreadExecutor(StandardThreadFactoryBuilder.newThreadFactory("metadataConfigParserThread"));
    ListeningExecutorService service = MoreExecutors.listeningDecorator(executor);
    addHttpCallback(propertyResolver, httpTransport, service, executor);
    try {
        if (!service.isShutdown() && !service.awaitTermination(30, TimeUnit.SECONDS)) {
            LOGGER.debug("Executor service shutdown timed out");
        }
    } catch (InterruptedException e) {
        LOGGER.debug("Problem shutting down executor", e);
        service.shutdown();
        Thread.currentThread().interrupt();
    }
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) PropertyResolver(org.codice.ddf.configuration.PropertyResolver)

Example 88 with HttpTransport

use of com.google.api.client.http.HttpTransport in project beam by apache.

the class RetryHttpRequestInitializerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    HttpTransport lowLevelTransport = new HttpTransport() {

        @Override
        protected LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
            return mockLowLevelRequest;
        }
    };
    // Retry initializer will pass through to credential, since we can have
    // only a single HttpRequestInitializer, and we use multiple Credential
    // types in the SDK, not all of which allow for retry configuration.
    RetryHttpRequestInitializer initializer = new RetryHttpRequestInitializer(new MockNanoClock(), millis -> {
    }, Arrays.asList(418), mockHttpResponseInterceptor);
    storage = new Storage.Builder(lowLevelTransport, jsonFactory, initializer).setApplicationName("test").build();
}
Also used : MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) Storage(com.google.api.services.storage.Storage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Before(org.junit.Before)

Example 89 with HttpTransport

use of com.google.api.client.http.HttpTransport in project heron by twitter.

the class GcsUploader method createStorage.

private Storage createStorage(Credential credential) throws GeneralSecurityException, IOException {
    final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    final JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    return new Storage.Builder(httpTransport, jsonFactory, credential).build();
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) Storage(com.google.api.services.storage.Storage) JsonFactory(com.google.api.client.json.JsonFactory)

Example 90 with HttpTransport

use of com.google.api.client.http.HttpTransport in project gradle by gradle.

the class GcsClient method create.

public static GcsClient create(GcsConnectionProperties gcsConnectionProperties) throws GeneralSecurityException, IOException {
    HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    Storage.Builder builder = new Storage.Builder(transport, jsonFactory, null);
    if (gcsConnectionProperties.requiresAuthentication()) {
        Supplier<Credential> credentialSupplier = getCredentialSupplier(transport, jsonFactory);
        builder.setHttpRequestInitializer(new RetryHttpInitializerWrapper(credentialSupplier));
    }
    if (gcsConnectionProperties.getEndpoint().isPresent()) {
        builder.setRootUrl(gcsConnectionProperties.getEndpoint().get().toString());
    }
    if (gcsConnectionProperties.getServicePath().isPresent()) {
        builder.setServicePath(gcsConnectionProperties.getServicePath().get());
    }
    builder.setApplicationName("gradle");
    return new GcsClient(builder.build());
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) Credential(com.google.api.client.auth.oauth2.Credential) Storage(com.google.api.services.storage.Storage) JsonFactory(com.google.api.client.json.JsonFactory) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory)

Aggregations

HttpTransport (com.google.api.client.http.HttpTransport)106 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)40 JsonFactory (com.google.api.client.json.JsonFactory)35 HttpRequest (com.google.api.client.http.HttpRequest)29 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)28 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)28 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)27 IOException (java.io.IOException)24 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)21 HttpResponse (com.google.api.client.http.HttpResponse)21 GenericUrl (com.google.api.client.http.GenericUrl)15 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)12 MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)11 Credential (com.google.api.client.auth.oauth2.Credential)10 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)10 Storage (com.google.api.services.storage.Storage)9 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)8 Test (org.junit.Test)8 Monitor (org.datatransferproject.api.launcher.Monitor)7 ErrorTransport (com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport)6