public class ResponseHandler<T>
extends java.lang.Object
| Constructor and Description |
|---|
ResponseHandler(com.google.gson.reflect.TypeToken<T> type)
"Generics on a type are typically erased at runtime, except when the type is compiled with the
generic parameter bound.
|
| Modifier and Type | Method and Description |
|---|---|
T |
handleResponse(okhttp3.Response response)
Handles the HTTP response and converts it to the appropriate object or throws exceptions based
on the response status.
|
T |
handleResponse(okhttp3.Response response,
boolean submitTransactionAsync)
Handles the HTTP response and converts it to the appropriate object or throws exceptions based
on the response status.
|
T |
handleResponse(okhttp3.Response response,
java.lang.String content)
Handles the HTTP response with pre-read body content and converts it to the appropriate object
or throws exceptions based on the response status.
|
public ResponseHandler(com.google.gson.reflect.TypeToken<T> type)
type - public T handleResponse(okhttp3.Response response)
response - The HTTP response to handleTooManyRequestsException - If the response code is 429 (Too Many Requests)UnexpectedException - If the response body is empty or there's an unexpected error
reading the responseBadRequestException - If the response code is in the 4xx rangeBadResponseException - If the response code is in the 5xx rangepublic T handleResponse(okhttp3.Response response, java.lang.String content)
This method is useful when the caller needs to limit the response body size before processing, for example to prevent denial-of-service attacks.
Note: This method does NOT close the response. The caller is responsible for closing the response, typically using try-with-resources on the response object.
response - The HTTP response to handle (used for status code and headers)content - The pre-read response body contentTooManyRequestsException - If the response code is 429 (Too Many Requests)BadRequestException - If the response code is in the 4xx rangeBadResponseException - If the response code is in the 5xx rangepublic T handleResponse(okhttp3.Response response, boolean submitTransactionAsync)
response - The HTTP response to handlesubmitTransactionAsync - Only set it to true when calling Server.submitTransactionXdrAsync(String).TooManyRequestsException - If the response code is 429 (Too Many Requests)UnexpectedException - If the response body is empty or there's an unexpected error
reading the responseBadRequestException - If the response code is in the 4xx rangeBadResponseException - If the response code is in the 5xx range