Skip to content

Commit

Permalink
Use DefaultServlet instead of ResourceHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Sep 29, 2018
1 parent 3179094 commit f8e2c91
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/org/traccar/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public static void init(String configFile) throws Exception {
}

if (config.getBoolean("web.enable")) {
webServer = new WebServer(config, dataManager.getDataSource());
webServer = new WebServer(config);
}

permissionsManager = new PermissionsManager(dataManager, usersManager);
Expand Down
4 changes: 0 additions & 4 deletions src/org/traccar/database/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ public DataManager(Config config) throws Exception {
initDatabaseSchema();
}

public DataSource getDataSource() {
return dataSource;
}

private void initDatabase() throws Exception {

String jndiName = config.getString("database.jndi");
Expand Down
16 changes: 9 additions & 7 deletions src/org/traccar/web/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,20 @@ public void doScope(
}

private void initWebApp() {
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(config.getString("web.path"));
ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
ServletHolder servletHolder = new ServletHolder(DefaultServlet.class);
servletHolder.setInitParameter("resourceBase", config.getString("web.path"));
if (config.getBoolean("web.debug")) {
resourceHandler.setWelcomeFiles(new String[] {"release.html", "index.html"});
servletHandler.setWelcomeFiles(new String[] {"debug.html", "index.html"});
} else {
String cache = config.getString("web.cacheControl");
if (cache != null && !cache.isEmpty()) {
resourceHandler.setCacheControl(cache);
servletHolder.setInitParameter("cacheControl", cache);
}
resourceHandler.setWelcomeFiles(new String[] {"release.html", "index.html"});
servletHandler.setWelcomeFiles(new String[] {"release.html", "index.html"});
}
handlers.addHandler(resourceHandler);
servletHandler.addServlet(servletHolder, "/*");
handlers.addHandler(servletHandler);
}

private void initApi() {
Expand All @@ -141,7 +143,7 @@ private void initApi() {
servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket");

if (config.hasKey("media.path")) {
ServletHolder servletHolder = new ServletHolder("media", DefaultServlet.class);
ServletHolder servletHolder = new ServletHolder(DefaultServlet.class);
servletHolder.setInitParameter("resourceBase", config.getString("media.path"));
servletHolder.setInitParameter("dirAllowed", config.getString("media.dirAllowed", "false"));
servletHolder.setInitParameter("pathInfoOnly", "true");
Expand Down

0 comments on commit f8e2c91

Please sign in to comment.