Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get HTTP GET parameters from Restlet request

Tags:

java

rest

restlet

I am trying to figure out how to get the parameters from a Restlet request object.

my request comes in as /customer?userId=1 and I want to grab the parameter to pass to my DAO for the query.

public class CustomerResource extends ServerResource
{
  @Get("xml")
  public Representation toXml() throws ResourceException, Exception
  {
      try
      {
          //get param from request
         //call DAO with parameter
      }
      catch(Exception e)
      {
          throw e;
      }
  }
}
like image 578
Holograham Avatar asked May 05 '10 13:05

Holograham


2 Answers

I figured it out....

public class CustomerResource extends ServerResource
{
  @Get("xml")
  public Representation toXml() throws ResourceException, Exception
  {
      try
      {
          //get param from request
          getQuery().getValues("userId")
         //call DAO with parameter
      }
      catch(Exception e)
      {
          throw e;
      }
  }
}
like image 157
Holograham Avatar answered Oct 17 '22 00:10

Holograham


Please not that there is a shortcut method for that:

String paramValue = getQueryValue("userId");

Hope it helps you.

like image 7
Thierry Templier Avatar answered Oct 16 '22 23:10

Thierry Templier