Search in sources :

Example 1 with WarResourceFetcher

use of org.bimserver.resources.WarResourceFetcher in project BIMserver by opensourceBIM.

the class WarServerInitializer method contextInitialized.

public void contextInitialized(ServletContextEvent servletContextEvent) {
    ServletContext servletContext = servletContextEvent.getServletContext();
    Path homeDir = null;
    if (servletContext.getAttribute("homedir") != null) {
        homeDir = Paths.get((String) servletContext.getAttribute("homedir"));
    }
    if (homeDir == null && servletContext.getInitParameter("homedir") != null) {
        homeDir = Paths.get(servletContext.getInitParameter("homedir"));
    }
    boolean autoMigrate = false;
    if (servletContext.getAttribute("autoMigrate") != null) {
        autoMigrate = (Boolean) servletContext.getAttribute("autoMigrate");
    }
    if (autoMigrate == false && servletContext.getInitParameter("autoMigrate") != null) {
        autoMigrate = Boolean.valueOf(servletContext.getInitParameter("autoMigrate"));
    }
    String realPath = servletContext.getRealPath("/");
    if (!realPath.endsWith("/")) {
        realPath = realPath + "/";
    }
    Path baseDir = Paths.get(realPath + "WEB-INF");
    if (homeDir == null) {
        homeDir = baseDir;
    }
    ResourceFetcher resourceFetcher = new WarResourceFetcher(servletContext, homeDir);
    BimServerConfig config = new BimServerConfig();
    config.setAutoMigrate(autoMigrate);
    config.setEnvironment(Environment.WAR);
    config.setHomeDir(homeDir);
    config.setResourceFetcher(resourceFetcher);
    if (homeDir != null) {
        // Basically doing this twice (also in BimServer.init), but this makes sure the logback.xml file is copied to the homedir
        try {
            BimServer.initHomeDir(config);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    setupLogging(homeDir);
    try {
        fixLogging(config);
        config.setClassPath(makeClassPath(resourceFetcher.getFile("lib")));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    config.setStartEmbeddedWebServer(false);
    bimServer = new BimServer(config);
    Jsr356Impl.setDefaultServletContext(servletContextEvent.getServletContext());
    Logger LOGGER = LoggerFactory.getLogger(WarServerInitializer.class);
    LOGGER.info("Servlet Context Name: " + servletContext.getServletContextName());
    try {
        bimServer.start();
    } catch (ServerException e) {
        LOGGER.error("", e);
    } catch (DatabaseInitException e) {
        LOGGER.error("", e);
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    } catch (PluginException e) {
        LOGGER.error("", e);
    } catch (DatabaseRestartRequiredException e) {
        LOGGER.error("", e);
    }
    servletContext.setAttribute("bimserver", bimServer);
}
Also used : Path(java.nio.file.Path) ServerException(org.bimserver.shared.exceptions.ServerException) WarResourceFetcher(org.bimserver.resources.WarResourceFetcher) BimServer(org.bimserver.BimServer) PluginException(org.bimserver.shared.exceptions.PluginException) WarResourceFetcher(org.bimserver.resources.WarResourceFetcher) ResourceFetcher(org.bimserver.plugins.ResourceFetcher) IOException(java.io.IOException) BimServerConfig(org.bimserver.BimServerConfig) Logger(org.slf4j.Logger) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ServletContext(javax.servlet.ServletContext) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException)

Aggregations

IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ServletContext (javax.servlet.ServletContext)1 BimServer (org.bimserver.BimServer)1 BimServerConfig (org.bimserver.BimServerConfig)1 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)1 DatabaseRestartRequiredException (org.bimserver.database.DatabaseRestartRequiredException)1 DatabaseInitException (org.bimserver.database.berkeley.DatabaseInitException)1 ResourceFetcher (org.bimserver.plugins.ResourceFetcher)1 WarResourceFetcher (org.bimserver.resources.WarResourceFetcher)1 PluginException (org.bimserver.shared.exceptions.PluginException)1 ServerException (org.bimserver.shared.exceptions.ServerException)1 Logger (org.slf4j.Logger)1