cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leszek Gawron <lgaw...@mobilebox.pl>
Subject Spring integration: accessing servlet context
Date Wed, 28 Jul 2004 08:35:58 GMT
When integrating web application with Spring one needs to use 
org.springframework.web.context.ContextLoaderListener. This listener 
registers spring ApplicationContext in web application's servlet context.

In the application you fetch spring application context via:

org.springframework.web.context.support.WebApplicationContextUtils
      .getWebApplicationContext(javax.servlet.ServletContext sc)

The problem is: how can I get access to cocoon's bare servlet context (I 
know that breaks the abstraction but who cares)?

Or how can I implement this functionality without direct acces to 
ServletContext (WebApplicationContextUtils source):

> public static WebApplicationContext getWebApplicationContext(ServletContext sc) {
> 	Object attr = sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
> 	if (attr == null) {
> 		return null;
> 	}
> 	if (attr instanceof RuntimeException) {
> 		throw (RuntimeException) attr;
> 	}
> 	if (attr instanceof Error) {
> 		throw (Error) attr;
> 	}
> 	if (!(attr instanceof WebApplicationContext)) {
> 		throw new IllegalStateException("Root context attribute is not of type WebApplicationContext:
" + attr);
> 	}
> 	return (WebApplicationContext) attr;
> }

Would does cocoon context reach to ServletContext to resolve the attributes?

-- 
Leszek Gawron                                      lgawron@mobilebox.pl
Project Manager                                    MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65


Mime
View raw message