14

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;
      }
  }
}
bluish
  • 23,093
  • 23
  • 110
  • 171
Holograham
  • 1,348
  • 1
  • 12
  • 34

2 Answers2

30

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;
      }
  }
}
Holograham
  • 1,348
  • 1
  • 12
  • 34
7

Please not that there is a shortcut method for that:

String paramValue = getQueryValue("userId");

Hope it helps you.

Maxime Lorant
  • 28,973
  • 16
  • 79
  • 93
Thierry Templier
  • 182,931
  • 35
  • 372
  • 339