コード例 #1
0
  @OnClassLoadEvent(classNameRegexp = "org.jboss.resteasy.plugins.server.servlet.FilterDispatcher")
  public static void patchFilterDispatcher(CtClass ctClass, ClassPool classPool)
      throws NotFoundException, CannotCompileException {

    CtClass fltCfgClass = classPool.get("javax.servlet.FilterConfig");
    CtField configField = new CtField(fltCfgClass, FIELD_NAME, ctClass);
    ctClass.addField(configField);

    CtClass setClass = classPool.get(java.util.Set.class.getName());
    CtField paramsField = new CtField(setClass, PARAMETER_FIELD_NAME, ctClass);
    ctClass.addField(paramsField);

    CtMethod methInit = ctClass.getDeclaredMethod("init");
    methInit.insertBefore(
        "{"
            + "   if(this."
            + PARAMETER_FIELD_NAME
            + " == null) {"
            + PluginManagerInvoker.buildInitializePlugin(ResteasyPlugin.class)
            + PluginManagerInvoker.buildCallPluginMethod(
                ResteasyPlugin.class, "registerDispatcher", "this", "java.lang.Object")
            + "   }"
            + "   this."
            + FIELD_NAME
            + " = $1;"
            + "   this."
            + PARAMETER_FIELD_NAME
            + " = "
            + ResteasyContextParams.class.getName()
            + ".init($1.getServletContext(), this."
            + PARAMETER_FIELD_NAME
            + "); "
            + "}");
  }
コード例 #2
0
ファイル: JettyPlugin.java プロジェクト: LTTDev/HotswapAgent
  // 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;
    }
  }
コード例 #3
0
ファイル: TomcatPlugin.java プロジェクト: 4n4n4s/HotswapAgent
  /** Init the plugin from start method. */
  @Transform(classNameRegexp = "org.apache.catalina.loader.WebappLoader")
  public static void patchWebappLoader(CtClass ctClass)
      throws NotFoundException, CannotCompileException, ClassNotFoundException {

    try {
      CtMethod startInternalMethod = ctClass.getDeclaredMethod("startInternal");
      // init the plugin
      String src = PluginManagerInvoker.buildInitializePlugin(TomcatPlugin.class, "classLoader");

      startInternalMethod.insertAfter(src);
    } catch (NotFoundException e) {
      LOGGER.warning(
          "org.apache.catalina.loader.WebappLoader does not contain startInternal method. Tomcat plugin will be disabled.\n"
              + "*** This is Ok, Tomcat plugin handles only special properties ***");
      return;
    }
  }