public void render(FacesContext context) {
   Lifecycle lifecycle = getBridgeConfig().getFacesLifecycle();
   lifecycle.execute(context);
   if (!context.getResponseComplete()) {
     lifecycle.render(context);
   }
 }
Пример #2
0
 /**
  * Informs phase listeners after a phase is executed
  *
  * @param facesContext The current faces context
  * @param phaseId The phase id that was executed
  */
 protected void informPhaseListenersAfter(FacesContext facesContext, PhaseId phaseId) {
   Lifecycle lifecycle = getLifecycle();
   PhaseListener[] phaseListeners = lifecycle.getPhaseListeners();
   for (int i = 0; i < phaseListeners.length; i++) {
     PhaseListener phaseListener = phaseListeners[i];
     int listenerPhaseId = phaseListener.getPhaseId().getOrdinal();
     if (listenerPhaseId == PhaseId.ANY_PHASE.getOrdinal()
         || listenerPhaseId == phaseId.getOrdinal()) {
       phaseListener.afterPhase(
           new PhaseEvent(FacesContext.getCurrentInstance(), phaseId, lifecycle));
     }
   }
 }
  /**
   * @param context
   * @param resource
   * @throws IOException
   */
  public void send(ResourceContext resourceContext, InternetResource resource) throws IOException {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (null != facesContext) {
      Lifecycle facesLifecycle = getFacesLifecycle();
      PhaseListener[] phaseListeners = facesLifecycle.getPhaseListeners();
      PhaseEvent restoreViewEvent = new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, this);
      processPhaseListeners(phaseListeners, restoreViewEvent, true);
      // Fix for a http://jira.jboss.org/jira/browse/RF-1056
      if (facesContext.getResponseComplete()) {
        return;
      }
      // fix for a http://jira.jboss.com/jira/browse/RF-1064 .
      // viewRoot can be created outside.
      UIViewRoot savedViewRoot = facesContext.getViewRoot();
      try {
        // create "dummy" viewRoot, to avoid problems in phase listeners.
        UIViewRoot root = new UIViewRoot();
        String key = resource.getKey();
        if (null != key && !key.startsWith("/")) {
          key = "/" + key;
        }
        root.setViewId(key);
        root.setLocale(Locale.getDefault());
        root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
        facesContext.setViewRoot(root);
        // We do not simulate other phases.
        facesContext.renderResponse();
        // Invoke after restore view phase listeners
        processPhaseListeners(phaseListeners, restoreViewEvent, false);
        // Fix for a http://jira.jboss.org/jira/browse/RF-1056
        if (!facesContext.getResponseComplete()) {
          // Invoke before render view phase listeners
          PhaseEvent renderViewEvent = new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, this);

          try {
            processPhaseListeners(phaseListeners, renderViewEvent, true);
            sendResource(resourceContext, resource);
          } finally {
            processPhaseListeners(phaseListeners, renderViewEvent, false);
          }
        }

      } finally {
        if (null != savedViewRoot) {
          facesContext.setViewRoot(savedViewRoot);
        }
      }
    } else {
      sendResource(resourceContext, resource);
    }
  }
Пример #4
0
 public final void postPhase(FacesContext context) {
   Lifecycle lifecycle = getLifecycle();
   PhaseListener[] phaseListeners = lifecycle.getPhaseListeners();
   if (phaseListeners != null) {
     for (int i = phaseListeners.length - 1; i >= 0; i--) {
       PhaseListener phaseListener = phaseListeners[i];
       PhaseId phaseId = getCurrentPhaseId();
       if (isTargetListener(phaseListener, phaseId)) {
         PhaseEvent event = createPhaseEvent(context, phaseId, lifecycle);
         phaseListener.afterPhase(event);
       }
     }
   }
 }
  /**
   * Jsf dispatch page.
   *
   * @param fctx the faces context
   * @param page the pge
   */
  private void jsfDispatchPage(FacesContext fctx, String page) {
    LifecycleFactory lf =
        (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    Lifecycle lifecycle = lf.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    ViewHandler vh = fctx.getApplication().getViewHandler();
    fctx.getViewRoot().setRenderKitId(vh.calculateRenderKitId(fctx));
    fctx.setViewRoot(vh.createView(fctx, page));

    // view rendering
    try {
      lifecycle.render(fctx);
    } catch (Exception e) {
      LOG.log(Level.INFO, "Error while rendering page. Attempting again" + page, e);
      lifecycle.render(fctx);
    } finally {
      fctx.release();
    }
  }
 /**
  * ICE-1084 : We have to turn off Seam's PhaseListener that makes it's debug page appear, so that
  * our SeamDebugResourceResolver can do its work.
  *
  * @param lifecycle The Lifecycle maintains the list of PhaseListeners
  */
 public static void removeSeamDebugPhaseListener(Lifecycle lifecycle) {
   PhaseListener[] phaseListeners = lifecycle.getPhaseListeners();
   //  System.out.println("*** SeamUtilities.removeSeamDebugPhaseListener()");
   // System.out.println("***   phaseListeners: " + phaseListeners.length);
   for (int i = 0; i < phaseListeners.length; i++) {
     // System.out.println("***     phaseListeners["+i+"]: " + phaseListeners[i]);
     if (phaseListeners[i]
         .getClass()
         .getName()
         .equals("org.jboss.seam.debug.jsf.SeamDebugPhaseListener")) {
       lifecycle.removePhaseListener(phaseListeners[i]);
       // System.out.println("***       REMOVED: " + phaseListeners[i]);
       seamDebugPhaseListenerClassLoader = phaseListeners[i].getClass().getClassLoader();
       // System.out.println("******      SeamDebugPhaseListener.class.getClassLoader(): " +
       // phaseListeners[i].getClass().getClassLoader());
     }
   }
 }
Пример #7
0
  public boolean isOrderCorrect() {

    LifecycleFactory factory =
        (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    Lifecycle l = factory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    PhaseListener[] listeners = l.getPhaseListeners();
    List<PhaseListener> list = new ArrayList<PhaseListener>();
    for (PhaseListener listener : listeners) {
      if (listener.getClass().getName().contains("com.sun.faces.systest.model.PhaseListener")) {
        list.add(listener);
      }
    }
    listeners = list.toArray(new PhaseListener[list.size()]);
    String[] suffixes = {"C", "B", "A", "D"};
    for (int i = 0; i < listeners.length; i++) {
      if (!listeners[i].getClass().getName().endsWith(suffixes[i])) {
        System.out.println("INCORRECT DOCUMENT ORDERING: " + Arrays.toString(listeners));
        return false;
      }
    }

    return true;
  }
Пример #8
0
  protected void processOutgoingPublicRenderParameters(Lifecycle lifecycle) {

    PhaseListener[] phaseListeners = lifecycle.getPhaseListeners();

    for (PhaseListener phaseListener : phaseListeners) {

      if (phaseListener instanceof IPCPhaseListener) {
        IPCPhaseListener ipcPhaseListener = (IPCPhaseListener) phaseListener;
        ipcPhaseListener.processOutgoingPublicRenderParameters(bridgeContext, facesContext);

        break;
      }
    }
  }
Пример #9
0
  /**
   * <span class="changed_modified_2_2">Process</span> an incoming request, and create the
   * corresponding response according to the following specification. <div
   * class="changed_modified_2_0">
   *
   * <p>If the <code>request</code> and <code>response</code> arguments to this method are not
   * instances of <code>HttpServletRequest</code> and <code>HttpServletResponse</code>,
   * respectively, the results of invoking this method are undefined.
   *
   * <p>This method must respond to requests that start with the following strings by invoking the
   * <code>sendError</code> method on the response argument (cast to <code>HttpServletResponse
   * </code>), passing the code <code>HttpServletResponse.SC_NOT_FOUND</code> as the argument.
   *
   * <ul>
   *   <pre><code>
   * /WEB-INF/
   * /WEB-INF
   * /META-INF/
   * /META-INF
   * </code></pre>
   * </ul>
   *
   * <p>If none of the cases described above in the specification for this method apply to the
   * servicing of this request, the following action must be taken to service the request.
   *
   * <p>Acquire a {@link FacesContext} instance for this request.
   *
   * <p>Acquire the <code>ResourceHandler</code> for this request by calling {@link
   * javax.faces.application.Application#getResourceHandler}. Call {@link
   * javax.faces.application.ResourceHandler#isResourceRequest}. If this returns <code>true</code>
   * call {@link javax.faces.application.ResourceHandler#handleResourceRequest}. If this returns
   * <code>false</code>, <span class="changed_added_2_2">call {@link
   * javax.faces.lifecycle.Lifecycle#attachWindow} followed by </span> {@link
   * javax.faces.lifecycle.Lifecycle#execute} followed by {@link
   * javax.faces.lifecycle.Lifecycle#render}. If a {@link javax.faces.FacesException} is thrown in
   * either case, extract the cause from the <code>FacesException</code>. If the cause is <code>null
   * </code> extract the message from the <code>FacesException</code>, put it inside of a new <code>
   * ServletException</code> instance, and pass the <code>FacesException</code> instance as the root
   * cause, then rethrow the <code>ServletException</code> instance. If the cause is an instance of
   * <code>ServletException</code>, rethrow the cause. If the cause is an instance of <code>
   * IOException</code>, rethrow the cause. Otherwise, create a new <code>ServletException</code>
   * instance, passing the message from the cause, as the first argument, and the cause itself as
   * the second argument.
   *
   * <p class="changed_modified_2_0_rev_a">The implementation must make it so {@link
   * javax.faces.context.FacesContext#release} is called within a finally block as late as possible
   * in the processing for the JSF related portion of this request. </div>
   *
   * @param req The servlet request we are processing
   * @param resp The servlet response we are creating
   * @throws IOException if an input/output error occurs during processing
   * @throws ServletException if a servlet error occurs during processing
   */
  public void service(ServletRequest req, ServletResponse resp)
      throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;

    requestStart(request.getRequestURI()); // V3 Probe hook

    if (!isHttpMethodValid(request)) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }
    if (Thread.currentThread().isInterrupted()) {
      if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.log(
            Level.FINE,
            "Thread {0} given to FacesServlet.service() in interrupted state",
            Thread.currentThread().getName());
      }
    }

    // If prefix mapped, then ensure requests for /WEB-INF are
    // not processed.
    String pathInfo = request.getPathInfo();
    if (pathInfo != null) {
      pathInfo = pathInfo.toUpperCase();
      if (pathInfo.startsWith("/WEB-INF/")
          || pathInfo.equals("/WEB-INF")
          || pathInfo.startsWith("/META-INF/")
          || pathInfo.equals("/META-INF")) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
      }
    }

    if (!initFacesContextReleased) {
      FacesContext initFacesContext = FacesContext.getCurrentInstance();
      if (null != initFacesContext) {
        initFacesContext.release();
      }
      initFacesContextReleased = true;
    }

    // Acquire the FacesContext instance for this request
    FacesContext context =
        facesContextFactory.getFacesContext(
            servletConfig.getServletContext(), request, response, lifecycle);

    // Execute the request processing lifecycle for this request
    try {
      ResourceHandler handler = context.getApplication().getResourceHandler();
      if (handler.isResourceRequest(context)) {
        handler.handleResourceRequest(context);
      } else {
        lifecycle.attachWindow(context);
        lifecycle.execute(context);
        lifecycle.render(context);
      }
    } catch (FacesException e) {
      Throwable t = e.getCause();
      if (t == null) {
        throw new ServletException(e.getMessage(), e);
      } else {
        if (t instanceof ServletException) {
          throw ((ServletException) t);
        } else if (t instanceof IOException) {
          throw ((IOException) t);
        } else {
          throw new ServletException(t.getMessage(), t);
        }
      }
    } finally {
      // Release the FacesContext instance for this request
      context.release();
    }

    requestEnd(); // V3 Probe hook
  }