You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2008/03/08 08:49:29 UTC

t5: dispatcher not fired in the start page

Hi,

I have a page that I make it as 'start' page by
configuration.add("tapestry.start-page-name", "home");
and I have a dispatcher that is configured in the AppModule as follow:

    public static void
contributeMasterDispatcher(OrderedConfiguration<Dispatcher> configuration,
                   @InjectService("CookieDispatcher") CookieDispatcher
cookieDispatcher) {
                   configuration.add("CookieDispatcher", cookieDispatcher,
"before:PageRender");
    }

the dispatcher is never fired if I start the app like this:

http://localhost:8080/app

but it will fire if I do:

http://localhost:8080/app/home

Any ideal? 

Thanks,

A.C.





-- 
View this message in context: http://www.nabble.com/t5%3A-dispatcher-not-fired-in-the-start-page-tp15912127p15912127.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: dispatcher not fired in the start page

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Hi Angelo,

Well, let's say I have a filter called CookieLoginRequestFilter that 
implements ComponentEventRequestFilter and PageRenderRequestFilter:

public class CookieLoginRequestFilter
     implements ComponentEventRequestFilter, PageRenderRequestFilter {

   private final CookieLoginService cookieLoginService;

   public AccessRequestFilter(CookieLoginService cookieLoginService) {
     this.cookieLoginService = cookieLoginService;
   }

   public void handle(ComponentEventRequestParameters parameters, 
ComponentEventRequestHandler handler)
       throws IOException {
     cookieLoginService.checkLogin();
     handler.handle(parameters);
   }

   public void handle(PageRenderRequestParameters parameters, 
PageRenderRequestHandler handler)
       throws IOException {
     cookieLoginService.checkLogin();
     handler.handle(parameters);
}

Then I contribute it to the relevant handlers in my AppModule:

   public static void contributeComponentEventRequestHandler(
       OrderedConfiguration<ComponentEventRequestFilter> configuration,
       AccessRequestFilter accessRequestFilter) {
     configuration.add("Access", accessRequestFilter, 
"after:SetRequestEncoding");
   }

   public static void contributePageRenderRequestHandler(
       OrderedConfiguration<PageRenderRequestFilter> configuration,
       AccessRequestFilter accessRequestFilter) {
     configuration.add("Access", accessRequestFilter, 
"after:SetRequestEncoding");
   }

And that's it. Regarding how to handle the actual login, I can't share 
that, but have a look at Tapestry's Cookies service - it's a lot easier 
to work with than CookieSource, which is an internal service, btw.

-Filip

Angelo Chen skrev:
> 
> Hi Filip S,
> 
> Can you show me sample code of doing that? here is my simple code:
> 
>  public boolean dispatch(Request request, Response response) throws
> IOException {
>         Cookie[] cookies = cookieSource.getCookies();
>         if (cookies != null) {
>             for (Cookie c : cookies) {
>                 if (LOG_KEY.equals(c.getName()) && !signIn.loggedIn()) {
>                     String[] p = c.getValue().split(",");
>                     if (p.length > 1) {
>                         try {
>                             signIn.login(p[0], p[1]);
>                         } catch (InvalidUserException e) {
>                             logger.info("invalid user in cookie " + p[0]);
>                         }
>                     }
>                     break;
>                 }
>             }
>         }
>         return false;
>     }
> 
> Filip S. Adamsen-2 wrote:
>> Angelo,
>>
>> I do exactly that in the request handling pipeline using a 
>> ComponentEventRequestFilter and a PageRenderRequestFilter. Works 
>> beautifully and let's you get the page name etc. easily from the 
>> supplied parameters. Pretty much doesn't get any easier than that. :)
>>
>> -Filip
>>
>>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: dispatcher not fired in the start page

Posted by Angelo Chen <an...@yahoo.com.hk>.

Hi Filip S,

Can you show me sample code of doing that? here is my simple code:

 public boolean dispatch(Request request, Response response) throws
IOException {
        Cookie[] cookies = cookieSource.getCookies();
        if (cookies != null) {
            for (Cookie c : cookies) {
                if (LOG_KEY.equals(c.getName()) && !signIn.loggedIn()) {
                    String[] p = c.getValue().split(",");
                    if (p.length > 1) {
                        try {
                            signIn.login(p[0], p[1]);
                        } catch (InvalidUserException e) {
                            logger.info("invalid user in cookie " + p[0]);
                        }
                    }
                    break;
                }
            }
        }
        return false;
    }

Filip S. Adamsen-2 wrote:
> 
> Angelo,
> 
> I do exactly that in the request handling pipeline using a 
> ComponentEventRequestFilter and a PageRenderRequestFilter. Works 
> beautifully and let's you get the page name etc. easily from the 
> supplied parameters. Pretty much doesn't get any easier than that. :)
> 
> -Filip
> 
> 

-- 
View this message in context: http://www.nabble.com/t5%3A-dispatcher-not-fired-in-the-start-page-tp15912127p15923083.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: dispatcher not fired in the start page

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Angelo,

I do exactly that in the request handling pipeline using a 
ComponentEventRequestFilter and a PageRenderRequestFilter. Works 
beautifully and let's you get the page name etc. easily from the 
supplied parameters. Pretty much doesn't get any easier than that. :)

-Filip

Angelo Chen skrev:
> hi Howard,
> 
> Thanks, cookieDispatcher check if a user cookie already exist, if yes, then
> it will log in the user using a login service, I don't know if it works with
> request handling pipelines.
> 
> A.C.
> 
> Howard Lewis Ship wrote:
>>
>> What does CookieDispatcher do?  It probably is a better fit for one of
>> the request handling pipelines.
>>
>>
>>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: dispatcher not fired in the start page

Posted by Angelo Chen <an...@yahoo.com.hk>.
hi Howard,

Thanks, cookieDispatcher check if a user cookie already exist, if yes, then
it will log in the user using a login service, I don't know if it works with
request handling pipelines.

A.C.

Howard Lewis Ship wrote:
> 
> 
> What does CookieDispatcher do?  It probably is a better fit for one of
> the request handling pipelines.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/t5%3A-dispatcher-not-fired-in-the-start-page-tp15912127p15921663.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: dispatcher not fired in the start page

Posted by Howard Lewis Ship <hl...@gmail.com>.
The Start page is a special case, and should be relegated to the
"backwards compatibility" scrap heap.  Recognizing the Start page is
its own Dispatcher and is probably being processed before your
CookieDispatcher.

What does CookieDispatcher do?  It probably is a better fit for one of
the request handling pipelines.

On Fri, Mar 7, 2008 at 11:49 PM, Angelo Chen <an...@yahoo.com.hk> wrote:
>
>  Hi,
>
>  I have a page that I make it as 'start' page by
>  configuration.add("tapestry.start-page-name", "home");
>  and I have a dispatcher that is configured in the AppModule as follow:
>
>     public static void
>  contributeMasterDispatcher(OrderedConfiguration<Dispatcher> configuration,
>                    @InjectService("CookieDispatcher") CookieDispatcher
>  cookieDispatcher) {
>                    configuration.add("CookieDispatcher", cookieDispatcher,
>  "before:PageRender");
>     }
>
>  the dispatcher is never fired if I start the app like this:
>
>  http://localhost:8080/app
>
>  but it will fire if I do:
>
>  http://localhost:8080/app/home
>
>  Any ideal?
>
>  Thanks,
>
>  A.C.
>
>
>
>
>
>  --
>  View this message in context: http://www.nabble.com/t5%3A-dispatcher-not-fired-in-the-start-page-tp15912127p15912127.html
>  Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org