dev@javaserverfaces.java.net

[REVIEW - PART 2] Avoid full lifecycle processing for images when using prefix mapping

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Mon, 16 Oct 2006 13:26:33 -0700

I've attached a follow up change bundle to this issue.
It turns out that the PhaseListener approach isn't going
to work (causes issues with Shale). I've instead
moved the PL logic into ViewHandlerImpl.renderView().



Ryan Lubke wrote:
> Avoid full lifecycle processing with the FacesServlet
> is prefix mapped and images are defined using relative URIs.
>
>
> SECTION: Modified Files
> ----------------------------
> M src/com/sun/faces/jsf-ri-config.xml
>
> A src/com/sun/faces/lifecycle/ImagePhaseListener.jav
>
>
> SECTION: Diffs
> ----------------------------
> Index: src/com/sun/faces/jsf-ri-config.xml
> ===================================================================
> RCS file:
> /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/jsf-ri-config.xml,v
> retrieving revision 1.69
> diff -u -r1.69 jsf-ri-config.xml
> --- src/com/sun/faces/jsf-ri-config.xml 11 May 2006 18:48:03
> -0000 1.69
> +++ src/com/sun/faces/jsf-ri-config.xml 11 Oct 2006 00:55:38 -0000
> @@ -167,9 +167,10 @@
> <converter-class>javax.faces.convert.EnumConverter</converter-class>
> </converter>
> - <!-- Add our InitializingPhaseListener -->
> + <!-- Add our implementation specific PhaseListeners -->
> <lifecycle>
>
> <phase-listener>com.sun.faces.lifecycle.ELResolverInitPhaseListener</phase-listener>
>
> +
> <phase-listener>com.sun.faces.lifecycle.ImagePhaseListener</phase-listener>
>
> </lifecycle>
>
> <!-- Configure Standard Validators -->
>
>
> SECTION: New Files
> ----------------------------
> SEE ATTACHMENTS
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: dev-help_at_javaserverfaces.dev.java.net
>




Follow up to my previous change bundle.
 - reverting the inclusion of the ImagePhaseListener
   as it may cause a conflict with shale static
   resource handling
 - Moving the image detection logic in
   ViewHandler.renderView()

SECTION: Modified Files
----------------------------
M src/com/sun/faces/jsf-ri-config.xml
  - remove the ImagePhaseListener from the config

M src/com/sun/faces/application/ViewHandlerImpl.java
  - update renderView to detect and image request
    and take the appropriate action (if prefix mapped
    only)


R src/com/sun/faces/lifecycle/ImagePhaseListener.java
 - REMOVED


SECTION: Diffs
----------------------------
Index: src/com/sun/faces/jsf-ri-config.xml
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/jsf-ri-config.xml,v
retrieving revision 1.70
diff -u -r1.70 jsf-ri-config.xml
--- src/com/sun/faces/jsf-ri-config.xml 11 Oct 2006 17:50:15 -0000 1.70
+++ src/com/sun/faces/jsf-ri-config.xml 16 Oct 2006 20:06:04 -0000
@@ -169,8 +169,7 @@
     
     <!-- Add our implementation specific PhaseListeners -->
     <lifecycle>
- <phase-listener>com.sun.faces.lifecycle.ELResolverInitPhaseListener</phase-listener>
- <phase-listener>com.sun.faces.lifecycle.ImagePhaseListener</phase-listener>
+ <phase-listener>com.sun.faces.lifecycle.ELResolverInitPhaseListener</phase-listener>
     </lifecycle>
 
   <!-- Configure Standard Validators -->
Index: src/com/sun/faces/application/ViewHandlerImpl.java
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/ViewHandlerImpl.java,v
retrieving revision 1.88
diff -u -r1.88 ViewHandlerImpl.java
--- src/com/sun/faces/application/ViewHandlerImpl.java 5 Oct 2006 20:56:36 -0000 1.88
+++ src/com/sun/faces/application/ViewHandlerImpl.java 16 Oct 2006 20:06:05 -0000
@@ -46,6 +46,7 @@
 import javax.faces.render.ResponseStateManager;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.jstl.core.Config;
 
@@ -89,6 +90,8 @@
      * or, if that isn't defined, the value of <code>DEFAULT_SUFFIX</code>
      */
     private String contextDefaultSuffix;
+
+ private ServletContext servletContext;
     private int bufSize = -1;
 
     public ViewHandlerImpl() {
@@ -111,6 +114,21 @@
         ExternalContext extContext = context.getExternalContext();
         ServletRequest request = (ServletRequest) extContext.getRequest();
         ServletResponse response = (ServletResponse) extContext.getResponse();
+ if (servletContext == null) {
+ servletContext = (ServletContext) extContext.getContext();
+ }
+ if (Util.isPrefixMapped(Util.getFacesMapping(context))) {
+ // if an image has been requested of the ViewHandler,
+ // set responseComplete() to terminate the remainder of
+ // the lifecycle and return null;
+ String viewId = viewToRender.getViewId();
+ String mimeType = servletContext.getMimeType(viewId);
+ if (mimeType != null && mimeType.startsWith("image")) {
+ context.responseComplete();
+ extContext.dispatch(viewId);
+ return;
+ }
+ }
         
         try {
             if (executePageToBuildView(context, viewToRender)) {