Class ResponseHandler
java.lang.Object
com.eqixiac.equinix.core.http.ResponseHandler
Deserializes and maps
EquinixResponse bodies: singleton/list/paginated JSON handling,
raw string/byte/map handling, header extraction, and the JSON-to-model mapping helpers that
turn deserialized Pages into user-facing PaginatedLists.
Split out of the former monolithic Utils class; see RequestAssembler,
ParameterMapper and SerializationHelper for the request-side helpers.
- Author:
- ianjones
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> StringextractFromHeader(EquinixResponse<T> equinixResponse, String headerName, Pattern extractionPattern) static <T> BooleanhandleBooleanResponse(EquinixResponse<T> equinixResponse, EquinixRequest<T> equinixRequest) static <T> byte[]handleByteResponse(EquinixResponse<T> equinixResponse) Reads the raw response body bytes;nullwhen the response has no body.static <T,S> List <S> handleListResponse(EquinixResponse<T> equinixResponse, EquinixRequest<T> equinixRequest) handleMapResponse(EquinixRequest<T> equinixRequest, EquinixResponse<T> equinixResponse) static <J> Page<J> handlePaginatedListResponse(EquinixResponse<?> equinixResponse, EquinixRequest<?> equinixRequest) Deserializes a paginated list/search response into aPageof raw JSON items and attaches the request/response pair for lazy paging.static <S,T> S handleSingletonResponse(EquinixResponse<T> equinixResponse, EquinixRequest<T> equinixRequest) static <T> StringhandleStringResponse(EquinixResponse<T> equinixResponse) Reads the raw response body as a UTF-8 string;nullwhen the response has no body.static <T,S> List <T> mapList(List<S> itemList, Pageable<T> serviceClient, BiFunction<? super S, ? super Pageable<T>, ? extends T> objectMapper) static <T,S> PaginatedFilteredList <T> mapPaginatedFilteredList(List<S> paginatedList, PageablePost<T> serviceClient, BiFunction<? super S, ? super PageablePost<T>, ? extends T> objectMapper) static <T,S> PaginatedList <T> mapPaginatedList(List<S> paginatedList, Pageable<T> serviceClient, BiFunction<? super S, ? super Pageable<T>, ? extends T> objectMapper) static <T,S> PaginatedFilteredList <T> toPaginatedFilteredList(Page<S> page, PageablePost<T> serviceClient, BiFunction<? super S, ? super PageablePost<T>, ? extends T> objectMapper) Builds a fully-populatedPaginatedFilteredListfrom a deserializedPagein one step (the POST-search counterpart totoPaginatedList(Page, Pageable, BiFunction)).static <T,S> PaginatedList <T> toPaginatedList(Page<S> page, Pageable<T> serviceClient, BiFunction<? super S, ? super Pageable<T>, ? extends T> objectMapper) Builds a fully-populatedPaginatedListfrom a deserializedPagein one step: maps each JSON item to its model wrapper and attaches the page's request/response/pagination for lazy paging.
-
Constructor Details
-
ResponseHandler
public ResponseHandler()
-
-
Method Details
-
handlePaginatedListResponse
public static <J> Page<J> handlePaginatedListResponse(EquinixResponse<?> equinixResponse, EquinixRequest<?> equinixRequest) throws EquinixClientException Deserializes a paginated list/search response into aPageof raw JSON items and attaches the request/response pair for lazy paging. The request may be typed over the public model or the JSON model - only the page's item type<J>matters here.- Type Parameters:
J- the page's item (JSON model) type- Throws:
EquinixClientException- if any.
-
handleListResponse
public static <T,S> List<S> handleListResponse(EquinixResponse<T> equinixResponse, EquinixRequest<T> equinixRequest) throws EquinixClientException - Throws:
EquinixClientException- if any.
-
handleSingletonResponse
public static <S,T> S handleSingletonResponse(EquinixResponse<T> equinixResponse, EquinixRequest<T> equinixRequest) throws EquinixClientException - Throws:
EquinixClientException- if any.
-
extractFromHeader
public static <T> String extractFromHeader(EquinixResponse<T> equinixResponse, String headerName, Pattern extractionPattern) -
handleBooleanResponse
public static <T> Boolean handleBooleanResponse(EquinixResponse<T> equinixResponse, EquinixRequest<T> equinixRequest) -
handleStringResponse
public static <T> String handleStringResponse(EquinixResponse<T> equinixResponse) throws EquinixClientException Reads the raw response body as a UTF-8 string;nullwhen the response has no body.- Throws:
EquinixClientException- if any.
-
handleByteResponse
public static <T> byte[] handleByteResponse(EquinixResponse<T> equinixResponse) throws EquinixClientException Reads the raw response body bytes;nullwhen the response has no body.- Throws:
EquinixClientException- if any.
-
handleMapResponse
public static <T> HashMap<String,String> handleMapResponse(EquinixRequest<T> equinixRequest, EquinixResponse<T> equinixResponse) throws EquinixClientException - Throws:
EquinixClientException- if any.
-
mapPaginatedList
public static <T,S> PaginatedList<T> mapPaginatedList(List<S> paginatedList, Pageable<T> serviceClient, BiFunction<? super S, ? super Pageable<T>, ? extends T> objectMapper) -
mapPaginatedFilteredList
public static <T,S> PaginatedFilteredList<T> mapPaginatedFilteredList(List<S> paginatedList, PageablePost<T> serviceClient, BiFunction<? super S, ? super PageablePost<T>, ? extends T> objectMapper) -
toPaginatedList
public static <T,S> PaginatedList<T> toPaginatedList(Page<S> page, Pageable<T> serviceClient, BiFunction<? super S, ? super Pageable<T>, ? extends T> objectMapper) Builds a fully-populatedPaginatedListfrom a deserializedPagein one step: maps each JSON item to its model wrapper and attaches the page's request/response/pagination for lazy paging. Replaces the repeated map-then-reconstruct boilerplate in resource clients.- Type Parameters:
T- the model typeS- the JSON type- Parameters:
page- the deserialized page (carries items + associated request/response + pagination)serviceClient- the paging client used to fetch subsequent pagesobjectMapper- maps a JSON item to its model wrapper- Returns:
- a paginated list ready for
next()/loadAll()
-
toPaginatedFilteredList
public static <T,S> PaginatedFilteredList<T> toPaginatedFilteredList(Page<S> page, PageablePost<T> serviceClient, BiFunction<? super S, ? super PageablePost<T>, ? extends T> objectMapper) Builds a fully-populatedPaginatedFilteredListfrom a deserializedPagein one step (the POST-search counterpart totoPaginatedList(Page, Pageable, BiFunction)).- Type Parameters:
T- the model typeS- the JSON type- Parameters:
page- the deserialized pageserviceClient- the paging client used to fetch subsequent pagesobjectMapper- maps a JSON item to its model wrapper- Returns:
- a paginated, filtered list ready for
next()/loadAll()
-
mapList
public static <T,S> List<T> mapList(List<S> itemList, Pageable<T> serviceClient, BiFunction<? super S, ? super Pageable<T>, ? extends T> objectMapper)
-