コード例 #1
0
  /**
   * check the top level component/app and get dependencies.
   *
   * <p>This routine checks to see that we have a valid top level component. If our top level
   * component is out of sync, we have to ignore it here, but we _must_ force the client to not
   * cache the response.
   *
   * <p>If there is a QFE, we substitute the QFE descriptor for the one given us, and continue.
   * Again, we cannot allow caching.
   *
   * <p>Finally, if there is no descriptor given, we simply ignore the request and give them an
   * empty response. Which is done here by returning null.
   *
   * <p>Also note that this handles the 'if-modified-since' header, as we want to tell the browser
   * that nothing changed in that case.
   *
   * @param request the request (for exception handling)
   * @param response the response (for exception handling)
   * @param context the context to get the definition.
   * @return the set of descriptors we are sending back, or null in the case that we handled the
   *     response.
   * @throws IOException if there was an IO exception handling a client out of sync exception
   * @throws ServletException if there was a problem handling the out of sync
   */
  @Override
  public Set<DefDescriptor<?>> verifyTopLevel(
      HttpServletRequest request, HttpServletResponse response, AuraContext context)
      throws IOException {
    DefDescriptor<? extends BaseComponentDef> appDesc = context.getApplicationDescriptor();

    context.setPreloading(true);
    if (appDesc == null) {
      //
      // This means we have nothing to say to the client, so the response is
      // left completely empty.
      //
      return null;
    }
    long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
    String uid = context.getUid(appDesc);
    try {
      try {
        definitionService.updateLoaded(appDesc);
        if (uid != null && ifModifiedSince != -1) {
          //
          // In this case, we have an unmodified descriptor, so just tell
          // the client that.
          //
          response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
          return null;
        }
      } catch (ClientOutOfSyncException coose) {
        //
        // We can't actually handle an out of sync here, since we are doing a
        // resource load. We have to ignore it, and continue as if nothing happened.
        // But in the process, we make sure to set 'no-cache' so that the result
        // is thrown away. This may actually not give the right result in bizarre
        // corner cases... beware cache inconsistencies on revert after a QFE.
        //
        // We actually probably should do something different, like send a minimalist
        // set of stuff to make the client re-try.
        //
        this.setNoCache(response);
        String oosUid = definitionService.getUid(null, appDesc);
        return definitionService.getDependencies(oosUid);
      }
    } catch (QuickFixException qfe) {
      //
      // A quickfix exception means that we couldn't compile something.
      // In this case, we still want to preload things, but we want to preload
      // quick fix values, note that we force NoCache here.
      //
      this.setNoCache(response);
      this.handleServletException(qfe, true, context, request, response, true);
      return null;
    }
    this.setLongCache(response);
    if (uid == null) {
      uid = context.getUid(appDesc);
    }
    return definitionService.getDependencies(uid);
  }