public abstract class BaseRestOperation extends Object
| Constructor and Description |
|---|
BaseRestOperation() |
| Modifier and Type | Method and Description |
|---|---|
protected CommonsExpressionLanguage |
getCommonsExpressionLanguage()
Simplified, and limited, version of the runtime's expression language, which heavily relies on
CommonsBindingContext. |
protected org.mule.runtime.api.metadata.MediaType |
getDefaultResponseMediaType()
This method specifies the
MediaType that should be assumed the response to have in case the remote service doesn't
specify a Content-Type header. |
protected org.mule.runtime.api.el.ExpressionLanguage |
getExpressionLanguage() |
protected <P,A,T> Function<Throwable,T> |
notifyCompletionCallbackError(org.mule.runtime.extension.api.runtime.process.CompletionCallback<P,A> completionCallback)
Utility method that provides a
Function responsible for handling Throwables and
notify the CompletionCallback on non-blocking operations only. |
protected org.mule.runtime.api.metadata.MediaType |
resolveDefaultResponseMediaType(RestConfiguration config)
Resolves the default
MediaType to be used when processing the response if remote server doesn't specify a
Content-Type header. |
protected void |
setExpressionLanguage(org.mule.runtime.api.el.ExpressionLanguage expressionLanguage) |
protected org.mule.runtime.extension.api.exception.ModuleException |
toUnknownErrorModuleException(Throwable throwable)
Allows to customize the generation of a
ModuleException for unknown errors. |
protected org.mule.runtime.api.el.ExpressionLanguage getExpressionLanguage()
protected void setExpressionLanguage(org.mule.runtime.api.el.ExpressionLanguage expressionLanguage)
protected CommonsExpressionLanguage getCommonsExpressionLanguage()
CommonsBindingContext.
CommonsBindingContext.Builder builder = CommonsBindingContext.builder();
String json = "{\"name\":\"John\", \"age\":30, \"car\":null}";
InputStream value = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
builder.addJson("jsonBinding", value, StandardCharsets.UTF_8);
CommonsExpressionLanguageValue evaluatedExpression =
commonsExpressionLanguage.evaluateJson("jsonBinding - 'car'", builder.build());
leaving in evaluatedExpression a CommonsExpressionLanguageValue object with the following String value:
{"name":"John", "age":30}
CommonsExpressionLanguage to evaluate expressions with.protected final <P,A,T> Function<Throwable,T> notifyCompletionCallbackError(org.mule.runtime.extension.api.runtime.process.CompletionCallback<P,A> completionCallback)
Function responsible for handling Throwables and
notify the CompletionCallback on non-blocking operations only. It will unwrap a CompletionException to get
the root cause.
connection.sendAsync(HttpRequest.builder()
.uri(connection.getBaseUri() + "/accounts/" + accountId)
.build())
.thenAccept(httpResponse -> completionCallback.success(Result.builder()
.output(IOUtils.toString(httpResponse.getEntity().getContent()))
.attributes(httpResponse.getStatusCode())
.attributesMediaType(APPLICATION_JAVA)
.build()))
.exceptionally(notifyCompletionCallbackError(completionCallback));
P - type for output.A - type for output attributes.completionCallback - the CompletionCallback to be notified about the error.Function to be provided as CompletableFuture.exceptionally(Function) to handle
any Throwable that happens during the execution of the completable future. It is responsible for notifying
the CompletionCallback with the Throwable.protected org.mule.runtime.extension.api.exception.ModuleException toUnknownErrorModuleException(Throwable throwable)
ModuleException for unknown errors.throwable - Throwable given an unexpected error it should create a ModuleException with a generic error
like RestError.CONNECTIVITY.ModuleException with a generic error like
RestError.CONNECTIVITY.protected org.mule.runtime.api.metadata.MediaType getDefaultResponseMediaType()
MediaType that should be assumed the response to have in case the remote service doesn't
specify a Content-Type header. MediaType.APPLICATION_JSON since it's the most common response type. However, this
method should be overwritten if a different type of media type is to be expected, or if you know that a certain encoding will
be enforced.MediaType to assign the response in case the server doesn't specify one in its responseprotected final org.mule.runtime.api.metadata.MediaType resolveDefaultResponseMediaType(RestConfiguration config)
MediaType to be used when processing the response if remote server doesn't specify a
Content-Type header.config - RestConfiguration to get the defaultCharset from Mule Runtime.MediaType.Copyright © 2023. All rights reserved.