public abstract class RestPagingProvider<C extends RestConnection> extends Object implements org.mule.runtime.extension.api.runtime.streaming.PagingProvider<C,org.mule.runtime.api.metadata.TypedValue<String>>
Different APIs use different paging strategies which are tackled in implementations of this class. This class provides the basics as:
PagingProvider contract
Each item in the obtained page will be returned as an individual TypedValue, with the proper mime type and encoding
set.
Type parameters: RestConnection
| Modifier and Type | Class and Description |
|---|---|
static interface |
RestPagingProvider.PagingContext
Context related to the pagination.
|
| Constructor and Description |
|---|
RestPagingProvider(Function<C,org.mule.runtime.http.api.domain.message.request.HttpRequestBuilder> requestFactory,
org.mule.runtime.api.metadata.MediaType defaultResponseMediaType,
PagingStrategy pagingStrategy)
Creates a new instance
|
| Modifier and Type | Method and Description |
|---|---|
void |
close(RestConnection connection) |
protected abstract List<org.mule.runtime.api.metadata.TypedValue<String>> |
extractPageItems(org.mule.runtime.api.metadata.TypedValue<String> content)
Given the raw content response body this method will extract the payload data as a list of items which represent a page.
|
List<org.mule.runtime.api.metadata.TypedValue<String>> |
getPage(C connection) |
Optional<Integer> |
getTotalResults(RestConnection connection) |
protected org.mule.runtime.api.metadata.TypedValue<String> |
postProcess(org.mule.runtime.api.metadata.TypedValue<String> rawPage)
Allows post process the server response before the payload is extracted.
|
protected HttpResponseResult |
send(C connection,
org.mule.runtime.http.api.domain.message.request.HttpRequestBuilder requestBuilder,
org.mule.runtime.api.metadata.MediaType defaultResponseMediaType)
Does the HTTP call with the given connection for the requestBuilder.
|
protected abstract org.mule.runtime.api.metadata.TypedValue<String> |
toRawPage(InputStream content,
org.mule.runtime.api.metadata.MediaType mediaType)
Given the server response this method will consume the response from the content
InputStream with the given
MediaType, which may or may not contain a charset (cases like application/json should use the default encodings),
returns a TypedValue with the content as String. |
public RestPagingProvider(Function<C,org.mule.runtime.http.api.domain.message.request.HttpRequestBuilder> requestFactory, org.mule.runtime.api.metadata.MediaType defaultResponseMediaType, PagingStrategy pagingStrategy)
requestFactory - a Function to generate the request to be used on each page request. Each invocation should
yield a different instance.defaultResponseMediaType - the MediaType for the page items if the server doesn't specify one.pagingStrategy - the pagination strategy.public final List<org.mule.runtime.api.metadata.TypedValue<String>> getPage(C connection)
getPage in interface org.mule.sdk.api.runtime.streaming.PagingProvider<C extends RestConnection,org.mule.runtime.api.metadata.TypedValue<String>>protected abstract org.mule.runtime.api.metadata.TypedValue<String> toRawPage(InputStream content, org.mule.runtime.api.metadata.MediaType mediaType)
InputStream with the given
MediaType, which may or may not contain a charset (cases like application/json should use the default encodings),
returns a TypedValue with the content as String.content - the stream response from the server.mediaType - the MediaType for this content.TypedValue with the content as String.protected HttpResponseResult send(C connection, org.mule.runtime.http.api.domain.message.request.HttpRequestBuilder requestBuilder, org.mule.runtime.api.metadata.MediaType defaultResponseMediaType)
connection - raw content page as TypedValuerequestBuilder - the HttpRequestBuilder to be executed.defaultResponseMediaType - to be used if the server doesn't specify one with the
HttpHeaders.Names.CONTENT_TYPE header.HttpResponse which represents the server response.protected abstract List<org.mule.runtime.api.metadata.TypedValue<String>> extractPageItems(org.mule.runtime.api.metadata.TypedValue<String> content)
content - raw content page as TypedValueList> which represents a page with items.protected org.mule.runtime.api.metadata.TypedValue<String> postProcess(org.mule.runtime.api.metadata.TypedValue<String> rawPage)
rawPage - the server response as it.public Optional<Integer> getTotalResults(RestConnection connection)
getTotalResults in interface org.mule.sdk.api.runtime.streaming.PagingProvider<C extends RestConnection,org.mule.runtime.api.metadata.TypedValue<String>>public final void close(RestConnection connection) throws org.mule.runtime.api.exception.MuleException
close in interface org.mule.sdk.api.runtime.streaming.PagingProvider<C extends RestConnection,org.mule.runtime.api.metadata.TypedValue<String>>org.mule.runtime.api.exception.MuleExceptionCopyright © 2023. All rights reserved.