final AbstractNetworkConnector jettyConnector = createJettyConnector();
configureConnector(jettyConnector, webappsConfiguration.getHost(), webappsConfiguration.getPort());
DeploymentManager deploymentManager = new DeploymentManager();
WebAppProvider webAppProvider = new WebAppProvider()
{
@Override
public ContextHandler createContextHandler(App app) throws Exception
{
WebAppContext webAppContext = (WebAppContext) super.createContextHandler(app);
if (webappsConfiguration.getServerClasses() != null)
{
webAppContext.setServerClasses(webappsConfiguration.getServerClasses());
}
if (webappsConfiguration.getSystemClasses() != null)
{
webAppContext.setSystemClasses(webappsConfiguration.getSystemClasses());
}
File workDir = new File(muleContext.getConfiguration().getWorkingDirectory(),
"_exploded_wars" + webAppContext.getContextPath());
workDir.mkdirs();
webAppContext.setTempDirectory(workDir);
webAppContext.setAttribute(MULE_CONTEXT_ATTRIBUTE, muleContext);
webAppContext.setVirtualHosts(new String[] {getVirtualHostName(jettyConnector)});
if (logger.isInfoEnabled())
{
String msg = String.format("Will deploy a web app at %s://%s%s%s",
"http", jettyConnector.getHost(),
jettyConnector.getPort() == 80 ? StringUtils.EMPTY : ":" + jettyConnector.getPort(),
webAppContext.getContextPath());
logger.info(StringMessageUtils.getBoilerPlate(msg, '*', 70));
}
return webAppContext;
}
};
deploymentManager.setContexts(contexts);
deploymentManager.addAppProvider(webAppProvider);
String webAppDir = webappsConfiguration.getDirectory();
if (StringUtils.isBlank(webAppDir))
{
// if none specified, resolve defaults dynamically
final String appDir = muleContext.getRegistry().get(MuleProperties.APP_HOME_DIRECTORY_PROPERTY);
webAppDir = appDir + "/webapps";
}
if (configFile == null)
{
// override only if user hasn't specified one (turn off file-mapped buffer for
// static files to avoid resource locking, makes webapp resources editable on the fly)
final URL muleDefaults = ClassUtils.getResource("org/mule/transport/jetty/webdefault.xml", getClass());
webAppProvider.setDefaultsDescriptor(muleDefaults.toExternalForm());
}
webAppProvider.setMonitoredDirName(webAppDir);
webAppProvider.setExtractWars(true);
webAppProvider.setParentLoaderPriority(false);
String[] confClasses = new String[]
{
// configures webapp's classloader as a child of a Mule app classloader
WebInfConfiguration.class.getName(),
WebXmlConfiguration.class.getName()
};
webAppProvider.setConfigurationClasses(confClasses);
webAppProvider.setDeploymentManager(deploymentManager);
httpServer.addBean(deploymentManager);
httpServer.addConnector(jettyConnector);
}