Search in sources :

Example 31 with Response

use of org.openclinica.ns.response.v31.Response in project okhttp by square.

the class AsynchronousGet method run.

public void run() throws Exception {
    Request request = new Request.Builder().url("http://publicobject.com/helloworld.txt").build();
    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
            e.printStackTrace();
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            try (ResponseBody responseBody = response.body()) {
                if (!response.isSuccessful())
                    throw new IOException("Unexpected code " + response);
                Headers responseHeaders = response.headers();
                for (int i = 0, size = responseHeaders.size(); i < size; i++) {
                    System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
                }
                System.out.println(responseBody.string());
            }
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Headers(okhttp3.Headers) Request(okhttp3.Request) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody)

Example 32 with Response

use of org.openclinica.ns.response.v31.Response in project okhttp by square.

the class CacheResponse method run.

public void run() throws Exception {
    Request request = new Request.Builder().url("http://publicobject.com/helloworld.txt").build();
    String response1Body;
    try (Response response1 = client.newCall(request).execute()) {
        if (!response1.isSuccessful())
            throw new IOException("Unexpected code " + response1);
        response1Body = response1.body().string();
        System.out.println("Response 1 response:          " + response1);
        System.out.println("Response 1 cache response:    " + response1.cacheResponse());
        System.out.println("Response 1 network response:  " + response1.networkResponse());
    }
    String response2Body;
    try (Response response2 = client.newCall(request).execute()) {
        if (!response2.isSuccessful())
            throw new IOException("Unexpected code " + response2);
        response2Body = response2.body().string();
        System.out.println("Response 2 response:          " + response2);
        System.out.println("Response 2 cache response:    " + response2.cacheResponse());
        System.out.println("Response 2 network response:  " + response2.networkResponse());
    }
    System.out.println("Response 2 equals Response 1? " + response1Body.equals(response2Body));
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) IOException(java.io.IOException)

Example 33 with Response

use of org.openclinica.ns.response.v31.Response in project keywhiz by square.

the class XsrfServletFilterIntegrationTest method rejectsForAdminUrlWithoutXsrf.

@Test
public void rejectsForAdminUrlWithoutXsrf() throws Exception {
    noXsrfClient.newCall(buildLoginPost(DbSeedCommand.defaultUser, DbSeedCommand.defaultPassword)).execute();
    Request request = new Request.Builder().url(testUrl("/admin/clients")).get().build();
    Response response = noXsrfClient.newCall(request).execute();
    assertThat(response.code()).isEqualTo(401);
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) Test(org.junit.Test)

Example 34 with Response

use of org.openclinica.ns.response.v31.Response in project keywhiz by square.

the class XsrfServletFilterIntegrationTest method xsrfNotRequiredForLogout.

@Test
public void xsrfNotRequiredForLogout() throws Exception {
    Request request = new Request.Builder().post(RequestBody.create(MediaType.parse("text/plain"), "")).url(testUrl("/admin/logout")).build();
    Response response = client.newCall(request).execute();
    assertThat(response.code()).isNotEqualTo(401);
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) Test(org.junit.Test)

Example 35 with Response

use of org.openclinica.ns.response.v31.Response in project keywhiz by square.

the class XsrfServletFilterIntegrationTest method allowsForAdminUrlWithXsrf.

@Test
public void allowsForAdminUrlWithXsrf() throws Exception {
    client.newCall(buildLoginPost(DbSeedCommand.defaultUser, DbSeedCommand.defaultPassword)).execute();
    Request request = new Request.Builder().url(testUrl("/admin/clients")).get().build();
    Response response = client.newCall(request).execute();
    assertThat(response.code()).isNotEqualTo(401);
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) Test(org.junit.Test)

Aggregations

Response (okhttp3.Response)474 Request (okhttp3.Request)350 Test (org.junit.Test)213 IOException (java.io.IOException)175 Response (retrofit2.Response)156 ResponseBody (okhttp3.ResponseBody)136 ServiceResponse (com.microsoft.rest.ServiceResponse)114 Call (okhttp3.Call)102 Observable (rx.Observable)98 MockResponse (okhttp3.mockwebserver.MockResponse)76 RequestBody (okhttp3.RequestBody)70 OkHttpClient (okhttp3.OkHttpClient)65 Callback (okhttp3.Callback)43 List (java.util.List)39 TestClients.clientRequest (keywhiz.TestClients.clientRequest)37 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)32 HttpUrl (okhttp3.HttpUrl)26 Interceptor (okhttp3.Interceptor)26 MediaType (okhttp3.MediaType)26 ANResponse (com.androidnetworking.common.ANResponse)23