Search in sources :

Example 11 with ANResponse

use of com.androidnetworking.common.ANResponse in project Fast-Android-Networking by amitshekhariitbhu.

the class InternalRunnable method executeUploadRequest.

private void executeUploadRequest() {
    Response okHttpResponse = null;
    try {
        okHttpResponse = InternalNetworking.performUploadRequest(request);
        if (okHttpResponse == null) {
            deliverError(request, Utils.getErrorForConnection(new ANError()));
            return;
        }
        if (request.getResponseAs() == ResponseType.OK_HTTP_RESPONSE) {
            request.deliverOkHttpResponse(okHttpResponse);
            return;
        }
        if (okHttpResponse.code() >= 400) {
            deliverError(request, Utils.getErrorForServerResponse(new ANError(okHttpResponse), request, okHttpResponse.code()));
            return;
        }
        ANResponse response = request.parseResponse(okHttpResponse);
        if (!response.isSuccess()) {
            deliverError(request, response.getError());
            return;
        }
        response.setOkHttpResponse(okHttpResponse);
        request.deliverResponse(response);
    } catch (Exception e) {
        deliverError(request, Utils.getErrorForConnection(new ANError(e)));
    } finally {
        SourceCloseUtil.close(okHttpResponse, request);
    }
}
Also used : ANResponse(com.androidnetworking.common.ANResponse) Response(okhttp3.Response) ANError(com.androidnetworking.error.ANError) ANResponse(com.androidnetworking.common.ANResponse)

Example 12 with ANResponse

use of com.androidnetworking.common.ANResponse in project Fast-Android-Networking by amitshekhariitbhu.

the class MultipartStringApiTest method testSyncResponseBodyMultipart404.

@SuppressWarnings("unchecked")
public void testSyncResponseBodyMultipart404() throws InterruptedException, IOException {
    server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
    ANRequest request = AndroidNetworking.upload(server.url("/").toString()).addMultipartParameter("key", "value").build();
    ANResponse<Response> response = request.executeForOkHttpResponse();
    assertEquals("data", response.getResult().body().string());
    assertEquals(404, response.getResult().code());
}
Also used : ANResponse(com.androidnetworking.common.ANResponse) Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) ANRequest(com.androidnetworking.common.ANRequest)

Example 13 with ANResponse

use of com.androidnetworking.common.ANResponse in project Fast-Android-Networking by amitshekhariitbhu.

the class PostStringApiTest method testSyncResponseBodyPost.

@SuppressWarnings("unchecked")
public void testSyncResponseBodyPost() throws InterruptedException, IOException {
    server.enqueue(new MockResponse().setBody("data"));
    ANRequest request = AndroidNetworking.post(server.url("/").toString()).addBodyParameter("fistName", "Amit").addBodyParameter("lastName", "Shekhar").build();
    ANResponse<Response> response = request.executeForOkHttpResponse();
    assertEquals("data", response.getResult().body().string());
}
Also used : ANResponse(com.androidnetworking.common.ANResponse) Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) ANRequest(com.androidnetworking.common.ANRequest)

Aggregations

ANResponse (com.androidnetworking.common.ANResponse)13 Response (okhttp3.Response)13 ANRequest (com.androidnetworking.common.ANRequest)8 MockResponse (okhttp3.mockwebserver.MockResponse)6 ANError (com.androidnetworking.error.ANError)5 AnalyticsListener (com.androidnetworking.interfaces.AnalyticsListener)2 DownloadProgressListener (com.androidnetworking.interfaces.DownloadProgressListener)2 User (com.networking.model.User)2 IOException (java.io.IOException)2 List (java.util.List)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2