Search in sources :

Example 46 with POST

use of retrofit2.http.POST in project autorest.java by Azure.

the class LROsImpl method postAsyncNoRetrySucceededWithServiceResponseAsync.

/**
 * Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status.
 *
 * @throws IllegalArgumentException thrown if parameters fail the validation
 * @return the observable for the request
 */
public Observable<ServiceResponseWithHeaders<Product, LROsPostAsyncNoRetrySucceededHeaders>> postAsyncNoRetrySucceededWithServiceResponseAsync() {
    final Product product = null;
    Observable<Response<ResponseBody>> observable = service.postAsyncNoRetrySucceeded(product, this.client.acceptLanguage(), this.client.userAgent());
    return client.getAzureClient().getPostOrDeleteResultWithHeadersAsync(observable, new TypeToken<Product>() {
    }.getType(), LROsPostAsyncNoRetrySucceededHeaders.class);
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) TypeToken(com.google.common.reflect.TypeToken) Product(fixtures.lro.models.Product) SubProduct(fixtures.lro.models.SubProduct)

Example 47 with POST

use of retrofit2.http.POST in project autorest.java by Azure.

the class LROsImpl method postAsyncRetrycanceledWithServiceResponseAsync.

/**
 * Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status.
 *
 * @throws IllegalArgumentException thrown if parameters fail the validation
 * @return the observable for the request
 */
public Observable<ServiceResponseWithHeaders<Void, LROsPostAsyncRetrycanceledHeaders>> postAsyncRetrycanceledWithServiceResponseAsync() {
    final Product product = null;
    Observable<Response<ResponseBody>> observable = service.postAsyncRetrycanceled(product, this.client.acceptLanguage(), this.client.userAgent());
    return client.getAzureClient().getPostOrDeleteResultWithHeadersAsync(observable, new TypeToken<Void>() {
    }.getType(), LROsPostAsyncRetrycanceledHeaders.class);
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) TypeToken(com.google.common.reflect.TypeToken) Product(fixtures.lro.models.Product) SubProduct(fixtures.lro.models.SubProduct)

Example 48 with POST

use of retrofit2.http.POST in project autorest.java by Azure.

the class ParameterGroupingsImpl method postOptionalWithServiceResponseAsync.

/**
 * Post a bunch of optional parameters grouped.
 *
 * @throws IllegalArgumentException thrown if parameters fail the validation
 * @return the {@link ServiceResponse} object if successful.
 */
public Observable<ServiceResponse<Void>> postOptionalWithServiceResponseAsync() {
    final ParameterGroupingPostOptionalParameters parameterGroupingPostOptionalParameters = null;
    String customHeader = null;
    Integer query = null;
    return service.postOptional(this.client.acceptLanguage(), customHeader, query, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {

        @Override
        public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<Void> clientResponse = postOptionalDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : ServiceResponse(com.microsoft.rest.ServiceResponse) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ParameterGroupingPostOptionalParameters(fixtures.azureparametergrouping.models.ParameterGroupingPostOptionalParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 49 with POST

use of retrofit2.http.POST in project EssayJoke by qiyei2015.

the class RetrofitEngine method getMethodName.

/**
 * 找到method
 * @param task
 * @return
 */
private String getMethodName(HttpTask task) {
    String methodName = null;
    // 这个循环找到method
    for (Method method : task.getRequest().getApiClazz().getDeclaredMethods()) {
        String value = null;
        switch(task.getRequest().getMethod()) {
            case HTTP.GET:
                GET getAnnotation = method.getAnnotation(GET.class);
                if (getAnnotation != null) {
                    value = getAnnotation.value();
                }
                break;
            case HTTP.POST:
                POST postAnnotation = method.getAnnotation(POST.class);
                if (postAnnotation != null) {
                    value = postAnnotation.value();
                }
                break;
            case HTTP.DOWNLOAD:
                if (method.getAnnotation(Streaming.class) != null) {
                    GET downloadAnnotation = method.getAnnotation(GET.class);
                    if (downloadAnnotation != null) {
                        value = downloadAnnotation.value();
                    }
                }
                break;
            case HTTP.UPLOAD:
                if (method.getAnnotation(Multipart.class) != null) {
                    POST uploadAnnotation = method.getAnnotation(POST.class);
                    if (uploadAnnotation != null) {
                        value = uploadAnnotation.value();
                    }
                }
                break;
            default:
                break;
        }
        if (value != null && task.getRequest().getPathUrl().equals(value)) {
            methodName = method.getName();
            LogManager.v(HTTP.TAG, "method :" + methodName);
        }
    }
    return methodName;
}
Also used : Streaming(retrofit2.http.Streaming) Multipart(retrofit2.http.Multipart) POST(retrofit2.http.POST) GET(retrofit2.http.GET) Method(java.lang.reflect.Method)

Example 50 with POST

use of retrofit2.http.POST in project retrofit by square.

the class RequestBuilderTest method simpleMultipart.

@Test
public void simpleMultipart() throws IOException {
    class Example {

        // 
        @Multipart
        // 
        @POST("/foo/bar/")
        Call<ResponseBody> method(@Part("ping") String ping, @Part("kit") RequestBody kit) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "pong", RequestBody.create(MediaType.parse("text/plain"), "kat"));
    assertThat(request.method()).isEqualTo("POST");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
    RequestBody body = request.body();
    Buffer buffer = new Buffer();
    body.writeTo(buffer);
    String bodyString = buffer.readUtf8();
    assertThat(bodyString).contains("Content-Disposition: form-data;").contains("name=\"ping\"\r\n").contains("\r\npong\r\n--");
    assertThat(bodyString).contains("Content-Disposition: form-data;").contains("name=\"kit\"").contains("\r\nkat\r\n--");
}
Also used : Buffer(okio.Buffer) Part(retrofit2.http.Part) Request(okhttp3.Request) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

ResponseBody (okhttp3.ResponseBody)38 Test (org.junit.Test)33 Request (okhttp3.Request)31 Response (retrofit2.Response)27 ServiceResponse (com.microsoft.rest.ServiceResponse)22 RequestBody (okhttp3.RequestBody)19 TypeToken (com.google.common.reflect.TypeToken)18 Product (fixtures.lro.models.Product)18 Buffer (okio.Buffer)14 MultipartBody (okhttp3.MultipartBody)13 Part (retrofit2.http.Part)10 Body (retrofit2.http.Body)8 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)7 OkHttpClient (okhttp3.OkHttpClient)6 Field (retrofit2.http.Field)6 FieldMap (retrofit2.http.FieldMap)6 PartMap (retrofit2.http.PartMap)6 List (java.util.List)5 Map (java.util.Map)5