use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class ApplicationPolicyDeploymentTestCase method appliesApplicationPolicyDuplicatingPlugin.
@Test
public void appliesApplicationPolicyDuplicatingPlugin() throws Exception {
policyManager.registerPolicyTemplate(exceptionThrowingPluginImportingPolicyFileBuilder.getArtifactFile());
ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices(APP_WITH_EXTENSION_PLUGIN_CONFIG, exceptionThrowingPlugin, helloExtensionV1Plugin);
addPackedAppFromBuilder(applicationFileBuilder);
startDeployment();
assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
policyManager.addPolicy(applicationFileBuilder.getId(), exceptionThrowingPluginImportingPolicyFileBuilder.getArtifactId(), new PolicyParametrization(EXCEPTION_POLICY_NAME, s -> true, 1, emptyMap(), getResourceFile("/exceptionThrowingPolicy.xml"), emptyList()));
try {
executeApplicationFlow("main");
fail("Flow execution was expected to throw an exception");
} catch (MuleRuntimeException expected) {
assertThat(expected.getCause().getCause().getClass().getName(), is(equalTo("org.exception.CustomException")));
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class MuleDeploymentService method deployTemplateMethod.
private void deployTemplateMethod(final URI artifactArchiveUri, final Optional<Properties> deploymentProperties, File artifactDeploymentFolder, ArchiveDeployer archiveDeployer) throws IOException {
executeSynchronized(() -> {
try {
File artifactLocation = toFile(artifactArchiveUri.toURL());
String fileName = artifactLocation.getName();
if (fileName.endsWith(".jar")) {
archiveDeployer.deployPackagedArtifact(artifactArchiveUri, deploymentProperties);
} else {
if (!artifactLocation.getParent().equals(artifactDeploymentFolder)) {
try {
copyDirectory(artifactLocation, new File(artifactDeploymentFolder, fileName));
} catch (IOException e) {
throw new MuleRuntimeException(e);
}
}
archiveDeployer.deployExplodedArtifact(fileName, deploymentProperties);
}
} catch (MalformedURLException e) {
throw new MuleRuntimeException(e);
}
});
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class DomainDeploymentTestCase method pluginFromDomainUsedInApp.
@Test
public void pluginFromDomainUsedInApp() throws Exception {
addPackedDomainFromBuilder(exceptionThrowingPluginImportingDomain);
ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices("exception-throwing-app.xml").dependingOn(exceptionThrowingPluginImportingDomain);
addPackedAppFromBuilder(applicationFileBuilder);
startDeployment();
try {
executeApplicationFlow("main");
fail("Flow execution was expected to throw an exception");
} catch (MuleRuntimeException expected) {
assertThat(expected.getCause().getCause().getClass().getName(), is(equalTo("org.exception.CustomException")));
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class ExtensionDefinitionParser method parseMapParameters.
/**
* Registers a definition for a {@link ParameterModel} which represents an open {@link ObjectType}
*
* @param key the key that the parsed value should have on the parsed parameter's map
* @param name the parameter's name
* @param dictionaryType the parameter's open {@link ObjectType}
* @param defaultValue the parameter's default value
* @param expressionSupport the parameter's {@link ExpressionSupport}
* @param required whether the parameter is required
*/
protected void parseMapParameters(String key, String name, ObjectType dictionaryType, Object defaultValue, ExpressionSupport expressionSupport, boolean required, DslElementSyntax paramDsl, Set<ModelProperty> modelProperties) {
parseAttributeParameter(key, name, dictionaryType, defaultValue, expressionSupport, required, modelProperties);
Class<? extends Map> mapType = getType(dictionaryType);
if (ConcurrentMap.class.equals(mapType)) {
mapType = ConcurrentHashMap.class;
} else if (Map.class.equals(mapType)) {
mapType = LinkedHashMap.class;
}
final MetadataType valueType = dictionaryType.getOpenRestriction().orElse(typeLoader.load(Object.class));
final Class<?> valueClass = getType(valueType);
final MetadataType keyType = typeLoader.load(String.class);
final Class<?> keyClass = String.class;
final String mapElementName = paramDsl.getElementName();
addParameter(getChildKey(key), fromChildMapConfiguration(String.class, valueClass).withWrapperIdentifier(mapElementName).withDefaultValue(defaultValue));
addDefinition(baseDefinitionBuilder.withIdentifier(mapElementName).withTypeDefinition(fromType(mapType)).build());
Optional<DslElementSyntax> mapValueChildDsl = paramDsl.getGeneric(valueType);
if (!mapValueChildDsl.isPresent()) {
return;
}
DslElementSyntax valueDsl = mapValueChildDsl.get();
valueType.accept(new MetadataTypeVisitor() {
@Override
protected void defaultVisit(MetadataType metadataType) {
String parameterName = paramDsl.getAttributeName();
addDefinition(baseDefinitionBuilder.withIdentifier(valueDsl.getElementName()).withTypeDefinition(fromMapEntryType(keyClass, valueClass)).withKeyTypeConverter(value -> resolverOf(parameterName, keyType, value, null, expressionSupport, true, emptySet(), false)).withTypeConverter(value -> resolverOf(parameterName, valueType, value, null, expressionSupport, true, emptySet(), false)).build());
}
@Override
public void visitObject(ObjectType objectType) {
defaultVisit(objectType);
Optional<DslElementSyntax> containedElement = valueDsl.getContainedElement(VALUE_ATTRIBUTE_NAME);
if (isMap(objectType) || !containedElement.isPresent()) {
return;
}
DslElementSyntax valueChild = containedElement.get();
if ((valueChild.supportsTopLevelDeclaration() || (valueChild.supportsChildDeclaration() && !valueChild.isWrapped())) && !parsingContext.isRegistered(valueChild.getElementName(), valueChild.getPrefix())) {
try {
parsingContext.registerObjectType(valueChild.getElementName(), valueChild.getPrefix(), objectType);
new ObjectTypeParameterParser(baseDefinitionBuilder, objectType, getContextClassLoader(), dslResolver, parsingContext).parse().forEach(definition -> addDefinition(definition));
} catch (ConfigurationException e) {
throw new MuleRuntimeException(createStaticMessage("Could not create parser for map complex type"), e);
}
}
}
@Override
public void visitArrayType(ArrayType arrayType) {
defaultVisit(arrayType);
Optional<DslElementSyntax> valueListGenericDsl = valueDsl.getGeneric(arrayType.getType());
if (valueDsl.supportsChildDeclaration() && valueListGenericDsl.isPresent()) {
arrayType.getType().accept(new BasicTypeMetadataVisitor() {
@Override
protected void visitBasicType(MetadataType metadataType) {
String parameterName = paramDsl.getAttributeName();
addDefinition(baseDefinitionBuilder.withIdentifier(valueListGenericDsl.get().getElementName()).withTypeDefinition(fromType(getType(metadataType))).withTypeConverter(value -> resolverOf(parameterName, metadataType, value, getDefaultValue(metadataType), getExpressionSupport(metadataType), false, emptySet())).build());
}
@Override
protected void defaultVisit(MetadataType metadataType) {
addDefinition(baseDefinitionBuilder.withIdentifier(valueListGenericDsl.get().getElementName()).withTypeDefinition(fromType(ValueResolver.class)).withObjectFactoryType(TopLevelParameterObjectFactory.class).withConstructorParameterDefinition(fromFixedValue(arrayType.getType()).build()).withConstructorParameterDefinition(fromFixedValue(getContextClassLoader()).build()).build());
}
});
}
}
});
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class ExtensionDefinitionParser method parseObject.
protected void parseObject(String key, String name, ObjectType type, Object defaultValue, ExpressionSupport expressionSupport, boolean required, boolean acceptsReferences, DslElementSyntax elementDsl, Set<ModelProperty> modelProperties) {
parseAttributeParameter(key, name, type, defaultValue, expressionSupport, required, acceptsReferences, modelProperties);
ObjectParsingDelegate delegate = (ObjectParsingDelegate) locateParsingDelegate(objectParsingDelegates, type).orElseThrow(() -> new MuleRuntimeException(createStaticMessage("Could not find a parsing delegate for type " + getType(type).getName())));
addParameter(getChildKey(key), delegate.parse(name, type, elementDsl));
}
Aggregations