ServiceResponseBuilder<T,E> Class

  • java.lang.Object
    • com.microsoft.bot.restclient.ServiceResponseBuilder<T,E>

Type Parameters

T

The return type the caller expects from the REST response.

E

the exception to throw in case of error.

Implements

public final class ServiceResponseBuilder<T,E>
implements ResponseBuilder<T,E>

The builder for building a ServiceResponse<T>.

Method Summary

Modifier and Type Method and Description
ServiceResponseWithHeaders<T,THeader> <THeader>buildEmptyWithHeaders(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.

ServiceResponseWithHeaders<T,THeader> <THeader>buildWithHeaders(Response<ResponseBody> response, Class<THeader> headerType)

Build a ServiceResponseWithHeaders instance from a REST call response, a header in JSON format, and a possible error.

ServiceResponse<T> build(Response<ResponseBody> response)

Build a ServiceResponse instance from a REST call response and a possible error.

ServiceResponse<T> buildEmpty(Response<Void> response)

Build a ServiceResponse instance from a REST call response and a possible error, which does not have a response body.

java.lang.Class<> exceptionType()
boolean isSuccessful(int statusCode)

Check if the returned status code will be considered a success for this builder.

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.

ServiceResponseBuilder<T,E> withThrowOnGet404(boolean throwOnGet404)

Specifies whether to throw on 404 responses from a GET call.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Method Details

<THeader>buildEmptyWithHeaders

public ServiceResponseWithHeaders buildEmptyWithHeaders(Response response, Class 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.

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.

Parameters:

response
headerType

Throws:

java.io.IOException

<THeader>buildWithHeaders

public ServiceResponseWithHeaders buildWithHeaders(Response response, Class headerType)

Build a ServiceResponseWithHeaders instance from a REST call response, a header in JSON format, and a possible error.

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.

Parameters:

response
headerType

Throws:

java.io.IOException

build

public ServiceResponse build(Response response)

Build a ServiceResponse instance from a REST call response and a possible error.

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.

Parameters:

response

Throws:

java.io.IOException

buildEmpty

public ServiceResponse buildEmpty(Response response)

Build a ServiceResponse instance from a REST call response and a possible error, which does not have a response body.

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.

Parameters:

response

Throws:

java.io.IOException

exceptionType

public Class exceptionType()

Returns:

the exception type to thrown in case of error.

isSuccessful

public boolean isSuccessful(int statusCode)

Check if the returned status code will be considered a success for this builder.

Parameters:

statusCode - the status code to check

Returns:

true if it's a success, false otherwise.

register

public ServiceResponseBuilder register(int statusCode, Type type)

Register a mapping from a response status code to a response destination type.

Parameters:

statusCode
type

registerAll

public ServiceResponseBuilder registerAll(Map responseTypes)

Register all the mappings from a response status code to a response destination type stored in a Map.

Parameters:

responseTypes - the mapping from response status codes to response types.

Returns:

the same builder instance.

registerError

public ServiceResponseBuilder registerError(Class type)

Register a destination type for errors with models.

Parameters:

type

withThrowOnGet404

public ServiceResponseBuilder withThrowOnGet404(boolean throwOnGet404)

Specifies whether to throw on 404 responses from a GET call.

Parameters:

throwOnGet404 - true if to throw; false to simply return null. Default is false.

Returns:

the response builder itself

Applies to