1

I'm trying to use the AWS generated Android SDK for my API Gateway project. Based on the information on this Site I created a client interface with a API method like this:

@com.amazonaws.mobileconnectors.apigateway.annotation.Operation(path = "/events/bookingUpdate", method = "POST")
void bookingUpdatePost(BookingUpdate body);

So when I want to call my API I used the following code:

 try {
    clientInterface.bookingUpdatePost(generateBookingUpdateDeviceInformation(bookingUpdate));
} catch (ApiClientException e) {
    Log.e(BuildConfig.APPLICATION_ID, e.getLocalizedMessage());
    if (listener != null) {
        listener.onBookingUpdatePostRequestFinished(new Error(e.getLocalizedMessage()));
    }
}

is there any way to retrieve the APIResponse Headers from the amazon mobile connectors library?

2 Answers 2

1

There isn't a way to do so because it's not exposed externally. But you can use a generic invoker instead to achieve this.

Sign up to request clarification or add additional context in comments.

1 Comment

okay, thanks! than I probably move on with an own solution :-)
0

ApiClientException will contain non 2** status codes which can be retrieved by calling e.getStatusCode(). Otherwise I don't see a way to get headers unless you call the ApiResponse execute(ApiRequest request); method directly to get a reference to the ApiResponse instance.

For references, here's the source code for the handleResponse:

    /**
     * Converts response to method's declared returned object
     *
     * @param response http response
     * @param method method
     * @return object of method's declared returned type
     * @throws Throwable
     */
    Object handleResponse(HttpResponse response, Method method) throws Throwable {
        final int code = response.getStatusCode();
        final InputStream content = response.getContent();
        // successful request if code is 2xx
        if (code >= HTTP_RESPONSE_OK && code < HTTP_RESPONSE_LAST_SUCCESS_STATUSCODE) {
            final Type t = method.getReturnType();
            if (t != void.class && content != null) {
                final Reader reader = new InputStreamReader(response.getContent(),
                        StringUtils.UTF8);
                final Object obj = GSON_WITH_DATE_FORMATTER.fromJson(reader, t);
                reader.close();
                return obj;
            } else {
                // discard response
                if (content != null) {
                    content.close();
                }
                return null;
            }
        } else {
            final String error = content == null ? "" : IOUtils.toString(content);
            final ApiClientException ase = new ApiClientException(error);
            ase.setStatusCode(response.getStatusCode());
            ase.setServiceName(apiName);
            final String requestId = response.getHeaders().get("x-amzn-RequestId");
            if (requestId != null) {
                ase.setRequestId(requestId);
            }
            throw ase;
        }
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.