Search in sources :

Example 16 with OnClassLoadEvent

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);");
}
Also used : CtMethod(org.hotswap.agent.javassist.CtMethod) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 17 with OnClassLoadEvent

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) {}");
}
Also used : CtMethod(org.hotswap.agent.javassist.CtMethod) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 18 with OnClassLoadEvent

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()");
}
Also used : CtMethod(org.hotswap.agent.javassist.CtMethod) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 19 with OnClassLoadEvent

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;
    }
}
Also used : NotFoundException(org.hotswap.agent.javassist.NotFoundException) CtMethod(org.hotswap.agent.javassist.CtMethod) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 20 with OnClassLoadEvent

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.");
}
Also used : CtConstructor(org.hotswap.agent.javassist.CtConstructor) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Aggregations

OnClassLoadEvent (org.hotswap.agent.annotation.OnClassLoadEvent)50 CtMethod (org.hotswap.agent.javassist.CtMethod)29 CtConstructor (org.hotswap.agent.javassist.CtConstructor)16 CtClass (org.hotswap.agent.javassist.CtClass)13 CtField (org.hotswap.agent.javassist.CtField)10 NotFoundException (org.hotswap.agent.javassist.NotFoundException)10 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)9 ExprEditor (org.hotswap.agent.javassist.expr.ExprEditor)5 IOException (java.io.IOException)4 WeldPlugin (org.hotswap.agent.plugin.weld.WeldPlugin)4 Method (java.lang.reflect.Method)3 MalformedURLException (java.net.MalformedURLException)3 URISyntaxException (java.net.URISyntaxException)3 MethodCall (org.hotswap.agent.javassist.expr.MethodCall)3 URL (java.net.URL)2 Set (java.util.Set)2 DeltaSpikePlugin (org.hotswap.agent.plugin.deltaspike.DeltaSpikePlugin)2 ClassFileTransformer (java.lang.instrument.ClassFileTransformer)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1