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.ContextLoaderListener</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
À : discuss@restlet.tigris.org
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
À : discuss@restlet.tigris.org
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