Adding possibility to reload the plugins

This commit is contained in:
nbaars
2015-01-05 19:10:36 +01:00
parent 34694b01c0
commit 3525226e68
2 changed files with 32 additions and 1 deletions

View File

@ -0,0 +1,27 @@
package org.owasp.webgoat.plugins;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.nio.file.Paths;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@WebListener
public class PluginBackgroundLoader implements ServletContextListener {
private ScheduledExecutorService scheduler;
@Override
public void contextInitialized(ServletContextEvent event) {
String pluginPath = event.getServletContext().getRealPath("plugin_lessons");
scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new PluginsLoader(Paths.get(pluginPath)), 0, 5, TimeUnit.SECONDS);
}
@Override
public void contextDestroyed(ServletContextEvent event) {
scheduler.shutdownNow();
}
}

View File

@ -12,7 +12,7 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
public class PluginsLoader {
public class PluginsLoader implements Runnable {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Path path;
@ -49,4 +49,8 @@ public class PluginsLoader {
}
@Override
public void run() {
loadPlugins();
}
}