use of org.mule.runtime.extension.api.runtime.operation.Result in project mule by mulesoft.
the class ExportedPackagesValidatorTestCase method setUpInvalidExtension.
private void setUpInvalidExtension() {
OutputModel appleList = mockOutputModel(InternalTestClass.class);
OperationModel firstOperation = mockOperationModel(appleList, mockOutputModel(InternalTestClass.class));
withMethod(firstOperation, getApiMethods(InternalTestClass.class).stream().filter(m -> m.getName().equals("someOperation")).findFirst());
ParameterModel parameter = mockParameterModel(Shape.class);
OutputModel resultList = mockOutputModel(new TypeToken<List<Result<Apple, VeganAttributes>>>() {
}.getType());
OperationModel secondOperation = mockOperationModel(resultList, mockOutputModel(List.class), parameter);
withMethod(secondOperation, empty());
when(extensionModel.getOperationModels()).thenReturn(asList(firstOperation, secondOperation));
visitableMock(firstOperation, secondOperation);
}
use of org.mule.runtime.extension.api.runtime.operation.Result in project mule by mulesoft.
the class DefaultExtensionsClient method executeAsync.
/**
* {@inheritDoc}
*/
@Override
public <T, A> CompletableFuture<Result<T, A>> executeAsync(String extension, String operation, OperationParameters parameters) {
OperationMessageProcessor processor = createProcessor(extension, operation, parameters);
Mono<Result<T, A>> resultMono = process(processor).map(event -> Result.<T, A>builder(event.getMessage()).build()).onErrorMap(Exceptions::unwrap).doAfterTerminate(() -> disposeProcessor(processor));
return resultMono.toFuture();
}
use of org.mule.runtime.extension.api.runtime.operation.Result in project mule by mulesoft.
the class AbstractReturnDelegate method resolveMediaType.
/**
* If provided, mimeType and encoding configured as operation parameters will take precedence over what comes with the message's
* {@link DataType}.
*
* @param value
* @param operationContext
* @return
*/
protected MediaType resolveMediaType(Object value, ExecutionContextAdapter<ComponentModel> operationContext) {
Charset existingEncoding = getDefaultEncoding(muleContext);
MediaType mediaType = defaultMediaType;
if (value instanceof Result) {
final Optional<MediaType> optionalMediaType = ((Result) value).getMediaType();
if (optionalMediaType.isPresent()) {
mediaType = optionalMediaType.get();
if (mediaType.getCharset().isPresent()) {
existingEncoding = mediaType.getCharset().get();
}
}
}
if (mediaType == null) {
mediaType = ANY;
}
if (operationContext.hasParameter(MIME_TYPE_PARAMETER_NAME)) {
mediaType = MediaType.parse(operationContext.getParameter(MIME_TYPE_PARAMETER_NAME));
}
if (operationContext.hasParameter(ENCODING_PARAMETER_NAME)) {
mediaType = mediaType.withCharset(parseCharset(operationContext.getParameter(ENCODING_PARAMETER_NAME)));
} else {
mediaType = mediaType.withCharset(existingEncoding);
}
return mediaType;
}
use of org.mule.runtime.extension.api.runtime.operation.Result in project mule by mulesoft.
the class ExportedArtifactsCollectorTestCase method setup.
@Before
public void setup() {
ClassLoaderModelProperty classLoaderModelProperty = new ClassLoaderModelProperty(getClass().getClassLoader());
when(extensionModel.getModelProperty(ClassLoaderModelProperty.class)).thenReturn(of(classLoaderModelProperty));
OutputModel appleList = mockOutputModel(new TypeToken<List<Apple>>() {
}.getType());
OperationModel firstOperation = mockOperationModel(appleList, mockOutputModel(List.class));
withMethod(firstOperation, getApiMethods(HeisenbergOperations.class).stream().filter(m -> m.getName().equals("callGusFring")).findFirst());
ParameterModel parameter = mockParameterModel(Shape.class);
OutputModel resultList = mockOutputModel(new TypeToken<List<Result<Apple, VeganAttributes>>>() {
}.getType());
OperationModel secondOperation = mockOperationModel(resultList, mockOutputModel(List.class), parameter);
withMethod(secondOperation, empty());
when(extensionModel.getOperationModels()).thenReturn(asList(firstOperation, secondOperation));
visitableMock(firstOperation, secondOperation);
collector = new ExportedArtifactsCollector(extensionModel);
}
use of org.mule.runtime.extension.api.runtime.operation.Result in project mule by mulesoft.
the class ReflectiveHttpConfigBasedRequester method getHttpHeaders.
/**
* Reflectively introspects the result to find the HTTP Headers.
*
* @param result the {@link Result} returned by the http request operation
*/
private Map<String, String> getHttpHeaders(Result<Object, Object> result) {
try {
Optional httpAttributes = result.getAttributes();
if (!httpAttributes.isPresent()) {
throw new IllegalStateException("No Http Attributes found on the response, cannot get response headers.");
}
Object headers = httpAttributes.get().getClass().getMethod("getHeaders").invoke(httpAttributes.get());
Map<String, List<String>> map = (Map<String, List<String>>) headers.getClass().getMethod("toListValuesMap").invoke(headers);
return map.entrySet().stream().collect(toMap(e -> e.getKey(), e -> e.getValue().stream().collect(joining(" "))));
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalStateException("Something went wrong when introspecting the http response attributes.", e);
}
}
Aggregations