simon wrote:
On Fri, 2008-06-13 at 08:14 +0200, Lilianne E. Blaze wrote:
Hello,
I need something that works more or less like a default servlet (serving static resources, basic caching, etc), but container-neutral and with a possibility to call it from a filter. I think your ResourceServlet can be easily adapted to that role (it will probably need to be 'dumbed down' in fact). As I understand it, ASF licence allows me to use it? What I need exactly is to take ResourceServlet and the classes it needs, wrap it in a subclass / glue code providing some sensible defaults, pack it in a jar, then pack it all in a .war with some other ASF and LGPL code and some of my own (commercial / closed source). I'm willing to publish the glue code with ASF licence in case anyone needs it too.

I am allowed to do it, right? Would that be ok with you?

Alternatively, do you know of any project which would be more suitable?

I'm not sure which project you're referring to, ie which the
ResourceServlet is in.

Trinidad.

Take a look at http://platform.xwiki.org/xwiki/bin/view/Main/ShortURLs , it's quite a good example of the problem I'm trying to solve - one main controller servlet mapped at /* , not allowing direct access to for example /images/*

Note the config code under "Servlet mapping name". Quite ugly, and completely dependent on a single container. Unacceptable.

What I need is two things - first a filter which acts like a pre-controller, allowing to - depending on some simple rules - proceed as normal, force 404 error, or force "default" behavior - that is serve a resource as a plain httpd would.

Now if I could just do something like ServletContext.getNamedDispatcher("default").forward(req,res); second part would be unnecessary, but it seems it just doesn't work. Shame. Making "default" and "jsp" servlets mandatory and visible by the Servlet/JSP specs would really make a lot of hackish things much easier.

So - I need something that would, basically, act like default servlet, the one which serves everything expect jsps in the default, no-web.xml-included scenario.

So, I got the idea to take your ResourceServlet and dumb it down to plain httpd level. Writing it from scratch would be easy, sure, but I thought that it'd be better to base it on a widely-used project to 'inherit' handling of caching, special cases, all the things which really benefit from wide usage and testing.

First I tried subclassing ResourceServlet - no offence, but it was a pain, it's too monolithic and closed, too many dependencies, too many private things. It seems it simply wasn't designed to be subclassable. Also it seems to depend on Faces everywhere, when no such dependency is necessary? At least, not in such a basic scenario as mine. Why not split it into a base framework-agnostic servlet, faces-friendly servlet subclass, and move anything that can be moved to a static-utils class? I don't mean to be ill-mannered, especially since I just joined and only to borrow your code, just writing how I see it.

Next thing I did I just started a new class, copied what I needed into it, then ended up with a ~80 lined Servlet and ~160 lined static utils class, with ResourceLoader and ServletContextResourceLoader the only direct imports. Pretty much done.

You're welcome to check the code at http://www.lilianne-blaze.net/temp_downloads/

It's proof-of-concept quality, and the pre-controller is hardcoded for example paths, but it pretty much works. As for legalese, treat it as ASF 2.0, though I'd very likely rewrite it before officially publishing.

I'd very much appreciate any feedback.


But in any case, you are very welcome to use any ASF code in your own 
applications. The ASF license specifically allows that. Make sure you leave the 
licensing comments that are at the top of the file.

If you do make some bugfixes or improvements then it is not mandatory to 
contribute them back but it would be appreciated.

Note that the final definition of what is and is not allowed is the apache 
license itself. If in doubt, read that. You'll find more info here:
 http://apache.org/licenses/

But AFAIK the ASF has never sued anyone over use of its code, and it is 
extremely unlikely that it ever will happen. The license is designed to allow 
use of the code in almost any way, including within proprietary applications 
(unlike the GPL for example).

You might also want to check out the weblets project:
  weblets.dev.java.net

Regards,
Simon


Greetings, Lilianne


Reply via email to