Пример #1
0
  public void handleContinuation(String continuationId, List params, Redirector redirector)
      throws Exception {

    WebContinuation wk =
        this.continuationsMgr.lookupWebContinuation(continuationId, getInterpreterID());
    if (wk == null) {
      // Throw an InvalidContinuationException to be handled inside the
      // <map:handle-errors> sitemap element.
      throw new InvalidContinuationException(
          "The continuation ID " + continuationId + " is invalid.");
    }

    AppleController app = (AppleController) wk.getContinuation();

    getLogger().debug("found apple from continuation: " + app);

    // TODO access control checks? exception to be thrown for illegal access?
    processApple(params, redirector, app, wk);
  }
Пример #2
0
  public void callFunction(String className, List params, Redirector redirector) throws Exception {

    AppleController app = instantiateController(className);

    WebContinuation wk = null;
    if (!(app instanceof StatelessAppleController)) {
      wk = this.continuationsMgr.createWebContinuation(app, null, 0, getInterpreterID(), this);
      if (getLogger().isDebugEnabled())
        getLogger().debug("Instantiated a stateful apple, continuationid = " + wk.getId());
    }

    DefaultContext appleContext = new DefaultContext(avalonContext);
    if (wk != null) {
      appleContext.put("continuation-id", wk.getId());
    }

    //      Use the current sitemap's service manager for components
    ServiceManager sitemapManager;
    try {
      sitemapManager =
          (ServiceManager) avalonContext.get(ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER);
    } catch (ContextException e) {
      throw new CascadingRuntimeException("Cannot get sitemap service manager", e);
    }

    LifecycleHelper.setupComponent(
        app,
        getLogger(),
        appleContext,
        sitemapManager,
        new WrapperComponentManager(sitemapManager),
        null,
        null,
        true);

    processApple(params, redirector, app, wk);
  }
Пример #3
0
  private void processApple(
      List params, Redirector redirector, AppleController app, WebContinuation wk)
      throws Exception {

    Request cocoonRequest = ContextHelper.getRequest(this.avalonContext);
    AppleRequest req = new DefaultAppleRequest(params, cocoonRequest);
    Response cocoonResponse = ContextHelper.getResponse(this.avalonContext);
    DefaultAppleResponse res = new DefaultAppleResponse(cocoonResponse);

    try {
      app.process(req, res);
    } finally {
      if (wk == null) {
        // dispose stateless apple immediatelly
        if (app instanceof Disposable) {
          try {
            ((Disposable) app).dispose();
          } catch (Exception e) {
            getLogger().error("Error disposing Apple instance.", e);
          }
        }
      }
    }

    if (res.isRedirect()) {
      redirector.redirect(false, res.getURI());
    } else {
      String uri = res.getURI();
      if (getLogger().isDebugEnabled()) {
        getLogger()
            .debug(
                "Apple forwards to "
                    + uri
                    + " with bizdata= "
                    + res.getData()
                    + (wk != null
                        ? " and continuationid= " + wk.getId()
                        : " without continuationid"));
      }

      // Note: it is ok for wk to be null
      this.forwardTo(uri, res.getData(), wk, redirector);
    }

    // TODO allow for AppleResponse to set some boolean saying the use case
    // is completed and the continuation can be invalidated ?
  }
Пример #4
0
 public void disposeContinuation(WebContinuation webContinuation) {
   AppleController app = (AppleController) webContinuation.getContinuation();
   if (app instanceof Disposable) {
     ((Disposable) app).dispose();
   }
 }