Hi Dennis,
 
In Restlet 1.1 there is a new Route."matchQuery" property that help you do
that. 
 
However, this way of matching query parameters imposes an order in the way
parameters are given by clients, prevent optional and repeating
parameters... 
 
So, it isn't very flexible in practice. So, for Restlet 1.0 where
"matchQuery" doesn't exist and in common cases, the recommended approach is
to extract the query parameters into a more convenient Form structure:
 
    request.getResourceRef().getQueryAsForm().getFirstValue("name");
 
>From within a Resource subclass in Restlet 1.1 you have a shortcut method:
 
    getQuery().getFirstValue("name");
Best regards,
Jerome


  _____  

De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] De la part de Dennis
Lo (CSE Mail)
Envoyé : vendredi 1 août 2008 06:17
À : [email protected]
Objet : Supporting URI query variables


Hi,

I'm using restlet version 1.0.10 (stable) and I'm basing my implementation
on the firstResource tutorial at
http://www.restlet.org/documentation/1.0/firstResource

Q1: I would like to know how to support URIs like:
/items?name={name}&description={desc} 
i.e. what should I replace the "URI Template matching query variables"
String within:
router.attach("URI Template matching query variables",
ItemsAlgoResource.class);       

Currently, I have the following inside firstApplication.java

   @Override
   public synchronized Restlet createRoot() {
      // Create a router Restlet that defines routes.
      Router router = new Router(getContext());

      // Defines a route for the resource "list of items"
      router.attach("/items", ItemsResource.class)

      // Defines a route for the resource "item"
      router.attach("/items/{itemName}", ItemResource.class);

      // Defines a route for the resource "list of items" but returning only
items that match
      router.attach("URI Template to support
/items?name={name}&description={desc}", ItemResourceQueryVariables.class);

     
      return router;
   }


Q2: I would also like to know how to extract the query variables inside my
Resource implementation ItemResourceQueryVariables.java

I've looked at the tutorial part05 [1] for some clues and [2], 
but I don't what lines of code can be use to do something like this inside
constructor of ItemResourceQueryVariables.java:


    /** The sequence of characters that identifies the resource. */
    String itemName;
    String itemDescription;

    public ItemResourceQueryVariables(Context context, Request request,
Response response) {
        super(context, request, response);

        // Get the "itemName" attribute value taken from the URI template

        this.itemName =                     //a line of code the get the
value of "name" from the URI /items?name={name}&description={desc} 

        this.itemDescription =            //a line of code the get the value
of "description" from the URI /items?name={name}&description={desc}
    }


Q3: I would also like to know how to support arbitrary number of URI query
variables. 
i.e. How do I modify the following bit of code below, so that I can support
/items?name={name}&description={desc}  and /items?name={name}

Currently, I have the following inside firstApplication.java:

   @Override
   public synchronized Restlet createRoot() {
      // Create a router Restlet that defines routes.
      Router router = new Router(getContext());

      // Defines a route for the resource "list of items" but returning only
items that match
      router.attach("URI Template to support
/items?name={name}&description={desc} AND /items?name={name} ",
ItemsQueryResource.class);       
     
      return router;
   }


[1] http://www.restlet.org/documentation/1.0/tutorial#part05
[2] http://restlet.tigris.org/servlets/ReadMsg?listName=discuss
<http://restlet.tigris.org/servlets/ReadMsg?listName=discuss&msgNo=4887>
&msgNo=4887
-- 
Thanks and kind regards,
Dennis Lo

Reply via email to