Moved the logic to the plugin loader which makes the context listener obsolete
This commit is contained in:
parent
219b38315b
commit
487bc71df1
@ -1,31 +0,0 @@
|
|||||||
package org.owasp.webgoat.plugins;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContextEvent;
|
|
||||||
import javax.servlet.ServletContextListener;
|
|
||||||
import javax.servlet.annotation.WebListener;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy the plugins to the WEB-INF/lib directory to take advantage of the automatic reloading of an application
|
|
||||||
* server.
|
|
||||||
*/
|
|
||||||
@WebListener
|
|
||||||
public class PluginContextListener implements ServletContextListener {
|
|
||||||
|
|
||||||
private static boolean alreadyLoaded = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void contextInitialized(ServletContextEvent event) {
|
|
||||||
String pluginPath = event.getServletContext().getRealPath("plugin_lessons");
|
|
||||||
String targetPath = event.getServletContext().getRealPath("plugin_extracted");
|
|
||||||
|
|
||||||
if (!alreadyLoaded) {
|
|
||||||
new PluginsLoader(Paths.get(pluginPath), Paths.get(targetPath)).copyJars();
|
|
||||||
alreadyLoaded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void contextDestroyed(ServletContextEvent event) {
|
|
||||||
}
|
|
||||||
}
|
|
@ -32,6 +32,7 @@ import java.util.concurrent.Executors;
|
|||||||
public class PluginsLoader {
|
public class PluginsLoader {
|
||||||
|
|
||||||
private static final String WEBGOAT_PLUGIN_EXTENSION = "jar";
|
private static final String WEBGOAT_PLUGIN_EXTENSION = "jar";
|
||||||
|
private static boolean alreadyLoaded = false;
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
private final Path pluginSource;
|
private final Path pluginSource;
|
||||||
private Path pluginTarget;
|
private Path pluginTarget;
|
||||||
@ -52,6 +53,7 @@ public class PluginsLoader {
|
|||||||
*/
|
*/
|
||||||
public void copyJars() {
|
public void copyJars() {
|
||||||
try {
|
try {
|
||||||
|
if (!alreadyLoaded) {
|
||||||
WebappClassLoader cl = (WebappClassLoader) Thread.currentThread().getContextClassLoader();
|
WebappClassLoader cl = (WebappClassLoader) Thread.currentThread().getContextClassLoader();
|
||||||
cl.setAntiJARLocking(true);
|
cl.setAntiJARLocking(true);
|
||||||
|
|
||||||
@ -62,8 +64,10 @@ public class PluginsLoader {
|
|||||||
Path sourceJarFile = Paths.get(jar.toURI());
|
Path sourceJarFile = Paths.get(jar.toURI());
|
||||||
FileUtils.copyFileToDirectory(sourceJarFile.toFile(), webInfLib.toFile());
|
FileUtils.copyFileToDirectory(sourceJarFile.toFile(), webInfLib.toFile());
|
||||||
}
|
}
|
||||||
|
alreadyLoaded = true;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Loading plugins failed", e);
|
logger.error("Copying plugins failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +77,7 @@ public class PluginsLoader {
|
|||||||
* @return a {@link java.util.List} object.
|
* @return a {@link java.util.List} object.
|
||||||
*/
|
*/
|
||||||
public List<Plugin> loadPlugins() {
|
public List<Plugin> loadPlugins() {
|
||||||
|
copyJars();
|
||||||
List<Plugin> plugins = Lists.newArrayList();
|
List<Plugin> plugins = Lists.newArrayList();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user