You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by so...@apache.org on 2008/04/12 02:18:33 UTC

svn commit: r647355 - in /myfaces/trinidad/branches/sobryan-portlet20: ./ trinidad-examples/trinidad-blank/ trinidad-examples/trinidad-demo/ trinidad-impl/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ trinidad-impl/src/main/j...

Author: sobryan
Date: Fri Apr 11 17:18:08 2008
New Revision: 647355

URL: http://svn.apache.org/viewvc?rev=647355&view=rev
Log:
Conversion of the initial configurators to handle JSR-286, and fixed 
XmlHttpConfigurator.  The other configurators still need to be handled
before this code is even tryable.

Some wierd design decisions that may have to be reversed in the final
patch are:

* I'm using the commons version of the ExternalContextUtils because it's
  much more complete (ie. handles JSR-286).  May or may not want to keep
  this depending on what the community thinks about an extra dependency
  and the release of the commons utils.

* This branch is going to assume all portal environments are JSR-286. I'm
  I'm likely going to want these to be trinidad extension packages that
  would be included depending on environment.  For instance, dropping the
  286 jar into the classpath would enable PPR in Trinidad for Portlets
  automatically whereas the 168 jar would disable ppr but would work in
  both containers.  We might be able to do this automagically, I'll
  research that as well.

Added:
    myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlResourceExternalContext.java
Modified:
    myfaces/trinidad/branches/sobryan-portlet20/pom.xml
    myfaces/trinidad/branches/sobryan-portlet20/trinidad-examples/trinidad-blank/pom.xml
    myfaces/trinidad/branches/sobryan-portlet20/trinidad-examples/trinidad-demo/pom.xml
    myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/pom.xml
    myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
    myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java
    myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java
    myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java
    myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator

Modified: myfaces/trinidad/branches/sobryan-portlet20/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/sobryan-portlet20/pom.xml?rev=647355&r1=647354&r2=647355&view=diff
==============================================================================
--- myfaces/trinidad/branches/sobryan-portlet20/pom.xml (original)
+++ myfaces/trinidad/branches/sobryan-portlet20/pom.xml Fri Apr 11 17:18:08 2008
@@ -216,7 +216,8 @@
                 </execution>
             </executions>
         </plugin-->
-
+        
+        <!-- Way early version of apache commons -->
       </plugins>
     </pluginManagement>
     <plugins>
@@ -467,6 +468,13 @@
         <version>4.4</version>
         <scope>test</scope>
       </dependency>
+      
+      <dependency>
+        <groupId>org.apache.myfaces.commons</groupId>
+        <artifactId>myfaces-commons-utils</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+      </dependency>
+
 
     </dependencies>
   </dependencyManagement>

Modified: myfaces/trinidad/branches/sobryan-portlet20/trinidad-examples/trinidad-blank/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/sobryan-portlet20/trinidad-examples/trinidad-blank/pom.xml?rev=647355&r1=647354&r2=647355&view=diff
==============================================================================
--- myfaces/trinidad/branches/sobryan-portlet20/trinidad-examples/trinidad-blank/pom.xml (original)
+++ myfaces/trinidad/branches/sobryan-portlet20/trinidad-examples/trinidad-blank/pom.xml Fri Apr 11 17:18:08 2008
@@ -136,5 +136,9 @@
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.myfaces.commons</groupId>
+      <artifactId>myfaces-commons-utils</artifactId>
+    </dependency>
   </dependencies>
 </project>

Modified: myfaces/trinidad/branches/sobryan-portlet20/trinidad-examples/trinidad-demo/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/sobryan-portlet20/trinidad-examples/trinidad-demo/pom.xml?rev=647355&r1=647354&r2=647355&view=diff
==============================================================================
--- myfaces/trinidad/branches/sobryan-portlet20/trinidad-examples/trinidad-demo/pom.xml (original)
+++ myfaces/trinidad/branches/sobryan-portlet20/trinidad-examples/trinidad-demo/pom.xml Fri Apr 11 17:18:08 2008
@@ -125,6 +125,11 @@
       <version>2.1</version>
       <scope>compile</scope>
     </dependency>
+
+    <dependency>
+      <groupId>org.apache.myfaces.commons</groupId>
+      <artifactId>myfaces-commons-utils</artifactId>
+    </dependency>
   </dependencies>
 
   <profiles>

Modified: myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/pom.xml?rev=647355&r1=647354&r2=647355&view=diff
==============================================================================
--- myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/pom.xml (original)
+++ myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/pom.xml Fri Apr 11 17:18:08 2008
@@ -276,6 +276,10 @@
       <artifactId>jsf-facelets</artifactId>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.myfaces.commons</groupId>
+      <artifactId>myfaces-commons-utils</artifactId>
+    </dependency>
   </dependencies>
 
   <reporting>

Modified: myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java?rev=647355&r1=647354&r2=647355&view=diff
==============================================================================
--- myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java (original)
+++ myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java Fri Apr 11 17:18:08 2008
@@ -31,6 +31,8 @@
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.myfaces.commons.util.ExternalContextUtils;
+import org.apache.myfaces.commons.util.RequestType;
 import org.apache.myfaces.trinidad.config.Configurator;
 import org.apache.myfaces.trinidad.context.ExternalContextDecorator;
 import org.apache.myfaces.trinidad.context.RequestContext;
@@ -47,7 +49,6 @@
 import org.apache.myfaces.trinidadinternal.context.external.ServletRequestParameterValuesMap;
 import org.apache.myfaces.trinidadinternal.skin.SkinFactoryImpl;
 import org.apache.myfaces.trinidadinternal.skin.SkinUtils;
-import org.apache.myfaces.trinidad.util.ExternalContextUtils;
 
 /**
  * This is the implementation of the Trinidad's Global configurator. It provides the entry point for
@@ -121,7 +122,7 @@
    */
   static public boolean isRequestStarted(final ExternalContext ec)
   {
-    return (RequestType.getType(ec) != null);
+    return (_getRequestTypeFromRequest(ec) != null);
   }
 
   /**
@@ -180,13 +181,15 @@
   {
     // asserts for debug which disappear in production
     assert externalContext != null;
+    RequestType currentRequestType = ExternalContextUtils.getRequestType(externalContext);
+    RequestType previousRequestType = _getRequestTypeFromRequest(externalContext);
 
     // Do per-virtual request stuff
-    if (RequestType.getType(externalContext) == null)
+    if (previousRequestType == null)
     {
       // RequestType may change in a portal environment. Make sure it's set up to enforce the
       // contracts
-      RequestType.setType(externalContext);
+      _setRequestTypeOnRequest(externalContext, currentRequestType);
 
       // By contract, Configurators beginRequest is only called once per physical request.
       // The globalConfigurator may be called multiple times, however, so we need to enforce
@@ -211,7 +214,7 @@
         _LOG.fine("GlobalConfigurator: Configurators have been disabled for this request.");
       }
     }
-    else if (!RequestType.isCorrectType(externalContext))
+    else if (!(previousRequestType == currentRequestType))
     {
       // This will happen if the actionRequest was not ended before dispatching to the render
       // request
@@ -265,22 +268,22 @@
   @Override
   public void endRequest(final ExternalContext externalContext)
   {
+    RequestType previousRequestType = _getRequestTypeFromRequest(externalContext);
     // do per virtual-request stuff
-    if (RequestType.getType(externalContext) != null)
+    if (previousRequestType != null)
     {
       if (!_isDisabled(externalContext))
       {
-        final RequestType type = RequestType.getType(externalContext);
-
-        // Do not end services at the end of a portal action request
-        if (type != RequestType.PORTAL_ACTION)
+        // Do not end services if response is not writable
+        if (previousRequestType.isResponseWritable())
         {
           _endConfiguratorServiceRequest(externalContext);
         }
 
         _releaseRequestContext(externalContext);
       }
-      RequestType.clearType(externalContext);
+      
+      _setRequestTypeOnRequest(externalContext, null);
     }
   }
 
@@ -299,14 +302,17 @@
   @Override
   public ExternalContext getExternalContext(ExternalContext externalContext)
   {
-    if (RequestType.getType(externalContext) == null)
+    if (_getRequestTypeFromRequest(externalContext) == null)
     {
       beginRequest(externalContext);
     }
 
     if (!_isDisabled(externalContext))
     {
-      if(!ExternalContextUtils.isPortlet(externalContext) && _isSetRequestBugPresent(externalContext))
+      RequestType rType = ExternalContextUtils.getRequestType(externalContext);
+      
+      //TODO: This should be handled for portlets as well
+      if(!rType.isPortlet() && _isSetRequestBugPresent(externalContext))
       {
         //This handles bug 493 against the JSF-RI 1.2_03 and earlier.  If the bug
         //is present in the current system, add a wrapper to fix it
@@ -430,7 +436,7 @@
   {
     //If it's not a portal action, we should remove the cached request because
     //well want to create a new one next request
-    if(RequestType.getType(ec) != RequestType.PORTAL_ACTION)
+    if(ExternalContextUtils.getRequestType(ec).isResponseWritable())
     {
       ec.getRequestMap().remove(_REQUEST_CONTEXT);
     }
@@ -499,6 +505,16 @@
 
     return _sHasSetRequestBug;
   }
+  
+  static private RequestType _getRequestTypeFromRequest(ExternalContext ec)
+  {
+    return (RequestType)ec.getRequestMap().get(_REQUEST_TYPE);
+  }
+  
+  static private void _setRequestTypeOnRequest(ExternalContext ec, RequestType type)
+  {
+    ec.getRequestMap().put(_REQUEST_TYPE, type);
+  }
 
   // This handles an issue with the ExternalContext object prior to
   // JSF1.2_04.
@@ -637,57 +653,10 @@
   static private final String _REQUEST_CONTEXT =
      GlobalConfiguratorImpl.class.getName()
      + ".REQUEST_CONTEXT";
+  static private final String _REQUEST_TYPE = 
+     GlobalConfiguratorImpl.class.getName()
+     + ".REQUEST_TYPE";
 
-
-  private enum RequestType
-  {
-    PORTAL_ACTION,
-    PORTAL_RENDER,
-    SERVLET;
-
-    public static void clearType(final ExternalContext ec)
-    {
-      ec.getRequestMap().remove(_REQUEST_TYPE);
-    }
-
-    public static RequestType getType(final ExternalContext ec)
-    {
-      return (RequestType) ec.getRequestMap().get(_REQUEST_TYPE);
-    }
-
-    public static boolean isCorrectType(final ExternalContext ec)
-    {
-      return _findType(ec) == getType(ec);
-    }
-
-    @SuppressWarnings("unchecked")
-    public static void setType(final ExternalContext ec)
-    {
-      ec.getRequestMap().put(_REQUEST_TYPE, _findType(ec));
-    }
-
-    private static final RequestType _findType(final ExternalContext ec)
-    {
-      if (ExternalContextUtils.isPortlet(ec))
-      {
-        if (ExternalContextUtils.isAction(ec))
-        {
-          return PORTAL_ACTION;
-        }
-        else
-        {
-          return PORTAL_RENDER;
-        }
-      }
-      else
-      {
-        return SERVLET;
-      }
-    }
-
-    static private final String _REQUEST_TYPE = GlobalConfiguratorImpl.class.getName()
-                                                  + ".REQUEST_TYPE";
-  }
 
   static private class TestRequest extends ServletRequestWrapper
   {

Modified: myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java?rev=647355&r1=647354&r2=647355&view=diff
==============================================================================
--- myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java (original)
+++ myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java Fri Apr 11 17:18:08 2008
@@ -33,6 +33,9 @@
 
 import javax.servlet.jsp.JspException;
 
+import org.apache.myfaces.commons.util.ExternalContextUtils;
+import org.apache.myfaces.commons.util.RequestType;
+import org.apache.myfaces.trinidad.config.Configurator;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidadinternal.application.StateManagerImpl;
 import org.apache.myfaces.trinidadinternal.renderkit.core.ppr.XmlResponseWriter;
@@ -43,8 +46,7 @@
  * 
  * TODO: support portlets, and make this a true configurator.
  */
-public class XmlHttpConfigurator
-  /*extends Configurator*/
+public class XmlHttpConfigurator extends Configurator
 {
   public XmlHttpConfigurator()
   {
@@ -55,14 +57,21 @@
     return new XmlHttpServletRequest(request);
   }
 
-  public static void beginRequest(ExternalContext externalContext)
+  public static ExternalContext getExternalContext(ExternalContext externalContext)
   {
     StateManagerImpl.reuseRequestTokenForResponse(externalContext);
-    Object response = externalContext.getResponse();
-    if (response instanceof ServletResponse)
+    RequestType type = ExternalContextUtils.getRequestType(externalContext);
+    
+    switch(type)
     {
-      externalContext.setResponse(
-         new XmlHttpServletResponse((ServletResponse) response));
+      case SERVLET:
+        externalContext.setResponse(new XmlHttpServletResponse(externalContext));
+        return externalContext;
+      case RESOURCE:
+        return new XmlResourceExternalContext(externalContext);
+      default:
+        _LOG.warning("Unknown request type being used for PPR: "+ externalContext.getRequest().getClass().getName());
+        return externalContext;
     }
   }
 

Modified: myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java?rev=647355&r1=647354&r2=647355&view=diff
==============================================================================
--- myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java (original)
+++ myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java Fri Apr 11 17:18:08 2008
@@ -21,6 +21,8 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 
+import javax.faces.context.ExternalContext;
+
 import javax.servlet.ServletOutputStream;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletResponse;
@@ -32,9 +34,9 @@
 @SuppressWarnings("deprecation")
 final class XmlHttpServletResponse extends HttpServletResponseWrapper
 {
-  XmlHttpServletResponse(ServletResponse response)
+  XmlHttpServletResponse(ExternalContext ec)
   {
-    super((HttpServletResponse)response);
+    super((HttpServletResponse)ec.getResponse());
     
     String contentType = "text/xml;charset=utf-8";
     

Added: myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlResourceExternalContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlResourceExternalContext.java?rev=647355&view=auto
==============================================================================
--- myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlResourceExternalContext.java (added)
+++ myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlResourceExternalContext.java Fri Apr 11 17:18:08 2008
@@ -0,0 +1,82 @@
+package org.apache.myfaces.trinidadinternal.config.xmlHttp;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+import javax.faces.context.ExternalContext;
+
+import javax.portlet.ResourceResponse;
+import javax.portlet.filter.ResourceResponseWrapper;
+
+import org.apache.myfaces.trinidad.context.ExternalContextDecorator;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidadinternal.renderkit.core.ppr.XmlResponseWriter;
+
+public class XmlResourceExternalContext
+  extends ExternalContextDecorator
+{
+  private ExternalContext _ec;
+  
+  public XmlResourceExternalContext(ExternalContext ec)
+  {    
+    ec.setResponse(new XmlResourceResponse((ResourceResponse)ec.getResponse()));
+    _ec = ec;
+  }
+  
+  protected ExternalContext getExternalContext()
+  {
+    return _ec;
+  }
+
+  @Override
+  public void redirect(String url)
+    throws IOException
+  {
+    //TODO: Should this just create the Resonse writer from the native object
+    XmlHttpConfigurator.__sendRedirect(((ResourceResponse)_ec.getResponse()).getWriter(), url);
+  }
+
+  private class XmlResourceResponse extends ResourceResponseWrapper
+  {
+    public XmlResourceResponse(ResourceResponse response)
+    {
+      super(response);
+      
+      String contentType = "text/xml;charset=utf-8";
+      
+      this.getResponse().setContentType(contentType);
+    }
+
+    @Override
+    public OutputStream getPortletOutputStream()
+      throws IOException
+    {
+      OutputStream os = super.getPortletOutputStream();
+      return new XmlOutput(os).getOutputStream();
+    }
+
+    @Override
+    public PrintWriter getWriter()
+      throws IOException
+    {
+      PrintWriter writer = super.getWriter();
+      return new XmlOutput(writer).getWriter();
+    }
+    
+    @Override
+    public void setContentType(final String type) 
+    {
+      // the reason we're using XmlHttpServletResponse is because
+      // we're producing a ppr xml response, so ignore any 
+      // attempts to set the contentType, since the contentType
+      // must be text/xml:
+      _LOG.finer("ignoring setContentType:{0}", type);
+    }
+    
+    //TODO How do we handle errors.
+    
+    static private final TrinidadLogger _LOG =
+      TrinidadLogger.createTrinidadLogger(XmlResourceResponse.class); 
+  }
+}

Modified: myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java?rev=647355&r1=647354&r2=647355&view=diff
==============================================================================
--- myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java (original)
+++ myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java Fri Apr 11 17:18:08 2008
@@ -33,6 +33,9 @@
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
+
+import javax.portlet.faces.annotation.ExcludeFromManagedRequestScope;
+
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -71,6 +74,8 @@
 
 /**
  */
+//TODO: This may need to go on the superclass
+@ExcludeFromManagedRequestScope
 public class RequestContextImpl extends RequestContext
 {
   static public final String LAUNCH_PARAMETERS =

Modified: myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator?rev=647355&r1=647354&r2=647355&view=diff
==============================================================================
--- myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator (original)
+++ myfaces/trinidad/branches/sobryan-portlet20/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator Fri Apr 11 17:18:08 2008
@@ -1,2 +1,3 @@
 org.apache.myfaces.trinidadinternal.config.upload.FileUploadConfiguratorImpl
 org.apache.myfaces.trinidadinternal.config.dispatch.DispatchResponseConfiguratorImpl
+org.apache.myfaces.trinidadinternal.config.xmlHttp.XmlHttpConfigurator