Search in sources :

Example 81 with Call

use of retrofit2.Call in project retrofit by square.

the class RequestBuilderTest method malformedContentTypeParameterThrows.

@Test
public void malformedContentTypeParameterThrows() {
    class Example {

        //
        @POST("/")
        Call<ResponseBody> method(@Header("Content-Type") String contentType, @Body RequestBody body) {
            return null;
        }
    }
    RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "hi");
    try {
        buildRequest(Example.class, "hello, world!", body);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("Malformed content type: hello, world!");
    }
}
Also used : Header(retrofit2.http.Header) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) MultipartBody(okhttp3.MultipartBody) Body(retrofit2.http.Body) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 82 with Call

use of retrofit2.Call in project retrofit by square.

the class RequestBuilderTest method formEncodedFieldOptional.

@Test
public void formEncodedFieldOptional() {
    class Example {

        //
        @FormUrlEncoded
        //
        @POST("/foo")
        Call<ResponseBody> method(@Field("foo") String foo, @Field("ping") String ping, @Field("kit") String kit) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "bar", null, "kat");
    assertBody(request.body(), "foo=bar&kit=kat");
}
Also used : Field(retrofit2.http.Field) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 83 with Call

use of retrofit2.Call in project retrofit by square.

the class RequestBuilderTest method bodyWithPathParams.

@Test
public void bodyWithPathParams() {
    class Example {

        //
        @POST("/foo/bar/{ping}/{kit}/")
        Call<ResponseBody> method(@Path("ping") String ping, @Body RequestBody body, @Path("kit") String kit) {
            return null;
        }
    }
    RequestBody body = RequestBody.create(TEXT_PLAIN, "Hi!");
    Request request = buildRequest(Example.class, "pong", body, "kat");
    assertThat(request.method()).isEqualTo("POST");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong/kat/");
    assertBody(request.body(), "Hi!");
}
Also used : Path(retrofit2.http.Path) Request(okhttp3.Request) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) MultipartBody(okhttp3.MultipartBody) Body(retrofit2.http.Body) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 84 with Call

use of retrofit2.Call in project retrofit by square.

the class RequestBuilderTest method headerParamToString.

@Test
public void headerParamToString() {
    class Example {

        //
        @GET("/foo/bar/")
        Call<ResponseBody> method(@Header("kit") BigInteger kit) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, new BigInteger("1234"));
    assertThat(request.method()).isEqualTo("GET");
    okhttp3.Headers headers = request.headers();
    assertThat(headers.size()).isEqualTo(1);
    assertThat(headers.get("kit")).isEqualTo("1234");
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
    assertThat(request.body()).isNull();
}
Also used : Header(retrofit2.http.Header) Request(okhttp3.Request) BigInteger(java.math.BigInteger) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 85 with Call

use of retrofit2.Call in project okhttp by square.

the class ClientAuthTest method missingClientAuthFailsForNeeds.

@Test
public void missingClientAuthFailsForNeeds() throws Exception {
    OkHttpClient client = buildClient(null, clientIntermediateCa);
    SSLSocketFactory socketFactory = buildServerSslSocketFactory(ClientAuth.NEEDS);
    server.useHttps(socketFactory, false);
    Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
    try {
        call.execute();
        fail();
    } catch (SSLHandshakeException expected) {
    } catch (SocketException expected) {
    // JDK 9
    }
}
Also used : Call(okhttp3.Call) SocketException(java.net.SocketException) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) DelegatingSSLSocketFactory(okhttp3.DelegatingSSLSocketFactory) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Test(org.junit.Test)

Aggregations

ResponseBody (okhttp3.ResponseBody)186 Request (okhttp3.Request)169 Test (org.junit.Test)155 Call (okhttp3.Call)116 Response (retrofit2.Response)106 Response (okhttp3.Response)98 Observable (rx.Observable)94 ServiceResponse (com.microsoft.rest.ServiceResponse)92 MockResponse (okhttp3.mockwebserver.MockResponse)67 IOException (java.io.IOException)66 RequestBody (okhttp3.RequestBody)50 Callback (okhttp3.Callback)41 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)34 OkHttpClient (okhttp3.OkHttpClient)27 ToStringConverterFactory (retrofit2.helpers.ToStringConverterFactory)27 Buffer (okio.Buffer)19 Call (retrofit2.Call)18 MultipartBody (okhttp3.MultipartBody)17 HttpUrl (okhttp3.HttpUrl)15 Callback (retrofit2.Callback)14