Beispiel #1
0
 public static String escapeQSValue(String str) {
   if (!ReqRspUtil.needEncoding(str, false)) return str;
   PageContextImpl pc = (PageContextImpl) ThreadLocalPageContext.get();
   if (pc != null) {
     try {
       return URLEncoder.encode(str, pc.getWebCharset());
     } catch (UnsupportedEncodingException e) {
     }
   }
   return URLEncoder.encode(str);
 }
Beispiel #2
0
  public void run() {
    PageContextImpl pci = (PageContextImpl) pc;
    Thread thread = pc.getThread();
    pci.stop(t);
    int count = 0;
    if (thread.isAlive()) {
      do {
        if (count > 0 && log != null) {
          LogUtil.log(
              log,
              Log.LEVEL_ERROR,
              "",
              "could not stop the thread on the first approach",
              thread.getStackTrace());
        }
        if (count++ > 10) break; // should never happen
        try {
          thread.stop(t);
        } catch (UnsupportedOperationException uoe) {
          LogUtil.log(
              log,
              Log.LEVEL_ERROR,
              "",
              "Thread.stop(Throwable) is not supported by this JVM and failed with UnsupportedOperationException",
              thread.getStackTrace());
          thread.stop();
        }
        SystemUtil.sleep(1000);
      } while (thread.isAlive() && pci.isInitialized());
    }

    if (count > 10 && log != null) {
      LogUtil.log(log, Log.LEVEL_ERROR, "", "could not stop the thread", thread.getStackTrace());
      aprint.e(thread.getStackTrace());
    }
  }
Beispiel #3
0
  static void _onRequest(
      PageContext pc, PageSource requestedPage, PageSource application, RequestListener rl)
      throws PageException {
    ((PageContextImpl) pc).setAppListenerType(AppListenerUtil.TYPE_CLASSIC);

    // on requestStart
    if (application != null) pc.doInclude(new PageSource[] {application}, false);

    if (rl != null) {
      requestedPage = rl.execute(pc, requestedPage);
      if (requestedPage == null) return;
    }

    // request
    try {
      pc.doInclude(new PageSource[] {requestedPage}, false);
    } catch (MissingIncludeException mie) {
      ApplicationContext ac = pc.getApplicationContext();
      boolean rethrow = true;
      if (ac instanceof ClassicApplicationContext) {
        ClassicApplicationContext cfc = (ClassicApplicationContext) ac;
        UDF udf = cfc.getOnMissingTemplate();
        if (udf != null) {
          String targetPage = requestedPage.getFullRealpath();
          rethrow = (!Caster.toBooleanValue(udf.call(pc, new Object[] {targetPage}, true), true));
        }
      }
      if (rethrow) throw mie;
    }

    // on Request End
    if (application != null) {
      PageSource onReqEnd = application.getRealPage("OnRequestEnd.cfm");
      if (onReqEnd.exists()) pc.doInclude(new PageSource[] {onReqEnd}, false);
    }
  }
Beispiel #4
0
  @Override
  public int doStartTag() throws PageException {
    // if(timeoutInMillis==0)timeoutInMillis=30000;
    // print.out("doStartTag");
    manager = pageContext.getConfig().getLockManager();
    // check attributes
    if (name != null && scope != SCOPE_NONE) {
      throw new LockException(
          LockException.OPERATION_CREATE,
          this.name,
          "invalid attribute combination",
          "attribute [name] and [scope] can't be used together");
    }
    if (name == null && scope == SCOPE_NONE) {
      name = "id-" + id;
    }

    String lockType = null;
    if (name == null) {
      String cid = pageContext.getConfig().getIdentification().getId();
      // Session
      if (scope == SCOPE_REQUEST) {
        lockType = "request";
        name = "__request_" + cid + "__" + ((RequestImpl) pageContext.requestScope())._getId();
      }
      // Session
      else if (scope == SCOPE_SESSION) {
        lockType = "session";
        name = "__session_" + cid + "__" + pageContext.sessionScope()._getId();
      }
      // Application
      else if (scope == SCOPE_APPLICATION) {
        lockType = "application";
        name =
            "__application_"
                + cid
                + "__"
                + ((ApplicationImpl) pageContext.applicationScope())._getId();
      }
      // Server
      else if (scope == SCOPE_SERVER) {
        lockType = "server";
        name = "__server_" + ((ServerImpl) pageContext.serverScope())._getId();
      }
    }
    Struct cflock = new StructImpl();
    cflock.set("succeeded", Boolean.TRUE);
    cflock.set("errortext", "");
    pageContext.variablesScope().set("cflock", cflock);
    start = System.nanoTime();
    try {
      ((PageContextImpl) pageContext)
          .setActiveLock(
              new ActiveLock(
                  type,
                  name,
                  timeoutInMillis)); // this has to be first, otherwise LockTimeoutException has
                                     // nothing to release
      data = manager.lock(type, name, timeoutInMillis, pageContext.getId());
    } catch (LockTimeoutException e) {
      LockManagerImpl mi = (LockManagerImpl) manager;
      Boolean hasReadLock = mi.isReadLocked(name);
      Boolean hasWriteLock = mi.isWriteLocked(name);
      String msg =
          LockTimeoutExceptionImpl.createMessage(
              type, name, lockType, timeoutInMillis, hasReadLock, hasWriteLock);

      _release(pageContext, System.nanoTime() - start);
      name = null;

      cflock.set("succeeded", Boolean.FALSE);
      cflock.set("errortext", msg);

      if (throwontimeout) throw new LockException(LockException.OPERATION_TIMEOUT, this.name, msg);

      return SKIP_BODY;
    } catch (InterruptedException e) {
      _release(pageContext, System.nanoTime() - start);
      cflock.set("succeeded", Boolean.FALSE);
      cflock.set("errortext", e.getMessage());

      if (throwontimeout) throw Caster.toPageException(e);

      return SKIP_BODY;
    }

    return EVAL_BODY_INCLUDE;
  }