public class DefaultRestConnection extends BaseRestConnection<org.mule.runtime.extension.api.exception.ModuleException,org.mule.runtime.extension.api.error.ErrorTypeDefinition<RestError>>
RestError.| Constructor and Description |
|---|
DefaultRestConnection(org.mule.runtime.http.api.client.HttpClient httpClient,
org.mule.runtime.http.api.client.HttpRequestOptions httpRequestOptions,
String baseUri,
org.mule.runtime.api.el.ExpressionLanguage expressionLanguage) |
| Modifier and Type | Method and Description |
|---|---|
protected org.mule.runtime.extension.api.exception.ModuleException |
createModuleException(org.mule.runtime.http.api.domain.message.response.HttpResponse httpResponse,
org.mule.runtime.extension.api.error.ErrorTypeDefinition<RestError> errorTypeDefinition,
org.mule.runtime.api.metadata.MediaType defaultMediaType)
Utility method that provides a hook for customizing the
E to be thrown when an HttpResponse is marked as
failure based on BaseRestConnection.httpResponseToErrorTypeDefinition(HttpResponse, MediaType). |
protected Optional<org.mule.runtime.extension.api.error.ErrorTypeDefinition<RestError>> |
httpResponseToErrorTypeDefinition(org.mule.runtime.http.api.domain.message.response.HttpResponse httpResponse,
org.mule.runtime.api.metadata.MediaType mediaType)
Template method that allows usage of custom
ErrorTypeDefinition's for those scenarios where SaaS is not Restful
complaint or signal success error responses are returned with 20x responses. |
protected org.mule.runtime.http.api.domain.entity.HttpEntity |
materializeHttpResponseEntity(org.mule.runtime.http.api.domain.entity.HttpEntity httpEntity)
Whenever the connection implementation needs to handle signal error responses which are 200 response status code the method
BaseRestConnection.httpResponseToErrorTypeDefinition(HttpResponse, MediaType) would be implemented in order to read the entity content
response to check for the signal error flag. |
protected org.mule.runtime.extension.api.exception.ModuleException |
toConnectivityErrorFunction(Throwable throwable)
Template method that allows usage of custom
ErrorTypeDefinition's for general errors like TimeoutException or
IOException which are thrown by the HttpClient API. |
authenticate, beforeRequest, getBaseUri, getCommonsExpressionLanguage, getExpressionLanguage, getHttpClient, getHttpRequestOptions, getMediaType, send, sendAsync, throwModuleExceptionIfErrorResponse, toResult, validatepublic DefaultRestConnection(org.mule.runtime.http.api.client.HttpClient httpClient,
org.mule.runtime.http.api.client.HttpRequestOptions httpRequestOptions,
String baseUri,
org.mule.runtime.api.el.ExpressionLanguage expressionLanguage)
protected org.mule.runtime.http.api.domain.entity.HttpEntity materializeHttpResponseEntity(org.mule.runtime.http.api.domain.entity.HttpEntity httpEntity)
BaseRestConnectionBaseRestConnection.httpResponseToErrorTypeDefinition(HttpResponse, MediaType) would be implemented in order to read the entity content
response to check for the signal error flag. If this is done without materializing the HttpEntity it won't later allow the
client which made the request to be executed by the connection to consume the response. Therefore, this method allows to
materialize the entity so it would allow to be read more than once.materializeHttpResponseEntity in class BaseRestConnection<org.mule.runtime.extension.api.exception.ModuleException,org.mule.runtime.extension.api.error.ErrorTypeDefinition<RestError>>httpEntity - the server's response.HttpEntity that allows to be read more than once.protected Optional<org.mule.runtime.extension.api.error.ErrorTypeDefinition<RestError>> httpResponseToErrorTypeDefinition(org.mule.runtime.http.api.domain.message.response.HttpResponse httpResponse, org.mule.runtime.api.metadata.MediaType mediaType)
BaseRestConnectionErrorTypeDefinition's for those scenarios where SaaS is not Restful
complaint or signal success error responses are returned with 20x responses. By overriding this method in a custom connection
implementation allows customizing ErrorTypeDefinition's. If the function returns an Optional.empty() it means
the HttpResponse is a success. If this method is overridden most like BaseRestConnection.toConnectivityErrorFunction(Throwable)
would need to be too as it uses RestError for generic errors. HttpResponse entity content with an in memory implementation such is
ByteArrayHttpEntity by overwritten
BaseRestConnection.materializeHttpResponseEntity(HttpEntity) so it could be consumed more than once, to check the body content for
signal error and if it not an error by the client when processing the response.httpResponseToErrorTypeDefinition in class BaseRestConnection<org.mule.runtime.extension.api.exception.ModuleException,org.mule.runtime.extension.api.error.ErrorTypeDefinition<RestError>>httpResponse - the response HttpResponse from the server.mediaType - to read the entity content from server.Optional to check if the response corresponds to an error.protected org.mule.runtime.extension.api.exception.ModuleException createModuleException(org.mule.runtime.http.api.domain.message.response.HttpResponse httpResponse,
org.mule.runtime.extension.api.error.ErrorTypeDefinition<RestError> errorTypeDefinition,
org.mule.runtime.api.metadata.MediaType defaultMediaType)
BaseRestConnectionE to be thrown when an HttpResponse is marked as
failure based on BaseRestConnection.httpResponseToErrorTypeDefinition(HttpResponse, MediaType). error.description based on statusCode " " reasonPhrase.
E that also implements
ErrorMessageAwareException so it associates the HttpResponse body as payload and the
attributes representation's for the response.createModuleException in class BaseRestConnection<org.mule.runtime.extension.api.exception.ModuleException,org.mule.runtime.extension.api.error.ErrorTypeDefinition<RestError>>httpResponse - the response HttpResponse from the server.errorTypeDefinition - ErrorTypeDefinition associated to this failure response.defaultMediaType - to read the entity content from server.E with the description and the ErrorTypeDefinition associated.protected org.mule.runtime.extension.api.exception.ModuleException toConnectivityErrorFunction(Throwable throwable)
BaseRestConnectionErrorTypeDefinition's for general errors like TimeoutException or
IOException which are thrown by the HttpClient API. The implementation should consider that a
E may be passed to this function in which case it should be propagated as it is. By overriding this method in a
custom connection implementation it will allow customizing these ErrorTypeDefinition's.toConnectivityErrorFunction in class BaseRestConnection<org.mule.runtime.extension.api.exception.ModuleException,org.mule.runtime.extension.api.error.ErrorTypeDefinition<RestError>>Function to handle a Throwable and return a E with its corresponding
ErrorTypeDefinition.Copyright © 2023. All rights reserved.