ARTEMIS-1698 support 'instance' web deployments

This commit is contained in:
Justin Bertram 2017-11-17 12:18:21 -06:00 committed by Clebert Suconic
parent af7f74e597
commit d552e4d2c8
1 changed files with 30 additions and 13 deletions

View File

@ -95,12 +95,17 @@ public class WebServerComponent implements ExternalComponent {
handlers = new HandlerList(); handlers = new HandlerList();
Path warDir = Paths.get(artemisHome != null ? artemisHome : ".").resolve(webServerConfig.path).toAbsolutePath(); Path homeWarDir = Paths.get(artemisHome != null ? artemisHome : ".").resolve(webServerConfig.path).toAbsolutePath();
Path instanceWarDir = Paths.get(artemisInstance != null ? artemisInstance : ".").resolve(webServerConfig.path).toAbsolutePath();
if (webServerConfig.apps != null && webServerConfig.apps.size() > 0) { if (webServerConfig.apps != null && webServerConfig.apps.size() > 0) {
webContexts = new ArrayList<>(); webContexts = new ArrayList<>();
for (AppDTO app : webServerConfig.apps) { for (AppDTO app : webServerConfig.apps) {
WebAppContext webContext = deployWar(app.url, app.war, warDir); Path dirToUse = homeWarDir;
if (new File(instanceWarDir.toFile().toString() + File.separator + app.war).exists()) {
dirToUse = instanceWarDir;
}
WebAppContext webContext = deployWar(app.url, app.war, dirToUse);
webContexts.add(webContext); webContexts.add(webContext);
if (app.war.startsWith("console")) { if (app.war.startsWith("console")) {
consoleUrl = webServerConfig.bind + "/" + app.url; consoleUrl = webServerConfig.bind + "/" + app.url;
@ -108,21 +113,33 @@ public class WebServerComponent implements ExternalComponent {
} }
} }
ResourceHandler resourceHandler = new ResourceHandler(); ResourceHandler homeResourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(warDir.toString()); homeResourceHandler.setResourceBase(homeWarDir.toString());
resourceHandler.setDirectoriesListed(false); homeResourceHandler.setDirectoriesListed(false);
resourceHandler.setWelcomeFiles(new String[]{"index.html"}); homeResourceHandler.setWelcomeFiles(new String[]{"index.html"});
ContextHandler homeContext = new ContextHandler();
homeContext.setContextPath("/");
homeContext.setResourceBase(homeWarDir.toString());
homeContext.setHandler(homeResourceHandler);
homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
ResourceHandler instanceResourceHandler = new ResourceHandler();
instanceResourceHandler.setResourceBase(instanceWarDir.toString());
instanceResourceHandler.setDirectoriesListed(false);
instanceResourceHandler.setWelcomeFiles(new String[]{"index.html"});
ContextHandler instanceContext = new ContextHandler();
instanceContext.setContextPath("/");
instanceContext.setResourceBase(instanceWarDir.toString());
instanceContext.setHandler(instanceResourceHandler);
homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
DefaultHandler defaultHandler = new DefaultHandler(); DefaultHandler defaultHandler = new DefaultHandler();
defaultHandler.setServeIcon(false); defaultHandler.setServeIcon(false);
ContextHandler context = new ContextHandler(); handlers.addHandler(homeContext);
context.setContextPath("/"); handlers.addHandler(instanceContext);
context.setResourceBase(warDir.toString());
context.setHandler(resourceHandler);
context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
handlers.addHandler(context);
handlers.addHandler(defaultHandler); handlers.addHandler(defaultHandler);
server.setHandler(handlers); server.setHandler(handlers);
} }