|
From: Cameron B. <ca...@da...> - 2004-03-18 15:43:23
|
I actually don't have this working with factories...
I think my knowledge of spring's internals still leaves a lot to be desired
;)
If one of the spring developers would like to help, you know where to reach
me ;)
Thanks.
Cameron
_____
From: spr...@li...
[mailto:spr...@li...] On Behalf Of
Cameron Braid
Sent: Friday, 19 March 2004 1:16 AM
To: spr...@li...
Subject: [Springframework-developer] Spring Web .. New idea :
requestContext.xml
I have wanted to use filters in a similiar way that you can use servlets
with the FrameworkServlet class - having servletName-servlet.xml as a child
context, in an web app. Thus creating a servlet scoped bean factory.
I wish to have a request scoped bean factory, so what I have done is this :
Coppied the FrameworkServlet class into
org.springframework.filter.FrameworkFilter .
I basically change the keywords servlet to filter, Servlet to Filter,
getServletName() to getFilterName()
I fixed all compile bugs
I made some little changes.
I changed the class hierarchy so that it extends OncePerRequestFilter
I stripped out the RequestHandledEvent sending
I introduced two new interfaces :
public interface HttpServletRequestAware {
public void setHttpServletRequest(HttpServletRequest httpServletRequest)
throws Exception;
}
public interface HttpServletResponseAware {
public void setHttpServletResponse(HttpServletResponse
httpServletResponse) throws Exception;
}
I created a FactoryFilterPostProcessor to set the request and response onto
beans created within this context that implement these interfaces.
I also implemented a filter that extends FrameworkFilter called
RequestContextFilterBean that gets every bean defined in this context and
sets it as a request attribute.
NOW : I can easily create request scoped beans just by adding them to this
new xml file.
I can use normal bean refrences to bind application scoped beans onto the
new request scoped beans, request scoped beans can depend on each other.
Request scoped beans can be aware of their application context, the servlet
context, the current request, the current response.
It works with factories as well.
I had to use some hacks to get the factories to work, since I need to add
the special postProcessor into the beanFactory's post processor list.
I have this all implemented, without tests, and partial docs.
Is anyone interested in using this.
Does it sound like a valuable addition to spring ?
A driving force for me doing this is I was often either
a) writing filters that created new objects, and placed them in the request
b) adding request scoped objects to my freemarker views by extending the
freemarker servlet
c) adding request scoped objects to my webwork actions by using interceptors
and in doing so I would often need to create custom factory classes, and use
request attributes to bind them together.
This was problematic because
- the filters had to be in the correct order.
- colaborating components needed to either use static methods to lookup
other request scoped beans, or use named request attributes to look them up
Moving all of this into a requestContext.xml has certainly simplified and
standardised this.
It also removes it from my webwork and freemarker dependencies.
The attached patch and example web.xml and requestContext-filter.xml files
will be a starting point for someone to review what I have done.
It is getting late here (1:10am) so I will leave preparing a working demo
until tomorrow.
Thanks for taking the time to read this, and I am certainly looking forward
to some feedback.
Cameron
|