Adding possibility to reload the plugins
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user