use of org.mule.runtime.core.api.config.ConfigurationException in project mule by mulesoft.
the class DefaultMuleContextFactory method createMuleContext.
/**
* Creates a new MuleContext using the given configurationBuilder and configuration. Properties if provided are used to replace
* "property placeholder" value in configuration files.
*/
public MuleContext createMuleContext(final List<ConfigurationBuilder> configurationBuilders, final Map<String, Object> properties, MuleConfiguration configuration) throws InitialisationException, ConfigurationException {
// Create MuleContext
MuleContextBuilder contextBuilder = MuleContextBuilder.builder(APP);
contextBuilder.setMuleConfiguration(configuration);
return doCreateMuleContext(contextBuilder, new ContextConfigurator() {
@Override
public void configure(MuleContext muleContext) throws ConfigurationException {
// Configure with startup properties
if (properties != null && !properties.isEmpty()) {
new SimpleConfigurationBuilder(properties).configure(muleContext);
}
// Configure with configurationBuilder
for (ConfigurationBuilder configurationBuilder : configurationBuilders) {
configurationBuilder.configure(muleContext);
}
}
});
}
use of org.mule.runtime.core.api.config.ConfigurationException in project mule by mulesoft.
the class DefaultMuleContextFactory method doCreateMuleContext.
private MuleContext doCreateMuleContext(MuleContextBuilder muleContextBuilder, ContextConfigurator configurator) throws InitialisationException, ConfigurationException {
MuleContext muleContext = buildMuleContext(muleContextBuilder);
listeners.forEach(l -> l.onCreation(muleContext));
try {
configurator.configure(muleContext);
muleContext.initialise();
} catch (ConfigurationException e) {
if (muleContext != null && !muleContext.isDisposed()) {
try {
muleContext.dispose();
} catch (Exception e1) {
logger.warn("Can not dispose context. " + getMessage(e1));
if (logger.isDebugEnabled()) {
logger.debug("Can not dispose context. " + getStackTrace(e1));
}
}
}
throw e;
}
return muleContext;
}
use of org.mule.runtime.core.api.config.ConfigurationException in project mule by mulesoft.
the class AbstractConfigurationBuilder method configure.
/**
* Will configure a MuleContext object based on the builders configuration settings. This method will delegate the actual
* processing to {@link #doConfigure(org.mule.runtime.core.api.MuleContext)}
*
* @param muleContext The current {@link org.mule.runtime.core.api.MuleContext}
* @throws ConfigurationException if the configuration fails i.e. an object cannot be created or initialised properly
*/
@Override
public void configure(MuleContext muleContext) throws ConfigurationException {
try {
doConfigure(muleContext);
applyLifecycle(muleContext.getLifecycleManager());
} catch (Exception e) {
throw new ConfigurationException(e);
}
}
use of org.mule.runtime.core.api.config.ConfigurationException in project mule by mulesoft.
the class ExtensionDefinitionParser method parseCollectionParameter.
/**
* Registers a definition for a {@link ParameterModel} which represents an {@link ArrayType}
*
* @param key the key that the parsed value should have on the parsed parameter's map
* @param name the parameter's name
* @param arrayType the parameter's {@link ArrayType}
* @param defaultValue the parameter's default value
* @param expressionSupport the parameter's {@link ExpressionSupport}
* @param required whether the parameter is required
*/
protected void parseCollectionParameter(String key, String name, ArrayType arrayType, Object defaultValue, ExpressionSupport expressionSupport, boolean required, DslElementSyntax parameterDsl, Set<ModelProperty> modelProperties) {
parseAttributeParameter(key, name, arrayType, defaultValue, expressionSupport, required, modelProperties);
Class<?> collectionType = ExtensionMetadataTypeUtils.getType(arrayType).orElse(null);
if (Set.class.equals(collectionType)) {
collectionType = HashSet.class;
} else if (Collection.class.equals(collectionType) || Iterable.class.equals(collectionType) || collectionType == null) {
collectionType = List.class;
}
final String collectionElementName = parameterDsl.getElementName();
addParameter(getChildKey(key), fromChildConfiguration(collectionType).withWrapperIdentifier(collectionElementName));
addDefinition(baseDefinitionBuilder.withIdentifier(collectionElementName).withTypeDefinition(fromType(collectionType)).build());
Optional<DslElementSyntax> collectionItemDsl = parameterDsl.getGeneric(arrayType.getType());
if (parameterDsl.supportsChildDeclaration() && collectionItemDsl.isPresent()) {
String itemIdentifier = collectionItemDsl.get().getElementName();
String itemNamespace = collectionItemDsl.get().getPrefix();
arrayType.getType().accept(new BasicTypeMetadataVisitor() {
private void addBasicTypeDefinition(MetadataType metadataType) {
Builder itemDefinitionBuilder = baseDefinitionBuilder.withIdentifier(itemIdentifier).withNamespace(itemNamespace).withTypeDefinition(fromType(ExtensionMetadataTypeUtils.getType(metadataType).orElse(Object.class))).withTypeConverter(value -> resolverOf(name, metadataType, value, getDefaultValue(metadataType).orElse(null), getExpressionSupport(metadataType), false, emptySet()));
addDefinition(itemDefinitionBuilder.build());
}
@Override
protected void visitBasicType(MetadataType metadataType) {
addBasicTypeDefinition(metadataType);
}
@Override
public void visitDate(DateType dateType) {
addBasicTypeDefinition(dateType);
}
@Override
public void visitDateTime(DateTimeType dateTimeType) {
addBasicTypeDefinition(dateTimeType);
}
@Override
public void visitObject(ObjectType objectType) {
if (isMap(objectType)) {
return;
}
DslElementSyntax itemDsl = collectionItemDsl.get();
if ((itemDsl.supportsTopLevelDeclaration() || itemDsl.supportsChildDeclaration()) && !parsingContext.isRegistered(itemDsl.getElementName(), itemDsl.getPrefix())) {
try {
parsingContext.registerObjectType(itemDsl.getElementName(), itemDsl.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 collection complex type"), e);
}
}
}
});
}
}
use of org.mule.runtime.core.api.config.ConfigurationException in project mule by mulesoft.
the class ExceptionHelperTestCase method getNonMuleExceptionCause.
@Test
public void getNonMuleExceptionCause() {
assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), null)), nullValue());
assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), null))), nullValue());
assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), new IllegalArgumentException()))), instanceOf(IllegalArgumentException.class));
assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), new IllegalArgumentException(new NullPointerException())))), instanceOf(IllegalArgumentException.class));
assertThat(getNonMuleException(new IllegalArgumentException()), instanceOf(IllegalArgumentException.class));
}
Aggregations