use of org.mule.runtime.core.api.config.ConfigurationException in project mule by mulesoft.
the class DefaultMuleContextFactoryTestCase method testCreateMuleContextStringProperties.
@Test
public void testCreateMuleContextStringProperties() throws InitialisationException, ConfigurationException {
Properties properties = new Properties();
properties.put("testKey1", "testValue1");
properties.put("testKey2", "testValue2");
context = null;
try {
context = muleContextFactory.createMuleContext("log4j2-test.xml", (Map) properties);
} catch (ConfigurationException e) {
assertThat(e.getMessage(), equalTo("No suitable configuration builder for resource \"[ConfigResource{resourceName='log4j2-test.xml'}]\" found. " + "Check you have configuration module on your classpath and are using correct file extension."));
}
assertNull(context);
}
use of org.mule.runtime.core.api.config.ConfigurationException in project mule by mulesoft.
the class AutoConfigurationBuilder method autoConfigure.
protected void autoConfigure(MuleContext muleContext, ConfigResource[] resources) throws ConfigurationException {
Map<String, List<ConfigResource>> configsMap = new LinkedHashMap<String, List<ConfigResource>>();
for (ConfigResource resource : resources) {
String configExtension = substringAfterLast(resource.getUrl().getPath(), ".");
List<ConfigResource> configs = configsMap.get(configExtension);
if (configs == null) {
configs = new ArrayList<ConfigResource>();
configsMap.put(configExtension, configs);
}
configs.add(resource);
}
try {
Properties props = loadProperties(getResource("configuration-builders.properties", this.getClass()).openStream());
for (Map.Entry<String, List<ConfigResource>> e : configsMap.entrySet()) {
String extension = e.getKey();
List<ConfigResource> configs = e.getValue();
String className = (String) props.get(extension);
if (className == null || !ClassUtils.isClassOnPath(className, this.getClass())) {
throw new ConfigurationException(configurationBuilderNoMatching(createConfigResourcesString()));
}
ConfigurationBuilder cb = (ConfigurationBuilder) ClassUtils.instantiateClass(className, new Object[] { configs.stream().map(ConfigResource::getResourceName).toArray(String[]::new), getArtifactProperties(), artifactType });
if (parentContext != null && cb instanceof ParentMuleContextAwareConfigurationBuilder) {
((ParentMuleContextAwareConfigurationBuilder) cb).setParentContext(parentContext);
} else if (parentContext != null) {
throw new MuleRuntimeException(createStaticMessage(format("ConfigurationBuilder %s does not support domain context", cb.getClass().getCanonicalName())));
}
cb.configure(muleContext);
}
} catch (ConfigurationException e) {
throw e;
} 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 parseRoute.
private void parseRoute(NestedRouteModel routeModel) {
DslElementSyntax routeDsl = dslResolver.resolve(routeModel);
Class<?> type = routeModel.getModelProperty(ImplementingTypeModelProperty.class).map(ImplementingTypeModelProperty::getType).orElseThrow(() -> new IllegalStateException("Missing route information"));
MetadataType metadataType = typeLoader.load(type);
addParameter(getChildKey(routeModel.getName()), new DefaultObjectParsingDelegate().parse(routeModel.getName(), (ObjectType) metadataType, routeDsl));
try {
new RouteComponentParser(baseDefinitionBuilder, routeModel, metadataType, getContextClassLoader(), routeDsl, dslResolver, parsingContext).parse().forEach(this::addDefinition);
} catch (Exception e) {
throw new MuleRuntimeException(new ConfigurationException(e));
}
}
use of org.mule.runtime.core.api.config.ConfigurationException in project mule by mulesoft.
the class ExtensionDefinitionParser method parseObjectParameter.
/**
* Registers a definition for a {@link ParameterModel} which represents an {@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 type an {@link ObjectType}
* @param defaultValue the parameter's default value
* @param expressionSupport the parameter's {@link ExpressionSupport}
* @param required whether the parameter is required or not
* @param modelProperties parameter's {@link ModelProperty}s
*/
protected void parseObjectParameter(String key, String name, ObjectType type, Object defaultValue, ExpressionSupport expressionSupport, boolean required, boolean acceptsReferences, DslElementSyntax elementDsl, Set<ModelProperty> modelProperties) {
parseObject(key, name, type, defaultValue, expressionSupport, required, acceptsReferences, elementDsl, modelProperties);
final String elementNamespace = elementDsl.getPrefix();
final String elementName = elementDsl.getElementName();
if (elementDsl.supportsChildDeclaration() && !elementDsl.isWrapped() && modelProperties.stream().noneMatch(m -> m.getName().equals(InfrastructureParameterModelProperty.NAME))) {
try {
new ObjectTypeParameterParser(baseDefinitionBuilder, elementName, elementNamespace, type, getContextClassLoader(), dslResolver, parsingContext).parse().forEach(this::addDefinition);
} catch (Exception e) {
throw new MuleRuntimeException(new ConfigurationException(e));
}
}
}
use of org.mule.runtime.core.api.config.ConfigurationException in project mule by mulesoft.
the class DefaultConfigurationProviderFactory method createStaticConfigurationProvider.
/**
* {@inheritDoc}
*/
@Override
public ConfigurationProvider createStaticConfigurationProvider(String name, ExtensionModel extensionModel, ConfigurationModel configurationModel, ResolverSet resolverSet, ConnectionProviderValueResolver connectionProviderResolver, ReflectionCache reflectionCache, MuleContext muleContext) throws Exception {
return withExtensionClassLoader(extensionModel, () -> {
configureConnectionProviderResolver(name, connectionProviderResolver);
ConfigurationInstance configuration;
CoreEvent initialiserEvent = null;
try {
initialiserEvent = getInitialiserEvent(muleContext);
initialiseIfNeeded(resolverSet, true, muleContext);
configuration = new ConfigurationInstanceFactory(extensionModel, configurationModel, resolverSet, reflectionCache, muleContext).createConfiguration(name, initialiserEvent, connectionProviderResolver);
} catch (MuleException e) {
throw new ConfigurationException(createStaticMessage(format("Could not create configuration '%s' for the '%s'", name, extensionModel.getName())), e);
} finally {
if (initialiserEvent != null) {
((BaseEventContext) initialiserEvent.getContext()).success();
}
}
return new ConfigurationProviderToolingAdapter(name, extensionModel, configurationModel, configuration, reflectionCache, muleContext);
});
}
Aggregations