Package org.stellar.sdk.requests
Class ResponseHandler<T>
java.lang.Object
org.stellar.sdk.requests.ResponseHandler<T>
- Type Parameters:
T- the expected response type
Handles HTTP responses and converts them into typed Java objects.
Successful responses (2xx) are deserialized into the target type T using Gson. Error
responses are translated into the appropriate SDK exception:
TooManyRequestsExceptionfor 429RequestTimeoutExceptionfor 504BadRequestExceptionfor other 4xxBadResponseExceptionfor other 5xxUnknownResponseExceptionfor unrecognized status codes
-
Constructor Summary
ConstructorsConstructorDescriptionResponseHandler(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. -
Method Summary
Modifier and TypeMethodDescriptionhandleResponse(okhttp3.Response response) Handles the HTTP response and converts it to the appropriate object or throws exceptions based on the response status.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.handleResponse(okhttp3.Response response, 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.
-
Constructor Details
-
ResponseHandler
"Generics on a type are typically erased at runtime, except when the type is compiled with the generic parameter bound. In that case, the compiler inserts the generic type information into the compiled class. In other cases, that is not possible." More info: http://stackoverflow.com/a/14506181- Parameters:
type- the type token representing the response class to deserialize into
-
-
Method Details
-
handleResponse
Handles the HTTP response and converts it to the appropriate object or throws exceptions based on the response status.- Parameters:
response- The HTTP response to handle- Returns:
- The parsed object of type T
- Throws:
TooManyRequestsException- If the response code is 429 (Too Many Requests)RequestTimeoutException- If the response code is 504 (Gateway Timeout)UnexpectedException- If the response body is empty or there's an unexpected error reading the responseBadRequestException- If the response code is in the 4xx range (except 429)BadResponseException- If the response code is in the 5xx range (except 504)UnknownResponseException- If the response code is not in the 2xx, 4xx, or 5xx range
-
handleResponse
Handles the HTTP response with pre-read body content and converts it to the appropriate object or throws exceptions based on the response status.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.
- Parameters:
response- The HTTP response to handle (used for status code and headers)content- The pre-read response body content- Returns:
- The parsed object of type T
- Throws:
TooManyRequestsException- If the response code is 429 (Too Many Requests)RequestTimeoutException- If the response code is 504 (Gateway Timeout)BadRequestException- If the response code is in the 4xx range (except 429)BadResponseException- If the response code is in the 5xx range (except 504)UnknownResponseException- If the response code is not in the 2xx, 4xx, or 5xx range
-
handleResponse
Handles the HTTP response and converts it to the appropriate object or throws exceptions based on the response status.- Parameters:
response- The HTTP response to handlesubmitTransactionAsync- Only set it to true when callingServer.submitTransactionXdrAsync(String).- Returns:
- The parsed object of type T
- Throws:
TooManyRequestsException- If the response code is 429 (Too Many Requests)RequestTimeoutException- If the response code is 504 (Gateway Timeout)UnexpectedException- If the response body is empty or there's an unexpected error reading the responseBadRequestException- If the response code is in the 4xx range (except 429)BadResponseException- If the response code is in the 5xx range (except 504)UnknownResponseException- If the response code is not in the 2xx, 4xx, or 5xx range
-