[ 
http://issues.apache.org/jira/browse/TAPESTRY-695?page=comments#action_12331591 
] 

Peter Ertl commented on TAPESTRY-695:
-------------------------------------

why is it a problem to put the request / response in the globals as a default 
before filter invocation?

image you want a function isLoggedOn in an Authenticator class (like already 
described) which has 
to check the request / session for the presence of a principal. as it should 
behave similar within a 
page or a filter it's undesirable to handle the request to it, like...

 isLoggedOn(WebRequest request)   [just the way it was before dependency 
injection came up :-( ]

This would mean you had to inject the request into your BasePage (or use 
cycle.getInfrastructure().getRequest()). 
ognl-based access within the html template is even worse, e.g. to display 'you 
are logged on' in your page. 
so you would really like to use RequestGlobals in your authenticator to make 
use of it simple 
(just inject the authenticator where you need and use it - don't worry about 
requests and where 
they come from).

once I put a 

      requestGlobals.store(request, response);

into the beginning of service(...) the call of isLoggedOn() works as expected.

having a filter chain is no problem as you could hand over the last result of 
RequestGlobals 
to the next filter#service(request, response, servicer)

I am sure that way life would be simpler :-)


> WebRequestServicerFilter lacks support for tapestry.globals.*
> -------------------------------------------------------------
>
>          Key: TAPESTRY-695
>          URL: http://issues.apache.org/jira/browse/TAPESTRY-695
>      Project: Tapestry
>         Type: Bug
>   Components: Framework, Web
>     Reporter: Peter Ertl

>
> problem description:
> step 1: let there be an "Authenticator" service which uses the current 
> request (for credentials lookup)
> // ----------------------------------------------------------
>   <service-point id="Authenticator">
>     <invoke-factory model="threaded">
>        <construct class="AuthenticatorImpl">
>           <set-service property="request" 
> service-id="tapestry.globals.WebRequest" />
>        </construct>
>     </invoke-factory>
>   </service-point>
> // ----------------------------------------------------------
>   public class AuthenticatorImpl implements Authenticator
>   {
>     private WebRequest request; // injected
>     // setters + other stuff omitted
>     
>     public boolean isAuthenticated()
>     {
>       if(request.getSession(false) == null)
>         return false;
>         
>       // more stuff comes here...
>     }
>   }
> // ----------------------------------------------------------
> step 2: now inject the authenticator into a request filter
> // ----------------------------------------------------------
>   <service-point id="AuthenticationFilter" 
> interface="org.apache.tapestry.services.WebRequestServicerFilter">
>     <invoke-factory>
>        <construct class="AuthenticationFilter">
>           <set-service property="authenticator" service-id="Authenticator" />
>        </construct>
>     </invoke-factory>
>   </service-point>
>   
>   <contribution 
> configuration-id="tapestry.request.WebRequestServicerPipeline">
>     <filter name="auth" object="service:AuthenticationFilter" />
>   </contribution>
>   
> // ----------------------------------------------------------
>   public class AuthenticationFilter implements WebRequestServicerFilter
>   {
>      private Authenticator authenticator; // injected
>   
>      // setters + other stuff omitted
>   
>      public void service(WebRequest request, WebResponse response, 
> WebRequestServicer servicer) throws IOException
>      {
>        if(authenticator.isAuthenticated())
>        {
>           // *****************************************************
>           // the above operation "isAuthenticated()" will fail !!!
>           // request == NULL
>           // *****************************************************
>        }
>      }
>   
>   }
> // ----------------------------------------------------------
> Property 'webRequest' of <OuterProxy for 
> tapestry.globals.RequestGlobals(org.apache.tapestry.services.RequestGlobals)> 
> is null.
> this should not happen as the request is available at this time (it's a 
> parameter of the service method)
> however, I do not want to handle the request to the authenticator as it's 
> used not only in the filter 
> but also in the login page.
> I think this is a general problem with filters being called before 
> tapestry.globals is fully initialized

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to