Package retrofit.client

Examples of retrofit.client.Response


            log.info("Retrofit success: " + t.getClass().getName());
        }
    }

    public String formatErrorMessage(RetrofitError error) {
        Response response = error.getResponse();
        StringBuilder sb = new StringBuilder("Retrofit failure:\nUrl: ").append(error.getUrl());

        sb.append("\nisNetworkError: ").append(error.isNetworkError());
        sb.append("\nMessage: ").append(error.getMessage());
        sb.append("\nCause: ").append(error.getCause());

        if (response != null) {
            if (response.getStatus() != 0) {
                sb.append("\nStatus code: ").append(response.getStatus());
            }

            sb.append("\nReason: ").append(response.getReason());

            if (response.getHeaders() != null) {
                sb.append("\nHeaders:");
                for (Header header : response.getHeaders()) {
                    sb.append("\n").append(header.toString());
                }
            }

            if (response.getBody() != null) {
                sb.append("\nBody: ");
                try {
                    Scanner s = new Scanner(response.getBody().in());
                    s.useDelimiter("\\A");
                    sb.append(s.hasNext() ? s.next() : "");
                    s.close();
                } catch (IOException e) {
                    sb.append("Error parsing body");
View Full Code Here


     * @return {@link CDASyncedSpace} result.
     * @throws retrofit.RetrofitError in case of an error.
     */
    public CDASyncedSpace performInitialSynchronizationBlocking() throws RetrofitError {
        ensureSpaceBlocking(true);
        Response response = service.performSynchronizationBlocking(spaceKey, true, null);
        CDASyncedSpace result;

        try {
            result = gson.fromJson(
                    new InputStreamReader(response.getBody().in()), CDASyncedSpace.class);

            result = new SpaceMerger(null, result, null, null, getSpace()).call();
        } catch (Exception e) {
            throw RetrofitError.unexpectedError(response.getUrl(), e);
        }

        return result;
    }
View Full Code Here

        if (existingSpace == null) {
            throw new IllegalArgumentException("Existing space may not be null.");
        }

        ensureSpaceBlocking(true);
        Response response = service.performSynchronizationBlocking(spaceKey, false, null);
        CDASyncedSpace result;

        try {
            CDASyncedSpace updatedSpace = gson.fromJson(new InputStreamReader(response.getBody().in()), CDASyncedSpace.class);
            result = new SpaceMerger(existingSpace, updatedSpace, null, response, getSpace()).call();
        } catch (Exception e) {
            throw RetrofitError.unexpectedError(response.getUrl(), e);
        }

        return result;
    }
View Full Code Here

        if (syncToken == null) {
            throw new IllegalArgumentException("Sync token may not be null.");
        }

        ensureSpaceBlocking(true);
        Response response = service.performSynchronizationBlocking(spaceKey, null, syncToken);
        CDASyncedSpace result;

        try {
            result = gson.fromJson(
                    new InputStreamReader(response.getBody().in()), CDASyncedSpace.class);

            result = new SpaceMerger(null, result, null, null, getSpace()).call();
        } catch (Exception e) {
            throw RetrofitError.unexpectedError(response.getUrl(), e);
        }

        return result;
    }
View Full Code Here

     * @return {@link CDAArray} result.
     * @throws retrofit.RetrofitError in case of an error.
     */
    private CDAArray fetchArrayWithTypeBlocking(String type, Map<String, String> query) throws RetrofitError {
        ensureSpaceBlocking(false);
        Response response = service.fetchArrayWithTypeBlocking(spaceKey, type, query);

        CDAArray result;

        try {
            result = gson.fromJson(new InputStreamReader(response.getBody().in()), CDAArray.class);
            ArrayResponse.prepareResponse(result, response);
        } catch (IOException e) {
            throw RetrofitError.unexpectedError(response.getUrl(), e);
        }

        return result;
    }
View Full Code Here

     * @return {@link CDAArray} result.
     * @throws Exception in case of an error.
     */
    private CDAArray fetchArrayWithTypeBlocking(String type, Map<String, String> query) throws Exception {
        ensureSpaceBlocking(false);
        Response response = service.fetchArrayWithTypeBlocking(spaceKey, type, query);
        CDAArray result = gson.fromJson(new InputStreamReader(response.getBody().in()), CDAArray.class);
        ArrayResponse.prepareResponse(result, response);
        return result;
    }
View Full Code Here

     * @return {@link CDAArray} result.
     * @throws Exception in case of an error.
     */
    private CDAArray fetchArrayWithTypeBlocking(String type, Map<String, String> query) throws Exception {
        ensureSpaceBlocking(false);
        Response response = service.fetchArrayWithTypeBlocking(spaceKey, type, query);
        CDAArray result = gson.fromJson(new InputStreamReader(response.getBody().in()), CDAArray.class);
        ArrayResponse.prepareResponse(result, response);
        return result;
    }
View Full Code Here

* Created by Piroelle on 04/03/14.
*/
public class RestServiceErrorHandler implements ErrorHandler {
    @Override
    public Throwable handleError(RetrofitError cause) {
        Response r = cause.getResponse();
        ErrorResponse data = (ErrorResponse) cause.getBodyAs(ErrorResponse.class);

        if (r != null) {
            if (r.getStatus() == 401) {
                return new AuthorizationException(data.getMessage(), cause);
            } else if (r.getStatus() == 403) {
                //TODO: Forbidden
            } else if (r.getStatus() == 404) {
                return new EntityNotFoundException(data.getMessage(), cause);
            } else if (r.getStatus() == 405) {
                //TODO: Method Not Allowed
            } else if (r.getStatus() == 409) {
                return new QueryException(data.getMessage(), cause);
            } else if (r.getStatus() == 429) {
                return new RateLimitException(data.getMessage(), cause);
            }


        }
View Full Code Here

     * @return {@link CDASyncedSpace} result.
     * @throws retrofit.RetrofitError in case of an error.
     */
    public CDASyncedSpace performInitialSynchronizationBlocking() throws RetrofitError {
        ensureSpaceBlocking(true);
        Response response = service.performSynchronizationBlocking(spaceKey, true, null);
        CDASyncedSpace result;

        try {
            result = gson.fromJson(
                    new InputStreamReader(response.getBody().in()), CDASyncedSpace.class);

            result = new SpaceMerger(null, result, null, null, getSpace()).call();
        } catch (Exception e) {
            throw RetrofitError.unexpectedError(response.getUrl(), e);
        }

        return result;
    }
View Full Code Here

        if (existingSpace == null) {
            throw new IllegalArgumentException("Existing space may not be null.");
        }

        ensureSpaceBlocking(true);
        Response response = service.performSynchronizationBlocking(spaceKey, null, existingSpace.getSyncToken());
        CDASyncedSpace result;

        try {
            CDASyncedSpace updatedSpace = gson.fromJson(new InputStreamReader(response.getBody().in()), CDASyncedSpace.class);
            result = new SpaceMerger(existingSpace, updatedSpace, null, response, getSpace()).call();
        } catch (Exception e) {
            throw RetrofitError.unexpectedError(response.getUrl(), e);
        }

        return result;
    }
View Full Code Here

TOP

Related Classes of retrofit.client.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.