Search in sources :

Example 96 with HttpTransport

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

the class HttpRequestIT method executeAsync.

@Test
public void executeAsync() throws Exception {
    HttpTransport NET_HTTP_TRANSPORT = new NetHttpTransport();
    HttpRequestFactory requestFactory = NET_HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {

        @Override
        public void initialize(HttpRequest request) {
        }
    });
    GenericUrl url = new GenericUrl(webServer.getCallHttpUrl());
    HttpRequest request = null;
    HttpResponse response = null;
    try {
        request = requestFactory.buildGetRequest(url);
        response = request.executeAsync().get();
    } catch (IOException ignored) {
    } finally {
        close(response);
    }
    Method executeAsyncMethod = HttpRequest.class.getDeclaredMethod("executeAsync", Executor.class);
    Method callMethod = Callable.class.getDeclaredMethod("call");
    Method executeMethod = HttpRequest.class.getDeclaredMethod("execute");
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    // async
    verifier.verifyTrace(Expectations.async(Expectations.event("GOOGLE_HTTP_CLIENT_INTERNAL", executeAsyncMethod), Expectations.event("ASYNC", "Asynchronous Invocation")));
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException) Method(java.lang.reflect.Method) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 97 with HttpTransport

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

the class HttpRequestJDK7IT method execute.

@Test
public void execute() throws Exception {
    HttpTransport NET_HTTP_TRANSPORT = new NetHttpTransport();
    HttpRequestFactory requestFactory = NET_HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {

        @Override
        public void initialize(HttpRequest request) {
        }
    });
    GenericUrl url = new GenericUrl(webServer.getCallHttpUrl());
    HttpRequest request = null;
    HttpResponse response = null;
    try {
        request = requestFactory.buildGetRequest(url);
        response = request.execute();
    } catch (IOException ignored) {
    } finally {
        close(response);
        requestFactory.getTransport().shutdown();
    }
    Method executeMethod = HttpRequest.class.getDeclaredMethod("execute");
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    verifier.verifyTrace(Expectations.event("GOOGLE_HTTP_CLIENT_INTERNAL", executeMethod));
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException) Method(java.lang.reflect.Method) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 98 with HttpTransport

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

the class HttpRequestJDK7IT method executeAsync.

@Test
public void executeAsync() throws Exception {
    HttpTransport NET_HTTP_TRANSPORT = new NetHttpTransport();
    HttpRequestFactory requestFactory = NET_HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {

        @Override
        public void initialize(HttpRequest request) {
        }
    });
    GenericUrl url = new GenericUrl(webServer.getCallHttpUrl());
    HttpRequest request = null;
    HttpResponse response = null;
    try {
        request = requestFactory.buildGetRequest(url);
        response = request.executeAsync().get();
    } catch (IOException ignored) {
    } finally {
        close(response);
        requestFactory.getTransport().shutdown();
    }
    Method executeAsyncMethod = HttpRequest.class.getDeclaredMethod("executeAsync", Executor.class);
    Method callMethod = Callable.class.getDeclaredMethod("call");
    Method executeMethod = HttpRequest.class.getDeclaredMethod("execute");
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    // async
    verifier.verifyTrace(Expectations.async(Expectations.event("GOOGLE_HTTP_CLIENT_INTERNAL", executeAsyncMethod), Expectations.event("ASYNC", "Asynchronous Invocation")));
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException) Method(java.lang.reflect.Method) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 99 with HttpTransport

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

the class RPCOptions method getHandler.

public PServiceCallHandler getHandler() {
    Serializer serializer = getSerializer(format);
    URI uri = URI.create(endpoint);
    if (uri.getScheme() == null || uri.getScheme().length() == 0) {
        throw new ArgumentException("No protocol on URI: " + endpoint);
    }
    if (uri.getScheme().startsWith("thrift")) {
        if (// Must have host and port.
        (uri.getPort() < 1) || (uri.getHost() == null || uri.getHost().length() == 0) || // No path, query or fragment.
        (uri.getFragment() != null && uri.getFragment().length() > 0) || (uri.getQuery() != null && uri.getQuery().length() > 0) || (uri.getPath() != null && uri.getPath().length() > 0)) {
            throw new ArgumentException("Illegal thrift URI: " + endpoint);
        }
        InetSocketAddress address = new InetSocketAddress(uri.getHost(), uri.getPort());
        switch(uri.getScheme()) {
            case "thrift":
                return new SocketClientHandler(serializer, address, connect_timeout, read_timeout);
            case "thrift+nonblocking":
                return new NonblockingSocketClientHandler(serializer, address, connect_timeout, read_timeout);
            default:
                throw new ArgumentException("Unknown thrift protocol " + uri.getScheme());
        }
    }
    GenericUrl url = new GenericUrl(endpoint);
    Map<String, String> hdrs = new HashMap<>();
    for (String hdr : headers) {
        String[] parts = hdr.split("[:]", 2);
        if (parts.length != 2) {
            throw new ArgumentException("Invalid headers param: " + hdr);
        }
        hdrs.put(parts[0].trim(), parts[1].trim());
    }
    HttpTransport transport = new NetHttpTransport();
    HttpRequestFactory factory = transport.createRequestFactory(new SetHeadersInitializer(hdrs, connect_timeout, read_timeout));
    SerializerProvider serializerProvider = new ThriftSerializerProvider(serializer.mediaType());
    return new HttpClientHandler(() -> url, factory, serializerProvider);
}
Also used : SocketClientHandler(net.morimekta.providence.thrift.client.SocketClientHandler) NonblockingSocketClientHandler(net.morimekta.providence.thrift.client.NonblockingSocketClientHandler) NonblockingSocketClientHandler(net.morimekta.providence.thrift.client.NonblockingSocketClientHandler) HashMap(java.util.HashMap) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) InetSocketAddress(java.net.InetSocketAddress) GenericUrl(com.google.api.client.http.GenericUrl) URI(java.net.URI) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) SetHeadersInitializer(net.morimekta.providence.tools.rpc.utils.SetHeadersInitializer) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) ArgumentException(net.morimekta.console.args.ArgumentException) ThriftSerializerProvider(net.morimekta.providence.thrift.ThriftSerializerProvider) SerializerProvider(net.morimekta.providence.serializer.SerializerProvider) HttpClientHandler(net.morimekta.providence.client.HttpClientHandler) ThriftSerializerProvider(net.morimekta.providence.thrift.ThriftSerializerProvider) Serializer(net.morimekta.providence.serializer.Serializer)

Example 100 with HttpTransport

use of com.google.api.client.http.HttpTransport in project druid by druid-io.

the class GceAutoScaler method createComputeServiceImpl.

@Nullable
Compute createComputeServiceImpl() throws IOException, GeneralSecurityException, GceServiceException {
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
    if (credential.createScopedRequired()) {
        List<String> scopes = new ArrayList<>();
        scopes.add(ComputeScopes.CLOUD_PLATFORM);
        scopes.add(ComputeScopes.COMPUTE);
        credential = credential.createScoped(scopes);
    }
    if (credential.getClientAuthentication() != null) {
        throw new GceServiceException("Not using a service account");
    }
    return new Compute.Builder(httpTransport, jsonFactory, credential).setApplicationName("DruidAutoscaler").build();
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) JsonFactory(com.google.api.client.json.JsonFactory) ArrayList(java.util.ArrayList) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) Nullable(javax.annotation.Nullable)

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