You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Aaron Zeckoski <aa...@vt.edu> on 2009/06/19 16:00:38 UTC

Selectors and URL paths

I am trying to handle requests for certain resourceTypes (e.g.
sakai/contactstore) a special way.
What I really want to do is handle something like:
/_user/contacts/key1.key2.json

Where key1 has an unlimited set of values (it would not be a real
node) and key2 has a set of about 8 values.

The current approach involces creating a file (contacts.json) at
/_user and then lots of servlets (8) which work with selectors like
so:
 * @scr.component metatype="no" immediate="true"
 * @scr.service interface="javax.servlet.Servlet"
 * @scr.property name="sling.servlet.resourceTypes" values="sakai/contactstore"
 * @scr.property name="sling.servlet.methods" value="POST"
 * @scr.property name="sling.servlet.selectors" value="accept"
 */
public class AcceptConnectionServlet extends SlingAllMethodsServlet {
...
}
(in this case key2 would be "accept")

The servlets end up having a lot of repetition in them and the code is
not so easy to manage so I am wondering if there is a better (more
slingy) way to do this.
Any suggestions or thoughts? Is this the best way already?
-AZ

-- 
Aaron Zeckoski (azeckoski (at) vt.edu)
Senior Research Engineer - CARET - University of Cambridge
https://twitter.com/azeckoski - http://www.linkedin.com/in/azeckoski
http://aaronz-sakai.blogspot.com/ -
http://confluence.sakaiproject.org/confluence/display/~aaronz/

Re: Selectors and URL paths

Posted by Aaron Zeckoski <aa...@vt.edu>.
Thanks! That makes sense, it would probably be like this for us:
/_user/contacts/key1.key2.connections.json

So, this prompts 2 other questions:
1) Does this mean I would get the request/resource for things like this as well?
 /_user/contacts/stuff/morestuff/key1.key2.connections.json
2) Is it possible to get all the requests/resources that are under the
contacts node (in this case based on the resourceType) without
specifying a selector? In other words, a request like:
 /_user/contacts/stuff/morestuff/thing.json

If there is some documentation somewhere then you can feel free to
tell me to RTFM.
:-)
-AZ


On Fri, Jun 19, 2009 at 3:11 PM, Bertrand Delacretaz
<bd...@apache.org> wrote:
>
> Hi Aaron,
>
> On Fri, Jun 19, 2009 at 4:00 PM, Aaron Zeckoski<aa...@vt.edu> wrote:
> > I am trying to handle requests for certain resourceTypes (e.g.
> > sakai/contactstore) a special way.
> > What I really want to do is handle something like:
> > /_user/contacts/key1.key2.json
> >
> > Where key1 has an unlimited set of values (it would not be a real
> > node) and key2 has a set of about 8 values.
>
> If you can, the simplest might be to add another selector that's constant:
>
>  /_user/contacts/key1.key2.userinfo.json
>
> Then, declare your servlet to handle the userinfo selector, and use
> SlingHttpServletRequest.getRequestPathInfo() .getSelectors() to list
> all selectors.
>
> -Bertrand



--
Aaron Zeckoski (azeckoski (at) vt.edu)
Senior Research Engineer - CARET - University of Cambridge
https://twitter.com/azeckoski - http://www.linkedin.com/in/azeckoski
http://aaronz-sakai.blogspot.com/ -
http://confluence.sakaiproject.org/confluence/display/~aaronz/

Re: Selectors and URL paths

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Aaron,

On Fri, Jun 19, 2009 at 4:00 PM, Aaron Zeckoski<aa...@vt.edu> wrote:
> I am trying to handle requests for certain resourceTypes (e.g.
> sakai/contactstore) a special way.
> What I really want to do is handle something like:
> /_user/contacts/key1.key2.json
>
> Where key1 has an unlimited set of values (it would not be a real
> node) and key2 has a set of about 8 values.

If you can, the simplest might be to add another selector that's constant:

  /_user/contacts/key1.key2.userinfo.json

Then, declare your servlet to handle the userinfo selector, and use
SlingHttpServletRequest.getRequestPathInfo() .getSelectors() to list
all selectors.

-Bertrand

Re: Selectors and URL paths

Posted by Dominik Süß <do...@gmail.com>.
Not really on topic but a hint:

On Fri, Jun 19, 2009 at 4:00 PM, Aaron Zeckoski <aa...@vt.edu> wrote:

> The current approach involces creating a file (contacts.json) at
> /_user and then lots of servlets (8) which work with selectors like
> so:
>  * @scr.component metatype="no" immediate="true"
>  * @scr.service interface="javax.servlet.Servlet"
>  * @scr.property name="sling.servlet.resourceTypes"
> values="sakai/contactstore"
>  * @scr.property name="sling.servlet.methods" value="POST"
>  * @scr.property name="sling.servlet.selectors" value="accept"
>  */
> public class AcceptConnectionServlet extends SlingAllMethodsServlet {
> ...
> }
>

can now be replaced by Java 5 Annotation:
@SlingServlet(methods="POST", resourceTypes="sakai/contactstore",
selectors="accept")

..when using the latest maven-scr-plugin (was enabled with maven-scr-plugin
1.2.0)

Regards,
Dominik

Re: Selectors and URL paths

Posted by Ian Boston <ie...@tfd.co.uk>.
On 19 Jun 2009, at 15:00, Aaron Zeckoski wrote:

> The servlets end up having a lot of repetition in them and the code is
> not so easy to manage so I am wondering if there is a better (more
> slingy) way to do this.
> Any suggestions or thoughts? Is this the best way already?
> -AZ


How about an abstract  base class, just for this set of servlets?
All the code can go in 1 base class.
Thats what is done in the jackrabbit-accessmanager and jackrabbit- 
usermanager.

Ian