Search in sources :

Example 6 with HttpRequestFactory

use of com.google.api.client.http.HttpRequestFactory 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("http://google.com");
    HttpRequest request = null;
    HttpResponse response = null;
    try {
        request = requestFactory.buildGetRequest(url);
        response = request.executeAsync().get();
        response.disconnect();
    } catch (IOException ignored) {
    } finally {
        if (response != null) {
            response.disconnect();
        }
    }
    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 7 with HttpRequestFactory

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

the class HttpRequestIT 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("http://google.com");
    HttpRequest request = null;
    HttpResponse response = null;
    try {
        request = requestFactory.buildGetRequest(url);
        response = request.execute();
        response.disconnect();
    } catch (IOException ignored) {
    } finally {
        if (response != null) {
            response.disconnect();
        }
    }
    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 8 with HttpRequestFactory

use of com.google.api.client.http.HttpRequestFactory in project google-cloud-java by GoogleCloudPlatform.

the class HttpBigQueryRpc method open.

@Override
public String open(JobConfiguration configuration) {
    try {
        Job loadJob = new Job().setConfiguration(configuration);
        StringBuilder builder = new StringBuilder().append(BASE_RESUMABLE_URI).append(options.getProjectId()).append("/jobs");
        GenericUrl url = new GenericUrl(builder.toString());
        url.set("uploadType", "resumable");
        JsonFactory jsonFactory = bigquery.getJsonFactory();
        HttpRequestFactory requestFactory = bigquery.getRequestFactory();
        HttpRequest httpRequest = requestFactory.buildPostRequest(url, new JsonHttpContent(jsonFactory, loadJob));
        httpRequest.getHeaders().set("X-Upload-Content-Value", "application/octet-stream");
        HttpResponse response = httpRequest.execute();
        return response.getHeaders().getLocation();
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) JsonFactory(com.google.api.client.json.JsonFactory) HttpResponse(com.google.api.client.http.HttpResponse) GenericUrl(com.google.api.client.http.GenericUrl) JsonHttpContent(com.google.api.client.http.json.JsonHttpContent) IOException(java.io.IOException) Job(com.google.api.services.bigquery.model.Job)

Aggregations

GenericUrl (com.google.api.client.http.GenericUrl)8 HttpRequest (com.google.api.client.http.HttpRequest)8 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)8 HttpResponse (com.google.api.client.http.HttpResponse)7 IOException (java.io.IOException)6 HttpTransport (com.google.api.client.http.HttpTransport)4 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)4 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)3 JsonHttpContent (com.google.api.client.http.json.JsonHttpContent)2 JsonFactory (com.google.api.client.json.JsonFactory)2 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)2 Method (java.lang.reflect.Method)2 JSONObject (org.json.simple.JSONObject)2 JSONParser (org.json.simple.parser.JSONParser)2 Test (org.junit.Test)2 Credential (com.google.api.client.auth.oauth2.Credential)1 StoredCredential (com.google.api.client.auth.oauth2.StoredCredential)1 GoogleJsonError (com.google.api.client.googleapis.json.GoogleJsonError)1 HttpHeaders (com.google.api.client.http.HttpHeaders)1 HttpResponseException (com.google.api.client.http.HttpResponseException)1