@Override
  public Response handle(Request request) {
    ResponseDefinition responseDefinition = handleRequest(request);
    responseDefinition.setOriginalRequest(request);

    Response response = responseRenderer.render(responseDefinition);
    for (RequestListener listener : listeners) {
      listener.requestReceived(request, response);
    }

    if (responseDefinition.getCallbackRequest() != null) {
      CallbackRequestDispatcher.dispatch(responseDefinition.getCallbackRequest(), request);
    }

    return response;
  }
 public int hashCode() {
   int result = context != null ? context.hashCode() : 0;
   result = 31 * result + (url != null ? url.hashCode() : 0);
   result = 31 * result + (method != null ? method.hashCode() : 0);
   result = 31 * result + (httpArgs != null ? Arrays.hashCode(httpArgs) : 0);
   result = 31 * result + (inputArgs != null ? Arrays.hashCode(inputArgs) : 0);
   result = 31 * result + (multiPart != null ? multiPart.hashCode() : 0);
   result = 31 * result + (listener != null ? listener.hashCode() : 0);
   return result;
 }
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Request request = (Request) o;

    if (context != null ? !context.equals(request.context) : request.context != null) return false;
    if (!Arrays.equals(httpArgs, request.httpArgs)) return false;
    if (!Arrays.equals(inputArgs, request.inputArgs)) return false;
    if (listener != null ? !listener.equals(request.listener) : request.listener != null)
      return false;
    if (method != null ? !method.equals(request.method) : request.method != null) return false;
    if (multiPart != null ? !multiPart.equals(request.multiPart) : request.multiPart != null)
      return false;
    if (url != null ? !url.equals(request.url) : request.url != null) return false;

    return true;
  }
Beispiel #4
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);
    }
  }
  /* (non-Javadoc)
   * @see MC2Request#parse(MC2Parser)
   */
  public void parse(MC2Parser mc2p) throws MC2ParserException, IOException {
    mc2p.nameOrError(MC2Strings.tone_search_reply);
    /*
     * xml 2.3.0
    <!ELEMENT one_search_reply ( search_list |
            ( status_code, status_message,
            status_uri? ) ) >
    <!ATTLIST one_search_reply transaction_id ID #REQUIRED >

    <!ELEMENT search_list ( search_match* )>
    <!ATTLIST search_list number_matches %number; #REQUIRED
            total_number_matches %number; #REQUIRED >
     */
    if (LOG.isDebug()) {
      LOG.debug("OneListSearchMC2Request.parse()", "Parsing compact search reply");
    }

    mc2p.childrenOrError();

    // check and report status code
    ServerError status = mc2p.getErrorIfExists();
    if (status != null) {
      error(status);
    } else {
      mc2p.nameOrError(MC2Strings.tsearch_list);
      int nbr = mc2p.attributeAsInt(MC2Strings.anumber_matches);
      int estimatedTotal = mc2p.attributeAsInt(MC2Strings.atotal_number_matches);

      OneListSearchMatchImpl[] matches;
      if (nbr > 0) {
        if (nbr <= m_maxNbrMatches) {
          mc2p.childrenOrError();
          matches = new OneListSearchMatchImpl[nbr];
          int n = 0;
          do {
            if (n < nbr) {
              OneListSearchMatchImpl match = parse_search_match(mc2p);
              if (match != null) {
                matches[n++] = match;
              } else {
                if (LOG.isInfo()) {
                  LOG.info("OneListSearchMC2Request.parse()", "match without position, ignored");
                }
              }
            } else {
              if (LOG.isWarn()) {
                LOG.warn(
                    "OneListSearchMC2Request.parse()",
                    "there are more results than requested, skip them");
              }
            }
          } while (mc2p.advance());

          // cope with the matches that didn't have a position
          // in an ideal world this should never happen
          if (n < nbr) {
            // create a clean array if needed
            OneListSearchMatchImpl[] tmp = matches;
            matches = new OneListSearchMatchImpl[n];
            System.arraycopy(tmp, 0, matches, 0, n);

            // adjust the total number as we have ignored some result
            estimatedTotal -= nbr - n;
          }
        } else {
          throw new MC2ParserException(
              "Nbr " + nbr + " of matches bigegr than max requested " + m_maxNbrMatches);
        }
      } else {
        // if no result create an empty array
        matches = EMPY_MATCH_ARRAY;
      }
      // skip all other elements and go back to parent;
      // it should be only one call of advance()
      mc2p.advance();
      m_listener.replyReceived(estimatedTotal, matches);
    }
    mc2p.nameOrError(MC2Strings.tone_search_reply);
  }
 /* (non-Javadoc)
  * @see MC2Request#error(CoreError)
  */
 public void error(CoreError coreError) {
   m_listener.requestFailed(coreError);
 }
  protected void _onRequest(
      PageContext pc, PageSource requestedPage, PageSource appPS, RequestListener rl)
      throws PageException {
    PageContextImpl pci = (PageContextImpl) pc;
    if (appPS != null) {
      String callPath = appPS.getComponentName();

      ComponentAccess app = ComponentLoader.loadComponent(pci, null, appPS, callPath, false, false);

      // init
      initApplicationContext(pci, app);

      apps.put(pc.getApplicationContext().getName(), app);

      if (!pci.initApplicationContext()) return;

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

      String targetPage = requestedPage.getFullRealpath();
      boolean doOnRequestEnd = true;

      // onRequestStart
      if (app.contains(pc, ON_REQUEST_START)) {
        Object rtn = call(app, pci, ON_REQUEST_START, new Object[] {targetPage}, true);
        if (!Caster.toBooleanValue(rtn, true)) return;
      }

      // onRequest
      boolean isCFC =
          ResourceUtil.getExtension(targetPage, "")
              .equalsIgnoreCase(pc.getConfig().getCFCExtension());
      Object method;
      if (isCFC
          && app.contains(pc, ON_CFCREQUEST)
          && (method = pc.urlFormScope().get(ComponentPage.METHOD, null)) != null) {

        Struct url = (Struct) Duplicator.duplicate(pc.urlFormScope(), true);

        url.removeEL(KeyConstants._fieldnames);
        url.removeEL(ComponentPage.METHOD);
        Object args = url.get(KeyConstants._argumentCollection, null);
        Object returnFormat = url.removeEL(KeyConstants._returnFormat);
        Object queryFormat = url.removeEL(KeyConstants._queryFormat);

        if (args == null) {
          args = pc.getHttpServletRequest().getAttribute("argumentCollection");
        }

        if (args instanceof String) {
          args = new JSONExpressionInterpreter().interpret(pc, (String) args);
        }

        if (args != null) {
          if (Decision.isCastableToStruct(args)) {
            Struct sct = Caster.toStruct(args, false);
            // Key[] keys = url.keys();
            Iterator<Entry<Key, Object>> it = url.entryIterator();
            Entry<Key, Object> e;
            while (it.hasNext()) {
              e = it.next();
              sct.setEL(e.getKey(), e.getValue());
            }
            args = sct;
          } else if (Decision.isCastableToArray(args)) {
            args = Caster.toArray(args);
          } else {
            Array arr = new ArrayImpl();
            arr.appendEL(args);
            args = arr;
          }
        } else args = url;

        Object rtn =
            call(
                app,
                pci,
                ON_CFCREQUEST,
                new Object[] {requestedPage.getComponentName(), method, args},
                true);

        if (rtn != null) {
          if (pc.getHttpServletRequest().getHeader("AMF-Forward") != null) {
            pc.variablesScope().setEL("AMF-Forward", rtn);
            // ThreadLocalWDDXResult.set(rtn);
          } else {
            try {
              pc.forceWrite(
                  ComponentPage.convertResult(
                      pc, app, method.toString(), returnFormat, queryFormat, rtn));
            } catch (Exception e) {
              throw Caster.toPageException(e);
            }
          }
        }

      }
      // else if(!isCFC && app.contains(pc,ON_REQUEST)) {}
      else {
        // TODO impl die nicht so generisch ist
        try {

          if (!isCFC && app.contains(pc, ON_REQUEST))
            call(app, pci, ON_REQUEST, new Object[] {targetPage}, false);
          else pci.doInclude(requestedPage);
        } catch (PageException pe) {
          if (!Abort.isSilentAbort(pe)) {
            if (pe instanceof MissingIncludeException) {
              if (((MissingIncludeException) pe).getPageSource().equals(requestedPage)) {
                if (app.contains(pc, ON_MISSING_TEMPLATE)) {
                  if (!Caster.toBooleanValue(
                      call(app, pci, ON_MISSING_TEMPLATE, new Object[] {targetPage}, true), true))
                    throw pe;
                } else throw pe;
              } else throw pe;
            } else throw pe;
          } else {
            doOnRequestEnd = false;
            if (app.contains(pc, ON_ABORT)) {
              call(app, pci, ON_ABORT, new Object[] {targetPage}, true);
            }
          }
        }
      }

      // onRequestEnd
      if (doOnRequestEnd && app.contains(pc, ON_REQUEST_END)) {
        call(app, pci, ON_REQUEST_END, new Object[] {targetPage}, true);
      }
    } else {
      apps.put(pc.getApplicationContext().getName(), null);
      pc.doInclude(requestedPage);
    }
  }
 @Override
 protected void processUI(BaseResponseData response) {
   CommentAppResponseData resp = (CommentAppResponseData) response;
   // resp.setPkg(bean.packageName);
   listener.onResponseData(resp);
 }