final String contextName = FilenameUtils.getBaseName(tempDir.toString());
serverId = contextName;
}
WebappMuleXmlConfigurationBuilder builder = new WebappMuleXmlConfigurationBuilder(servletContext, configResource);
MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
String muleAppConfig = servletContext.getInitParameter(INIT_PARAMETER_MULE_APP_CONFIG) != null
? servletContext.getInitParameter(INIT_PARAMETER_MULE_APP_CONFIG)
: PropertiesMuleConfigurationFactory.getMuleAppConfiguration(configResource);
DefaultMuleConfiguration muleConfiguration = new PropertiesMuleConfigurationFactory(muleAppConfig).createConfiguration();
/*
We deliberately enable container mode here to allow for multi-tenant environment (multiple WARs
embedding Mule instance each). See property javadocs for more info.
*/
muleConfiguration.setContainerMode(true);
if (serverId != null)
{
muleConfiguration.setId(serverId);
}
MuleContextBuilder muleContextBuilder = new DefaultMuleContextBuilder();
muleContextBuilder.setMuleConfiguration(muleConfiguration);
// Support Spring-first configuration in webapps
final ApplicationContext parentContext = (ApplicationContext) servletContext.getAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
if (parentContext != null)
{
builder.setParentContext(parentContext);
}
return muleContextFactory.createMuleContext(builder, muleContextBuilder);
}