T - The return type the caller expects from the REST response.E - the exception to throw in case of error.public class ServiceResponseBuilder<T,E extends RestException> extends Object
ServiceResponse.| Modifier and Type | Field and Description |
|---|---|
protected Class<? extends RestException> |
exceptionType
The exception type to thrown in case of error.
|
protected JacksonMapperAdapter |
mapperAdapter
The mapperAdapter used for deserializing the response.
|
protected Map<Integer,Type> |
responseTypes
A mapping of HTTP status codes and their corresponding return types.
|
| Constructor and Description |
|---|
ServiceResponseBuilder(JacksonMapperAdapter mapperAdapter)
Create a ServiceResponseBuilder instance.
|
ServiceResponseBuilder(JacksonMapperAdapter mapperAdapter,
Map<Integer,Type> responseTypes)
Create a ServiceResponseBuilder instance.
|
| Modifier and Type | Method and Description |
|---|---|
ServiceResponse<T> |
build(retrofit2.Response<okhttp3.ResponseBody> response)
Build a ServiceResponse instance from a REST call response and a
possible error.
|
protected Object |
buildBody(int statusCode,
okhttp3.ResponseBody responseBody)
Builds the body object from the HTTP status code and returned response
body undeserialized and wrapped in
ResponseBody. |
ServiceResponse<T> |
buildEmpty(retrofit2.Response<Void> response)
Build a ServiceResponse instance from a REST call response and a
possible error, which does not have a response body.
|
<THeader> ServiceResponseWithHeaders<T,THeader> |
buildEmptyWithHeaders(retrofit2.Response<Void> response,
Class<THeader> headerType)
Build a ServiceResponseWithHeaders instance from a REST call response, a header
in JSON format, and a possible error, which does not have a response body.
|
<THeader> ServiceResponseWithHeaders<T,THeader> |
buildWithHeaders(retrofit2.Response<okhttp3.ResponseBody> response,
Class<THeader> headerType)
Build a ServiceResponseWithHeaders instance from a REST call response, a header
in JSON format, and a possible error.
|
ServiceResponseBuilder<T,E> |
register(int statusCode,
Type type)
Register a mapping from a response status code to a response destination type.
|
ServiceResponseBuilder<T,E> |
registerAll(Map<Integer,Type> responseTypes)
Register all the mappings from a response status code to a response
destination type stored in a
Map. |
ServiceResponseBuilder<T,E> |
registerError(Class<? extends RestException> type)
Register a destination type for errors with models.
|
protected Map<Integer,Type> responseTypes
protected Class<? extends RestException> exceptionType
protected JacksonMapperAdapter mapperAdapter
public ServiceResponseBuilder(JacksonMapperAdapter mapperAdapter)
mapperAdapter - the serialization utils to use for deserialization operationspublic ServiceResponseBuilder(JacksonMapperAdapter mapperAdapter, Map<Integer,Type> responseTypes)
mapperAdapter - the serialization utils to use for deserialization operationsresponseTypes - a mapping of response status codes and response destination typespublic ServiceResponseBuilder<T,E> register(int statusCode, Type type)
statusCode - the status code.type - the type to deserialize.public ServiceResponseBuilder<T,E> registerError(Class<? extends RestException> type)
type - the type to deserialize.public ServiceResponseBuilder<T,E> registerAll(Map<Integer,Type> responseTypes)
Map.responseTypes - the mapping from response status codes to response types.public ServiceResponse<T> build(retrofit2.Response<okhttp3.ResponseBody> response) throws E extends RestException, IOException
If the status code in the response is registered, the response will be considered valid and deserialized into the specified destination type. If the status code is not registered, the response will be considered invalid and deserialized into the specified error type if there is one. An AutoRestException is also thrown.
response - the Response instance from REST callTE - exceptions from the REST callIOException - exceptions from deserializationE extends RestExceptionpublic ServiceResponse<T> buildEmpty(retrofit2.Response<Void> response) throws E extends RestException, IOException
If the status code in the response is registered, the response will be considered valid. If the status code is not registered, the response will be considered invalid. An AutoRestException is also thrown.
response - the Response instance from REST callTE - exceptions from the REST callIOException - exceptions from deserializationE extends RestExceptionpublic <THeader> ServiceResponseWithHeaders<T,THeader> buildWithHeaders(retrofit2.Response<okhttp3.ResponseBody> response, Class<THeader> headerType) throws E extends RestException, IOException
If the status code in the response is registered, the response will be considered valid and deserialized into the specified destination type. If the status code is not registered, the response will be considered invalid and deserialized into the specified error type if there is one. An AutoRestException is also thrown.
THeader - the type of the headerresponse - the Response instance from REST callheaderType - the type of the headerTE - exceptions from the REST callIOException - exceptions from deserializationE extends RestExceptionpublic <THeader> ServiceResponseWithHeaders<T,THeader> buildEmptyWithHeaders(retrofit2.Response<Void> response, Class<THeader> headerType) throws E extends RestException, IOException
If the status code in the response is registered, the response will be considered valid. If the status code is not registered, the response will be considered invalid. An AutoRestException is also thrown.
THeader - the type of the headerresponse - the Response instance from REST callheaderType - the type of the headerTE - exceptions from the REST callIOException - exceptions from deserializationE extends RestExceptionprotected Object buildBody(int statusCode, okhttp3.ResponseBody responseBody) throws IOException
ResponseBody.statusCode - the HTTP status coderesponseBody - the response bodyIOException - thrown for any deserialization errors/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/