Search in sources :

Example 76 with OkHttpClient

use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project pulsar by apache.

the class ProxyAdditionalServletTest method httpGet.

String httpGet(String url) throws IOException {
    OkHttpClient client = new OkHttpClient();
    okhttp3.Request request = new okhttp3.Request.Builder().get().url(url).build();
    try (Response response = client.newCall(request).execute()) {
        return response.body().string();
    }
}
Also used : Response(okhttp3.Response) ServletResponse(javax.servlet.ServletResponse) OkHttpClient(okhttp3.OkHttpClient) Request(org.eclipse.jetty.server.Request) ServletRequest(javax.servlet.ServletRequest)

Example 77 with OkHttpClient

use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project pulsar by apache.

the class TestPulsarSQLBase method waitPulsarSQLReady.

public void waitPulsarSQLReady() throws Exception {
    // wait until presto worker started
    ContainerExecResult result;
    do {
        try {
            result = execQuery("show catalogs;");
            assertThat(result.getExitCode()).isEqualTo(0);
            assertThat(result.getStdout()).contains("pulsar", "system");
            break;
        } catch (ContainerExecException cee) {
            if (cee.getResult().getStderr().contains("Presto server is still initializing")) {
                Thread.sleep(10000);
            } else {
                throw cee;
            }
        }
    } while (true);
    // check presto follow workers start finish.
    if (pulsarCluster.getSqlFollowWorkerContainers() != null && pulsarCluster.getSqlFollowWorkerContainers().size() > 0) {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder().url("http://" + pulsarCluster.getPrestoWorkerContainer().getUrl() + "/v1/node").build();
        do {
            try (Response response = okHttpClient.newCall(request).execute()) {
                Assert.assertNotNull(response.body());
                String nodeJsonStr = response.body().string();
                Assert.assertTrue(nodeJsonStr.length() > 0);
                log.info("presto node info: {}", nodeJsonStr);
                if (nodeJsonStr.contains("uri")) {
                    log.info("presto node exist.");
                    break;
                }
                Thread.sleep(1000);
            }
        } while (true);
    }
}
Also used : Response(org.testcontainers.shaded.okhttp3.Response) ContainerExecException(org.apache.pulsar.tests.integration.docker.ContainerExecException) OkHttpClient(org.testcontainers.shaded.okhttp3.OkHttpClient) Request(org.testcontainers.shaded.okhttp3.Request) ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult)

Example 78 with OkHttpClient

use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project teamscale-jacoco-agent by cqse.

the class AgentHttpServerTest method getText.

private String getText(String endpointPath) throws Exception {
    OkHttpClient client = new OkHttpClient();
    HttpUrl endpointUrl = HttpUrl.get(baseUri.resolve(endpointPath));
    Request request = new Request.Builder().url(endpointUrl).build();
    Response response = client.newCall(request).execute();
    return response.body() != null ? response.body().string() : "";
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) TestAgentOptionsBuilder(com.teamscale.jacoco.agent.options.TestAgentOptionsBuilder) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl)

Example 79 with OkHttpClient

use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project bonita-java-client by bonitasoft.

the class BonitaFeignClientBuilderImplTest method can_provide_custom_http_client.

@Test
void can_provide_custom_http_client() {
    // Given
    final OkHttpClient customHttpClient = new OkHttpClient();
    clientBuilder.okHttpClient(customHttpClient);
    // When
    clientBuilder.build();
    // Then
    verify(clientBuilder, never()).configureHttpClient(any());
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 80 with OkHttpClient

use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project AnkiChinaAndroid by ankichinateam.

the class HttpFetcher method fetchThroughHttp.

public static String fetchThroughHttp(String address, String encoding) {
    Timber.d("fetching %s", address);
    Response response = null;
    try {
        Request.Builder requestBuilder = new Request.Builder();
        requestBuilder.url(address).get();
        Request httpGet = requestBuilder.build();
        OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
        Tls12SocketFactory.enableTls12OnPreLollipop(clientBuilder).connectTimeout(Connection.CONN_TIMEOUT, TimeUnit.SECONDS).writeTimeout(Connection.CONN_TIMEOUT, TimeUnit.SECONDS).readTimeout(Connection.CONN_TIMEOUT, TimeUnit.SECONDS);
        OkHttpClient client = clientBuilder.build();
        response = client.newCall(httpGet).execute();
        if (response.code() != 200) {
            Timber.d("Response code was %s, returning failure", response.code());
            return "FAILED";
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(response.body().byteStream(), Charset.forName(encoding)));
        StringBuilder stringBuilder = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            stringBuilder.append(line);
        }
        return stringBuilder.toString();
    } catch (Exception e) {
        Timber.d(e, "Failed with an exception");
        return "FAILED with exception: " + e.getMessage();
    } finally {
        if (response != null && response.body() != null) {
            response.body().close();
        }
    }
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) InputStreamReader(java.io.InputStreamReader) Request(okhttp3.Request) BufferedReader(java.io.BufferedReader)

Aggregations

OkHttpClient (okhttp3.OkHttpClient)1944 Request (okhttp3.Request)1024 Response (okhttp3.Response)880 IOException (java.io.IOException)567 Test (org.junit.Test)365 Call (okhttp3.Call)290 RequestBody (okhttp3.RequestBody)222 Test (org.junit.jupiter.api.Test)145 Retrofit (retrofit2.Retrofit)138 File (java.io.File)132 HttpUrl (okhttp3.HttpUrl)131 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)128 Callback (okhttp3.Callback)117 JSONObject (org.json.JSONObject)110 ArrayList (java.util.ArrayList)106 ResponseBody (okhttp3.ResponseBody)105 Gson (com.google.gson.Gson)98 MediaType (okhttp3.MediaType)98 List (java.util.List)92 Map (java.util.Map)85