-
- All Implemented Interfaces:
-
java.io.Closeable,java.lang.AutoCloseable
public abstract class RequestFactory implements Closeable
Factory for requests, responses and event sources.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classRequestFactory.Companionpublic enumRequestFactory.RequestPurposePurpose of the request.
-
Field Summary
Fields Modifier and Type Field Description private final Map<String, KClass<out ThrowableProblem>>registeredProblemTypesprivate final MediaTypeEncodersmediaTypeEncodersprivate final MediaTypeDecodersmediaTypeDecodersprivate final Map<KClass<?>, Function1<Object, String>>pathEncoders
-
Constructor Summary
Constructors Constructor Description RequestFactory()
-
Method Summary
Modifier and Type Method Description abstract Map<String, KClass<out ThrowableProblem>>getRegisteredProblemTypes()abstract MediaTypeEncodersgetMediaTypeEncoders()abstract MediaTypeDecodersgetMediaTypeDecoders()abstract Map<KClass<?>, Function1<Object, String>>getPathEncoders()abstract UnitregisterProblem(String typeId, KClass<out ThrowableProblem> problemType)Register a type of Problem to allow decoding and throwing specific exception instances of the provided type when returned in server responses. final Requestrequest(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)Create a Request. abstract <B extends Any> Requestrequest(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers, RequestFactory.RequestPurpose purpose)Create a Request. abstract Responseresponse(Request request)Execute a request and return the server's response. final Responseresponse(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)Create and execute a request created from the given request parameters and return the server's response. final <B extends Any> Responseresponse(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)Create and execute a request created from the given request parameters and return the server's response. final <B extends Any, R extends Any> Rresult(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)Create and execute a request created from the given request parameters and returns a result decoded from the server's response. final <R extends Any> Rresult(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)Create and execute a request created from the given request parameters and returns a result decoded from the server's response. final <B extends Any, R extends Any> Rresult(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers, KType resultType)Create and execute a request created from the given request parameters and returns a result decoded from the server's response. final <B extends Any, R extends Any> ResultResponse<R>resultResponse(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)Create and execute a request created from the given request parameters and return the server's response along with a result decoded from the server's response. final <R extends Any> ResultResponse<R>resultResponse(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)Create and execute a request created from the given request parameters and return the server's response along with a result decoded from the server's response. final <B extends Any, R extends Any> ResultResponse<R>resultResponse(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers, KType resultType)Create and execute a request created from the given request parameters and return the server's response along with a result decoded from the server's response. final <B extends Any> EventSourceeventSource(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)Creates an EventSource that uses the provided request parameters to supply the Request used for connecting to the Server-Sent Events stream. final EventSourceeventSource(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)Creates an EventSource that uses the provided request parameters to supply the Request used for connecting to the Server-Sent Events stream. final <B extends Any, D extends Any> Flow<D>eventStream(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers, Function5<TextMediaTypeDecoder, String, String, String, Logger, D> decoder)Creates an Flow of events that uses the provided request parameters to supply the Request used for connecting to the Server-Sent Events stream. final <D extends Any> Flow<D>eventStream(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers, Function5<TextMediaTypeDecoder, String, String, String, Logger, D> decoder)Creates an Flow of events that uses the provided request parameters to supply the Request used for connecting to the Server-Sent Events stream. final <D extends Any> Flow<D>eventStream(Function5<TextMediaTypeDecoder, String, String, String, Logger, D> decoder, SuspendFunction1<Iterable<Pair<String, String>>, Request> requestSupplier)Creates a Flow of events that uses the provided requestSupplier to supply the Request used for connecting to the Server-Sent Events stream. abstract Unitclose(Boolean cancelOutstandingRequests)-
-
Method Detail
-
getRegisteredProblemTypes
abstract Map<String, KClass<out ThrowableProblem>> getRegisteredProblemTypes()
-
getMediaTypeEncoders
abstract MediaTypeEncoders getMediaTypeEncoders()
-
getMediaTypeDecoders
abstract MediaTypeDecoders getMediaTypeDecoders()
-
getPathEncoders
abstract Map<KClass<?>, Function1<Object, String>> getPathEncoders()
-
registerProblem
abstract Unit registerProblem(String typeId, KClass<out ThrowableProblem> problemType)
Register a type of Problem to allow decoding and throwing specific exception instances of the provided type when returned in server responses.
If a problem response is encountered that do not have a registered type, a generic Problem will be returned/thrown.
- Parameters:
typeId- Problem type id to register.problemType- Problem subclass to map to typeId.
-
request
final Request request(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)
Create a Request.
-
request
abstract <B extends Any> Request request(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers, RequestFactory.RequestPurpose purpose)
Create a Request.
-
response
abstract Response response(Request request)
- Parameters:
request- Request used to generate the response.
-
response
final Response response(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)
-
response
final <B extends Any> Response response(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)
-
result
final <B extends Any, R extends Any> R result(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)
Create and execute a request created from the given request parameters and returns a result decoded from the server's response.
-
result
final <R extends Any> R result(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)
Create and execute a request created from the given request parameters and returns a result decoded from the server's response.
-
result
final <B extends Any, R extends Any> R result(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers, KType resultType)
Create and execute a request created from the given request parameters and returns a result decoded from the server's response.
-
resultResponse
final <B extends Any, R extends Any> ResultResponse<R> resultResponse(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)
-
resultResponse
final <R extends Any> ResultResponse<R> resultResponse(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)
-
resultResponse
final <B extends Any, R extends Any> ResultResponse<R> resultResponse(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers, KType resultType)
-
eventSource
final <B extends Any> EventSource eventSource(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)
Creates an EventSource that uses the provided request parameters to supply the Request used for connecting to the Server-Sent Events stream.
-
eventSource
final EventSource eventSource(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers)
Creates an EventSource that uses the provided request parameters to supply the Request used for connecting to the Server-Sent Events stream.
-
eventStream
final <B extends Any, D extends Any> Flow<D> eventStream(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, B body, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers, Function5<TextMediaTypeDecoder, String, String, String, Logger, D> decoder)
Creates an Flow of events that uses the provided request parameters to supply the Request used for connecting to the Server-Sent Events stream.
- Parameters:
decoder- Function used to decode events from the SSE stream.
-
eventStream
final <D extends Any> Flow<D> eventStream(Method method, String pathTemplate, Map<String, Object> pathParameters, Map<String, Object> queryParameters, List<MediaType> contentTypes, List<MediaType> acceptTypes, Map<String, Object> headers, Function5<TextMediaTypeDecoder, String, String, String, Logger, D> decoder)
Creates an Flow of events that uses the provided request parameters to supply the Request used for connecting to the Server-Sent Events stream.
- Parameters:
decoder- Function used to decode events from the SSE stream.
-
eventStream
final <D extends Any> Flow<D> eventStream(Function5<TextMediaTypeDecoder, String, String, String, Logger, D> decoder, SuspendFunction1<Iterable<Pair<String, String>>, Request> requestSupplier)
Creates a Flow of events that uses the provided requestSupplier to supply the Request used for connecting to the Server-Sent Events stream.
- Parameters:
decoder- Function used to decode events from the SSE stream.requestSupplier- Function that provides Request for connecting to the SSE stream.
-
-
-
-