Reputation: 29014
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?
Upvotes: 2
Views: 2705
Reputation: 29014
From the mailing list:
the init parameters are available in the application's context: getApplication().getContext().getParameters().
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");
Upvotes: 3
Reputation: 37047
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.
Upvotes: 1