views:

917

answers:

2

When using Restlets, how can I read configuration parameters passed in through web.xml? With servlets, context-param can be used. How do I read context parameters from within a Restlet?

+1  A: 

ServerServlet adds all the init parameters from both the servletConfig and from the servletContext to the application context.

So depending on your need, you could either examine the source code for ServerServlet, and read the configuration parameters in the same way, or simply obtain the values from your restlet, or your restlet's application's context.

Stephen Denne
+3  A: 

From the mailing list:

the init parameters are available in the application's context: getApplication().get​Context().getParamet​ers().

In web.xml:

  <context-param>
    <param-name>my.context.param</param-name>
    <param-value>Hello World</param-value>
  </context-param>

In a Restlet's represent method, use:

// => "Hello World"
String result = 
  getApplication().getContext().getParameters().getFirstValue("my.context.param");
Rich Apodaca