Jonathan,

Thanks for insisting! There is a solution but it isn't fully available yet
:) It is based of the concept of WAR scheme that let you address resources
inside the WAR directory using URIs like "war:///path1/path2/file" (very
similar to file URIs). 

We already have a client connector for the WAR scheme in the Servlet
extension (see the com.noelios.restlet.ext.servlet.ServletWarClient class)
and one for standalone applications (see the
com.noelios.restlet.local.WarClientHelper class). When we complete the
support for WARs in version 1.1 (see
http://restlet.tigris.org/issues/show_bug.cgi?id=76) we will be able to
resolve these WAR URIs directly from the Restlet context's dispatcher, thus
letting you define portable code like:

        SpringContext springContext = new SpringContext(getContext());
        
springContext.getXmlConfigRefs().add("war:///path/spring/config.xml");

For now, you can easily get the ServletContext by casting the Restlet
context to the com.noelios.restlet.ext.servlet.ServletContextAdapter class.
Then you can call the getServletContext() method.

Best regards,
Jerome  

> -----Message d'origine-----
> De : Jonathan Hall [mailto:[EMAIL PROTECTED] 
> Envoyé : mercredi 7 mars 2007 09:53
> À : [email protected]
> Objet : Re: Servlet Context
> 
> Hey Jerome,
> 
> I did have a look at the org.restlet.ext.spring.SpringContext 
> class. It 
> seems it requires:
> 
> SpringContext springContext = new SpringContext(getContext());
> springContext.getXmlConfigRefs().add("RESOURCES");
> 
> Which would be the same inconvenience of hard coding the resource 
> locations.
> 
> With having access to the Servlet Context, you can then access the 
> Spring Context by:
> 
> web.xml
> 
>     <listener>
>         
> <listener-class>org.springframework.web.context.ContextLoaderL
> istener</listener-class>
>     </listener>
>         <context-param>
>         <param-name>contextConfigLocation</param-name>
>         <param-value>
>             /WEB-INF/resources.xml
>         </param-value>
>     </context-param>
> 
> and the previous code.
> 
> This seems to be a popular way to load Spring Contexts. Just 
> a thought.
> 
> Cheers,
> Jonathan Hall
> 
> 
> 
> 
> Jerome Louvel wrote:
> > Hi Jonathan,
> >
> > For this use case, couldn't you leverage the SpringContext 
> class in the
> > org.restlet.ext.spring extension?
> >
> > Best regards,
> > Jerome  
> >
> >   
> >> -----Message d'origine-----
> >> De : Jonathan Hall [mailto:[EMAIL PROTECTED] 
> >> Envoyé : mardi 6 mars 2007 22:27
> >> À : [email protected]
> >> Objet : Re: Servlet Context
> >>
> >> Hi Jerome,
> >>
> >> Thankyou for responding.
> >>
> >> The use case I had in mind was for creating a 
> springContext without 
> >> hardcoding the configuration xml locations:
> >>
> >> WebApplicationContext springContext = 
> >> WebApplicationContextUtils.getWebApplicationContext(getServlet
> >> Context());
> >>
> >> This requires a ServletContext and I couldn't find another way to 
> >> access/cast it.
> >> I haven't looked into it, so I shouldn't really comment if 
> other IoC 
> >> frameworks use this or not.
> >>
> >> If you don't believe this should be added, it is fair 
> enough. It is 
> >> trivial to extend ServerServlet myself and use that. I just 
> >> thought it 
> >> might be useful to have.
> >>
> >> Best Regards,
> >> Jonathan
> >>
> >>
> >>
> >> Jerome Louvel wrote:
> >>     
> >>> Hi Jonathan,
> >>>
> >>> When using the ServerServlet, the Restlet's context already 
> >>>       
> >> wraps the
> >>     
> >>> Servlet's context (logging, resource loading, parameters, 
> >>>       
> >> etc.). Why would
> >>     
> >>> you need a direct access to the Servlet context?
> >>>
> >>> Best regards,
> >>> Jerome  
> >>>
> >>>   
> >>>       
> >>>> -----Message d'origine-----
> >>>> De : Jonathan Hall [mailto:[EMAIL PROTECTED] 
> >>>> Envoyé : mardi 6 mars 2007 20:27
> >>>> À : [email protected]
> >>>> Objet : Servlet Context
> >>>>
> >>>> Hi,
> >>>>
> >>>> I was wondering if a way to access the ServletContext could 
> >>>> be added to 
> >>>> the code. This would be useful for Spring and I presume 
> other IoC 
> >>>> frameworks.
> >>>> It would not tie Restlet to any other libraries or harm it as 
> >>>> far as I 
> >>>> can see.
> >>>>
> >>>> As per shloks example, it would require changes to 
> >>>> com.noelios.restlet.ext.servlet.ServerServlet and 
> >>>> org.restlet.Application
> >>>>
> >>>> com.noelios.restlet.ext.servlet.ServerServlet 
> >>>>
> >>>>     public Application createApplication(Context context) {
> >>>> ...
> >>>>
> >>>>         if (application != null)
> >>>>             application.setServletContext(getServletContext());
> >>>>
> >>>> }
> >>>>
> >>>>
> >>>> org.restlet.Application.java
> >>>>
> >>>>     private ServletContext servletContext = null;
> >>>>
> >>>>     public ServletContext getServletContext() {
> >>>>         return servletContext;
> >>>>     }
> >>>>
> >>>>     public void setServletContext(ServletContext 
> servletContext) {
> >>>>         this.servletContext = servletContext;
> >>>>     }
> >>>>
> >>>> Please let me know what you think,
> >>>>
> >>>> Best Regards,
> >>>> Jonathan
> >>>>
> >>>>     
> >>>>         
> >>>   
> >>>       
> >
> >   

Reply via email to