> Looking into Stripes for a simple application to learn a Java
> framework. I'd like my simple application to follow the Twitter URL
> patterns.
>
> http://twitter.com/bigeasy
> http://twitter.com/shey
>
> The above urls are paths to a particular user's messages.
>
> While there are also paths to other aspects of the application.
>
> http://twitter.com/account/settings
> http://twitter.com/signup
>
> The logic would be, match a system page, like signup or account/
> settings , if not found then attempt to find a user in the database,
> otherwise 404.
>
> Turns out this layout is impossible in Wicket, so I'm sniffing around
> here.
<jab>
Wicket is a component framework where HTTP is a four letter word.
Here at Stripes World Headquarters, we embrace HTTP.
</jab>
Well, welcome. Stripes middle name is "impossible". ("Stripes" full
name is Champion Stripes Impossible Conundrum Juxtaposition, but we
just refer to it colloquially as Stripes.)
Basically, you have two things that you want to do.
You want to bind logic to a specific url (like //host.com/signup),
but also capture "rogue" urls.
The first one is easy, Stripes has a @UrlBinding annotation that will
let you bind an Action (Stripes logic artifact) to most any URL.
The second one is a bit trickier, because it's so fundamental to the
handling of the request, being at the root.
But it's readily done as well.
Here you drop out of Stripes for just a sec and would need to write a
Servlet Filter.
The Servlet Filter would capture the request and do the appropriate
processing.
Now, to be fair, it's not a "simple thing", it takes some intimate
knowledge of both the Servlet API and Stripes. (There may be some
filter sequencing issues, for example, as Stripes relies on a filter
as well.)
But Stripes can help out here, most certainly.
The way I would write this is I'd write simple Stripes Actions for
all of your "static" system URLs (like signup).
Then, I would create a Servlet Filter.
That filter would capture all of the requests.
Then, and this is where Stripes can help, you would take the URL and
"ask Stripes" if there's an action already bound to the URL.
If there is, then you simply continue with the filter as if nothing
happened. That means then you have a static action already bound, so
get out of the way and let the framework handle it like normal.
However, if it isn't mapped, then what I would do is I'd perform a
little bit of "request surgery" and "rewrite" the URL to point to
another, everyday Stripes action, and then Forward the request to
this new URL. Stripes will pick this up and direct it to the Action
you wrote, which can do whatever it wants with it.
For example, say you have a "User Action", and you map it to the url
"//host.com/processuser", so you'd rewrite "//host.com/bobbarker" to
"/processuser?userid= bobbarker", and forward THAT URL to Stripes,
where, again, magic happens and all is right in the world.
The nice part of this is two fold.
One, you get to write everyday Stripes actions to handle your logic,
which is a good thing. That lets you leverage the Stripes framework
100%, you don't have to juggle around, sneak behind its back, lie to
it or anything silly.
And two, it means you don't need to maintain a separate list of
"static" actions. You don't have to create an action, bind it to a
URL, and then put that URL in some list that your Filter would check
to see "where to go". Stripes already does that! Hell, I bet Tim
Fennel spent HOURS on that code alone. No reason you should rewrite
yourself (or even worse, write it faster, humiliating poor Tim -- he
hates that!).
It's a bit of a configuration trick to pull this off, but someone FAR
more knowledgeable in that kind of plumbing than me will no doubt
chime in with the 3 lines of code you need to pull this off.
But, that's how I'd do it.
Finally, 1.5 has "friendly URLs" and just might be able to do this
out of the box with no chicanery or gymnastics. In that case, some
know-it-all yahoo will come barreling out of their high tower
bellowing "Don't listen to him, he's an ignorant idjit" followed by
the arcane symbols and gesticulations necessary to pull this off with
little more than a glance at a Stripes Reference Card.
So, don't take my word for it. But I can safely say it can be done.
Regards,
Will Hartung
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users