Get HTTP GET parameters from Restlet request
Asked Answered
R

2

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;
      }
  }
}
Richelle answered 5/5, 2010 at 13:32 Comment(0)
R
31

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;
      }
  }
}
Richelle answered 5/5, 2010 at 16:8 Comment(2)
It was hard for me to figure it out too.Lizbeth
Its 2014 and I still felt hard to figure this out :) Thanks for the solution !Cheree
T
8

Please not that there is a shortcut method for that:

String paramValue = getQueryValue("userId");

Hope it helps you.

Transpontine answered 15/4, 2013 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.