*
* Also, add the ServletContainer to a list of registeredJerseyContainers so that we can call reload on it later when classes change
*/
@OnClassLoadEvent(classNameRegexp = "org.glassfish.jersey.servlet.ServletContainer")
public static void jerseyServletCallInitialized(CtClass ctClass, ClassPool classPool) throws NotFoundException, CannotCompileException {
CtMethod init = ctClass.getDeclaredMethod("init", new CtClass[] { classPool.get("org.glassfish.jersey.servlet.WebConfig") });
init.insertBefore(PluginManagerInvoker.buildInitializePlugin(Jersey2Plugin.class));
LOGGER.info("org.glassfish.jersey.servlet.ServletContainer enhanced with plugin initialization.");
String registerThis = PluginManagerInvoker.buildCallPluginMethod(Jersey2Plugin.class, "registerJerseyContainer", "this",
"java.lang.Object", "getConfiguration()", "java.lang.Object");
init.insertAfter(registerThis);
// Workaround a Jersey issue where ServletContainer cannot be reloaded since it is in an immutable state
CtMethod reload = ctClass.getDeclaredMethod("reload", new CtClass[] { classPool.get("org.glassfish.jersey.server.ResourceConfig") });
reload.insertBefore("$1 = new org.glassfish.jersey.server.ResourceConfig($1);");
}