use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class ProcessorChainExecutorTestCase method testDoProcessOnErrorMessagingException.
@Test
public void testDoProcessOnErrorMessagingException() throws InterruptedException, MuleException {
final String ERROR_PAYLOAD = "ERROR_PAYLOAD";
when(chain.apply(any())).thenReturn(error(new MessagingException(createStaticMessage(""), getEventBuilder().message(of(ERROR_PAYLOAD)).build())));
ImmutableProcessorChainExecutor chainExecutor = new ImmutableProcessorChainExecutor(coreEvent, chain);
AtomicInteger successCalls = new AtomicInteger(0);
AtomicInteger errorCalls = new AtomicInteger(0);
Reference<Event> errorEvent = new Reference<>();
doProcessAndWait(chainExecutor, r -> successCalls.incrementAndGet(), (t, r) -> {
errorCalls.incrementAndGet();
errorEvent.set(((EventedResult) r).getEvent());
});
assertThat(successCalls.get(), is(0));
assertThat(errorCalls.get(), is(1));
assertThat(errorEvent.get().getMessage().getPayload().getValue(), is(ERROR_PAYLOAD));
}
use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareElement.
private void declareElement(final ConfigLine configLine, final ArtifactDeclarer artifactDeclarer) {
final ExtensionModel ownerExtension = getExtensionModel(configLine);
final ElementDeclarer extensionElementsDeclarer = forExtension(ownerExtension.getName());
final DslSyntaxResolver dsl = resolvers.get(getNamespace(configLine));
Reference<Boolean> alreadyDeclared = new Reference<>(false);
new ExtensionWalker() {
@Override
protected void onConstruct(HasConstructModels owner, ConstructModel model) {
declareComponentModel(configLine, model, extensionElementsDeclarer::newConstruct).ifPresent(declarer -> {
getDeclaredName(configLine).ifPresent(((ConstructElementDeclarer) declarer)::withRefName);
artifactDeclarer.withGlobalElement((GlobalElementDeclaration) declarer.getDeclaration());
alreadyDeclared.set(true);
stop();
});
}
@Override
protected void onConfiguration(ConfigurationModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
if (elementDsl.getElementName().equals(configLine.getIdentifier())) {
ConfigurationElementDeclarer configurationDeclarer = extensionElementsDeclarer.newConfiguration(model.getName());
getDeclaredName(configLine).ifPresent(configurationDeclarer::withRefName);
Map<String, SimpleConfigAttribute> attributes = configLine.getConfigAttributes().values().stream().filter(a -> !a.getName().equals(NAME_ATTRIBUTE_NAME)).collect(toMap(SimpleConfigAttribute::getName, a -> a));
List<ConfigLine> configComplexParameters = configLine.getChildren().stream().filter(config -> declareAsConnectionProvider(ownerExtension, model, configurationDeclarer, config, extensionElementsDeclarer)).collect(toList());
declareParameterizedComponent(model, elementDsl, configurationDeclarer, attributes, configComplexParameters);
artifactDeclarer.withGlobalElement(configurationDeclarer.getDeclaration());
alreadyDeclared.set(true);
stop();
}
}
}.walk(ownerExtension);
if (!alreadyDeclared.get()) {
ownerExtension.getTypes().stream().filter(type -> dsl.resolve(type).map(typeDsl -> typeDsl.getElementName().equals(configLine.getIdentifier())).orElse(false)).findFirst().ifPresent(type -> {
TopLevelParameterDeclarer topLevelParameter = extensionElementsDeclarer.newGlobalParameter(configLine.getIdentifier());
getDeclaredName(configLine).ifPresent(topLevelParameter::withRefName);
type.accept(getParameterDeclarerVisitor(configLine, dsl.resolve(type).get(), value -> topLevelParameter.withValue((ParameterObjectValue) value)));
artifactDeclarer.withGlobalElement(topLevelParameter.getDeclaration());
});
}
}
use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareComposableModel.
private void declareComposableModel(ComposableModel model, DslElementSyntax elementDsl, ConfigLine containerConfig, HasNestedComponentDeclarer declarer) {
containerConfig.getChildren().forEach((ConfigLine child) -> {
ExtensionModel extensionModel = getExtensionModel(child);
ElementDeclarer extensionElementsDeclarer = forExtension(extensionModel.getName());
Reference<Boolean> componentFound = new Reference<>(false);
getComponentDeclaringWalker(declaration -> {
declarer.withComponent(declaration);
componentFound.set(true);
}, child, extensionElementsDeclarer).walk(extensionModel);
if (!componentFound.get()) {
declareRoute(model, elementDsl, child, extensionElementsDeclarer).ifPresent(declarer::withComponent);
}
});
}
use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class DefaultXmlDslElementModelConverter method writeApplicationElement.
private void writeApplicationElement(Element element, DslElementModel<?> elementModel, Element parentNode) {
populateInfrastructureConfiguration(element, elementModel);
if (elementModel.getContainedElements().isEmpty() && elementModel.getValue().isPresent()) {
setTextContentElement(element, elementModel, parentNode);
return;
}
elementModel.getContainedElements().stream().filter(c -> !isInfrastructure(c)).forEach(inner -> {
DslElementSyntax innerDsl = inner.getDsl();
Reference<Boolean> configured = new Reference<>(false);
if (innerDsl.supportsAttributeDeclaration() && inner.getValue().isPresent()) {
getCustomizedValue(inner).ifPresent(value -> {
configured.set(true);
element.setAttribute(innerDsl.getAttributeName(), value);
});
}
if (!configured.get() && innerDsl.supportsChildDeclaration() && inner.isExplicitInDsl()) {
Element childElement = createElement(innerDsl, inner.getConfiguration());
if (isEETransform(childElement)) {
element.appendChild(populateEETransform(inner));
} else {
writeApplicationElement(childElement, inner, element);
}
}
});
if (parentNode != element) {
parentNode.appendChild(element);
}
}
Aggregations