@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
            + "); "
            + "}");
  }
Exemple #2
0
  // 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;
    }
  }