[ 
https://issues.apache.org/jira/browse/TRINIDAD-1377?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12667463#action_12667463
 ] 

Scott O'Bryan commented on TRINIDAD-1377:
-----------------------------------------

Action "type" request are, Portlet 1.0 Action Request, servlet request, and 
eventually Resource Requests (Portlet 2.0).  In the more updated vernacular in 
the command project, this essentially tests for a "client" request which is a 
request that comes directly from the client.

For Action and Servlet Requests this will return true.  for all render request, 
INCLUDING THOSE THAT WRAP SERVLET REQUEST, it returns false.  Look at the last 
line..

return (request instanceof ServletRequest && 
!_PORTLET_RENDER_REQUEST_CLASS.isInstance(request) ||
            _PORTLET_ACTION_REQUEST_CLASS.isInstance(request)) ; 

This says if it's a servlet request that us *NOT* an render request, or if it's 
an action request, return true.  If this is not happening, it's a bug.

I'll again re-iterate, Trinidad treats this API as if it's a request that comes 
from the client.  It tells us, for instance, whether we can receive an input 
stream, whether we are in the inital phases of a request.  As I said, in the 
commons version of this class, it is essentially the isClientRequest flag.  The 
definition of this and the isClientRequest flag are the same.

On the flipside is the isResponseWritable.  These include Servlet Requests as 
well, but would also include a render request.  Here is a list of, basically, 
all the objects we do (will soon) handle by the configurators and what they 
return..

                                         isClientRequest (isAction in Trinidad) 
                           isResponseWritable (no equiv in Trinidad)
ServletRequest                                      true                        
                                                       true
ActionRequest                                       true                        
                                                       false
RenderRequest                                      false                        
                                                      true
ResourceRequest                                   true                          
                                                    true
EventRequest                                         false                      
                                                       false

How is this used?  Most of the time within Trinidad, we need to check for 
whether something has access to headers or is in response to say a real request 
(like PPR Request or whatnot).  Other times we need to know whether we are in a 
portlet environment.  By far the fewest number of times do we have to check if 
we are in a portlet ACTION REQUEST specifically.  In this case, the results of 
isPortlet and isAction need to be used together, OR the ExternalContextUtils in 
the commons should be used (it supports an enum for request type).

Scott

> ActionRequest not properly detected.
> ------------------------------------
>
>                 Key: TRINIDAD-1377
>                 URL: https://issues.apache.org/jira/browse/TRINIDAD-1377
>             Project: MyFaces Trinidad
>          Issue Type: Bug
>          Components: Portlet
>    Affects Versions:  1.2.11-core
>            Reporter: Felix Röthenbacher
>
> The method ExternalContextUtils.isAction(final ExternalContext 
> externalContext) does not reliably detect an action request.
> If the object returned by ExternalContext.getRequest() implements the 
> ServletRequest interface the method above returns
> true. This can also apply for a RenderRequest which is not an ActionRequest.
> The following fixes this:
>   /**
>    * Returns <code>true</code> if this externalContext represents an 
> "action". An action request
>    * is any ServletRequest or a portlet ActionRequest. It is assumed that the 
> ExternalContext
>    *
>    * @return a boolean of <code>true</code> if this is a Portlet 
> ActionRequest or an non-portlet
>    *         request.
>    */
>   public static boolean isAction(final ExternalContext externalContext)
>   {
>     final Object request = externalContext.getRequest();
>     if (_PORTLET_ACTION_REQUEST_CLASS == null)
>     {
>       _LOG
>           .fine("Portlet API's are not on the classpath so isAction will only 
> check for servlet request.");
>       return request instanceof ServletRequest;
>     }
>     return (request instanceof ServletRequest && 
> !_PORTLET_RENDER_REQUEST_CLASS.isInstance(request) ||
>             _PORTLET_ACTION_REQUEST_CLASS.isInstance(request))  ;
>   }
> _PORTLET_RENDER_REQUEST_CLASS has to be properly initialized. Not sure why 
> this method checks for ServletRequest.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to