use of org.hotswap.agent.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.
the class Jersey2Plugin method jerseyServletCallInitialized.
/**
* Initialize the plugin when Jersey's ServletContainer.init(WebConfig config) is called. This is called from both init() for a servlet
* and init(Config) for a filter.
*
* 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);");
}
use of org.hotswap.agent.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.
the class Jersey2Plugin method fixAnnoationAcceptingListener.
/**
* Fix a scanning issue with jersey pre-2.4 versions. https://java.net/jira/browse/JERSEY-1936
*/
@OnClassLoadEvent(classNameRegexp = "org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener")
public static void fixAnnoationAcceptingListener(CtClass ctClass) throws NotFoundException, CannotCompileException {
CtMethod process = ctClass.getDeclaredMethod("process");
process.insertAfter("try { $2.close(); } catch (Exception e) {}");
}
use of org.hotswap.agent.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.
the class Jersey2Plugin method fixSingleHk2LocatorManager.
/**
* Fix CDI CDI_MULTIPLE_LOCATORS_INTO_SIMPLE_APP exception on class redefinition
*/
@OnClassLoadEvent(classNameRegexp = "org.glassfish.jersey.ext.cdi1x.internal.SingleHk2LocatorManager")
public static void fixSingleHk2LocatorManager(CtClass ctClass) throws NotFoundException, CannotCompileException {
CtMethod process = ctClass.getDeclaredMethod("registerLocator");
process.insertBefore("if (this.locator != null) return;");
LOGGER.debug("SingleHk2LocatorManager : patched()");
}
use of org.hotswap.agent.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.
the class JettyPlugin method patchWebXmlConfiguration6x.
// same as above for older jetty versions
@OnClassLoadEvent(classNameRegexp = "org.mortbay.jetty.webapp.WebXmlConfiguration")
public static void patchWebXmlConfiguration6x(CtClass ctClass) throws NotFoundException, CannotCompileException, ClassNotFoundException {
try {
// after application context initialized, but before processing started
CtMethod doStart = ctClass.getDeclaredMethod("configureWebApp");
// init the plugin
String src = PluginManagerInvoker.buildInitializePlugin(JettyPlugin.class, "getWebAppContext().getClassLoader()");
src += PluginManagerInvoker.buildCallPluginMethod("getWebAppContext().getClassLoader()", JettyPlugin.class, "init", "getWebAppContext()", "java.lang.Object");
doStart.insertBefore(src);
} catch (NotFoundException e) {
LOGGER.warning("org.mortbay.jetty.webapp.WebXmlConfiguration does not contain startContext method. Jetty plugin will be disabled.\n" + "*** This is Ok, Jetty plugin handles only special properties ***");
return;
}
}
use of org.hotswap.agent.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.
the class MojarraPlugin method facesApplicationAssociateInitialized.
@OnClassLoadEvent(classNameRegexp = "com.sun.faces.application.ApplicationResourceBundle")
public static void facesApplicationAssociateInitialized(CtClass ctClass) throws NotFoundException, CannotCompileException {
String registerResourceBundle = PluginManagerInvoker.buildCallPluginMethod(MojarraPlugin.class, "registerApplicationResourceBundle", "baseName", "java.lang.String", "resources", "java.lang.Object");
String buildInitializePlugin = PluginManagerInvoker.buildInitializePlugin(MojarraPlugin.class);
for (CtConstructor constructor : ctClass.getDeclaredConstructors()) {
constructor.insertAfter(buildInitializePlugin);
constructor.insertAfter(registerResourceBundle);
}
LOGGER.debug("com.sun.faces.application.ApplicationAssociate enhanced with resource bundles registration.");
}
Aggregations