Configuration of resources in Restlet Router

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Configuration of resources in Restlet Router

Stephane Fellah
I posted this question on StackOverflow and remained unanswered. I am hoping I will get better luck and posting it here.

I am currently building a Restlet application where I need to build the router from a configuration file. The router has different endpoints using the SAME resource but configured with different settings defined in a configuration file. Usually routers are defined using template route with target resource class. This would not work in my case, as the resource needs to be initialized with the different settings. I can see one way to solve this problem : using a Filter that set the initialization parameters in the context, the filter with then forward to the target resource. The target resource will read the initialization parameters from context in the doInit(). Is it the best practice to handle this use case ? Should I use Restlet or Finder instead of Filter.

Thanks for your help.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3070534
Reply | Threaded
Open this post in threaded view
|

Re: Configuration of resources in Restlet Router

Tim Peierls
On Thu, Dec 19, 2013 at 11:27 AM, Stephane Fellah <[hidden email]> wrote:
I am currently building a Restlet application where I need to build the router from a configuration file. The router has different endpoints using the SAME resource but configured with different settings defined in a configuration file. Usually routers are defined using template route with target resource class. This would not work in my case, as the resource needs to be initialized with the different settings. I can see one way to solve this problem : using a Filter that set the initialization parameters in the context, the filter with then forward to the target resource. The target resource will read the initialization parameters from context in the doInit(). Is it the best practice to handle this use case ? Should I use Restlet or Finder instead of Filter.

That's a reasonable way to go. 

Another way that avoids passing values via the Context is to use custom Finder that creates and initializes the resource in an overridden create(Class, Request, Response), either by calling super.create(targetClass, request, response) and setting the initialization parameters on the returned value, or by re-implementing create(Class, Request, Response) entirely.

--tim