Exemplo n.º 1
0
  public Object call(
      String cfcPath,
      String id,
      String functionName,
      Struct arguments,
      boolean cfcPeristent,
      Object defaultValue)
      throws PageException {
    DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
    String requestURI = toRequestURI(cfcPath);

    PageContext oldPC = ThreadLocalPageContext.get();
    PageContextImpl pc =
        ThreadUtil.createPageContext(
            config, os, "localhost", requestURI, "", null, null, null, null);
    pc.setRequestTimeout(999999999999999999L);
    try {
      ThreadLocalPageContext.register(pc);
      Component cfc = getCFC(pc, requestURI, cfcPath, id, cfcPeristent);
      if (cfc.containsKey(functionName)) {
        return cfc.callWithNamedValues(pc, functionName, arguments);
      }
    } finally {
      CFMLFactory factory = config.getFactory();
      factory.releasePageContext(pc);
      ThreadLocalPageContext.register(oldPC);
    }
    return defaultValue;
  }
Exemplo n.º 2
0
  private PageContextImpl createPageContext(
      CFMLFactory factory,
      ComponentAccess app,
      String applicationName,
      String cfid,
      Collection.Key methodName)
      throws PageException {
    Resource root = factory.getConfig().getRootDirectory();
    String path = app.getPageSource().getFullRealpath();

    // Request
    HttpServletRequestDummy req =
        new HttpServletRequestDummy(root, "localhost", path, "", null, null, null, null, null);
    if (!StringUtil.isEmpty(cfid))
      req.setCookies(new Cookie[] {new Cookie("cfid", cfid), new Cookie("cftoken", "0")});

    // Response
    OutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
    try {
      Resource out =
          factory
              .getConfig()
              .getConfigDir()
              .getRealResource("output/" + methodName.getString() + ".out");
      out.getParentResource().mkdirs();
      os = out.getOutputStream(false);
    } catch (IOException e) {
      e.printStackTrace();
      // TODO was passiert hier
    }
    HttpServletResponseDummy rsp = new HttpServletResponseDummy(os);

    // PageContext
    PageContextImpl pc =
        (PageContextImpl)
            factory.getRailoPageContext(factory.getServlet(), req, rsp, null, false, -1, false);
    // ApplicationContext
    ClassicApplicationContext ap =
        new ClassicApplicationContext(
            factory.getConfig(),
            applicationName,
            false,
            app == null ? null : ResourceUtil.getResource(pc, app.getPageSource(), null));
    initApplicationContext(pc, app);
    ap.setName(applicationName);
    ap.setSetSessionManagement(true);
    // if(!ap.hasName())ap.setName("Controler")
    // Base
    pc.setBase(app.getPageSource());

    return pc;
  }
Exemplo n.º 3
0
  @Override
  public void onApplicationEnd(CFMLFactory factory, String applicationName) throws PageException {
    ComponentAccess app = apps.get(applicationName);
    if (app == null || !app.containsKey(ON_APPLICATION_END)) return;

    PageContextImpl pc = (PageContextImpl) ThreadLocalPageContext.get();
    boolean createPc = pc == null;
    try {
      if (createPc) pc = createPageContext(factory, app, applicationName, null, ON_APPLICATION_END);
      call(app, pc, ON_APPLICATION_END, new Object[] {pc.applicationScope()}, true);
    } finally {
      if (createPc && pc != null) {
        factory.releasePageContext(pc);
      }
    }
  }
Exemplo n.º 4
0
  @Override
  public void onSessionEnd(CFMLFactory factory, String applicationName, String cfid)
      throws PageException {
    ComponentAccess app = apps.get(applicationName);
    if (app == null || !app.containsKey(ON_SESSION_END)) return;

    PageContextImpl pc = null;
    try {
      pc = createPageContext(factory, app, applicationName, cfid, ON_SESSION_END);
      call(
          app,
          pc,
          ON_SESSION_END,
          new Object[] {pc.sessionScope(false), pc.applicationScope()},
          true);
    } finally {
      if (pc != null) {
        factory.releasePageContext(pc);
      }
    }
  }