On mar, 2008-09-23 at 10:37 +0200, Thierry Boileau wrote:
> Hello Paolo,
>
Hi Thierry,
thanks, things seem to be working now, I still have a minor problem
though (see below).
> thanks for your test code it helps us to find a bug regarding the
> Restlet attached with the "attachDefault" method to virtual hosts.
> That bug was part of your problem. The fix is available in the svn
> repository.
>
> Now, let me explain the other part that is is due to some changes that
> have been made with RC1, regarding configuration of servlet [1] and
> management of context [2].
>
> There are several ways to refactor your code and web.xml file:
> 1/ use the component by default and specify only the application in
> the web.xml (i.e. remove the "org.restlet.component" parameter). This
> is called "mode 3" in [1]
> 2/ use your custom component. This is called "mode 2" in [1]. In this
> case:
> a/ remove there "org.restlet.application" parameter from the
> web.xml because it is useless.
> b/ let the constructor with the context of the TestApplication
> class since you need some customization. In this case, the context
> that is passed to the constructor is no more the parent context, but a
> "child" context. That is to say, in your TestComponent#init method you
> must change the way you instantiate the TestApplication class:
> testApplication = new
> TestApplication(this.getContext().createChildContext());
>
> I hope that my explanations are clear enough. Do not hesitate to ask
> more questions.
>
The explanations are clear and I choose (2) since in my real app I'd
like to have more than one Applications in the Component. However I have
a hard time propagating the "context-param" I set in web.xml to the app:
as far as I understand what happens is
1) the component gets created
2) the app is created in the component constructor using a child context
3) the restlet integration with tomcat reads the params in the web.xml
and puts them in the component context
So the application has no way to access those context-params since a) it
doesn't have access to the component context and b) those params are not
automatically propagated to the child context passed to the app since
the are added to the component context *after* the child context is
created.
The workaround I found is to override component.start() and there read
the param from the component context (since at that point it contains
them) and manually add them in the app context so that I can read them
in app.createRoot(). Do you see problems with this approach?
I think it would be cool if a context could be created and popoulated
with the web.xml params *before* the creating the component and passed
to the component constructor... do you think this would be possible?
Ciao and thanks again for your help,
Paolo