You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Johnny Kewl <jo...@kewlstuff.co.za> on 2007/05/18 22:44:04 UTC

Overriding Default Servlet?

Read some tomcat docs where it said one can override the default servlet... and then it gets a little cocky and says if you cant read the code... this is not for you (pleb!) 

So this plebian is asking... wot does override actually mean??

I do know that if one creates a servlet and say maps it as /*.... that will effectively block the default servlet.... is that wot override means?

Or and this is wot I'm hoping.... does it mean one can "extend" it... as in...
     Class MagicDefault extends Default

Anyway if it can be overriden in true class form without a recompile of Tomcat.... it gets very interesting?... if so please tell me how... thx

________________________________________________________________

Johnny Kewl 
  eMail: John<No Spam>kewlstuff.co.za  -- replace <No Spam> with @ --
  Cell: +027-72- 473-9331
Java Developer (Tomcat Aficionado)
  Free Tomcat software at  http://coolese.100free.com/
________________________________________________________________

Re: Overriding Default Servlet?

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Thanks everyone for the info.... magic mailing list this!
My interest in the default servlet is 2 fold....

A Resin user asked whether tomcat could do this....
   <path-mapping url-pattern="/activeadv/*"
real-path="/doc_root/activeadv/"/>

   <path-mapping url-pattern="/includes/*"
real-path="/doc_root/includes/"/>

I thought... be kind of cool to add that functionality and maybe extend it 
to full paths on HTML PDF files
files... so one can serve up isolated sites installed on a machine (outside 
of a web-app)... like for example the SUN tutorial.   its a nice way do turn 
tomcat into a full document system for entire machine... as well as allow 
for some additional mapping... a question that seems to come up over and 
over again... naturally JSPs will have to be relative paths.

The other thing... is that if one looks at the default servlet code... the 
thing can do XSLT XML transformations, but one cant see that functionality 
in the Generic servlet....

So I guess from previous discussion... the thing to do its create a 
DefaultHttpServlet.... which extends HttpServlet.
Use Tims trick
{
   getServletContext().getNamedDispatcher("default")
                      .forward(request, response);
   return;
}
to pull in the safe functionality... ie exclude things like PUTs... and make 
default file serving something that one can turn on and off.... in the 
Servlet that
extends DefaultHttpServlet.... probably best way is as overridable 
function.... call super if you want default file serving etc...
Then... "Recreate" the XSLT XML inheritable functionality....

Regards... Johnny 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Overriding Default Servlet?

Posted by Tim Funk <fu...@joedog.org>.
It can be extended like any other java class.  In reality - there are 
probably 2 better solutions than extending (or replacing) the Default 
Servlet.

1) Create a filter which does what you need then pass control to the 
default servlet. (chain.doFilter())
2) Create your own default servlet but in cases where you'd rather use 
the default servlet instead of your own - use the following code:
{
   getServletContext().getNamedDispatcher("default")
                      .forward(request, response);
   return;
}

-Tim

Johnny Kewl wrote:
> Read some tomcat docs where it said one can override the default servlet... and then it gets a little cocky and says if you cant read the code... this is not for you (pleb!) 
> 
> So this plebian is asking... wot does override actually mean??
> 
> I do know that if one creates a servlet and say maps it as /*.... that will effectively block the default servlet.... is that wot override means?
> 
> Or and this is wot I'm hoping.... does it mean one can "extend" it... as in...
>      Class MagicDefault extends Default
> 
> Anyway if it can be overriden in true class form without a recompile of Tomcat.... it gets very interesting?... if so please tell me how... thx
> 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Overriding Default Servlet?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Johnny,

Johnny Kewl wrote:
> So this plebian is asking... wot does override actually mean??
> 
> I do know that if one creates a servlet and say maps it as /*....
> that will effectively block the default servlet.... is that wot
> override means?

Yes, but you should map it to "/" to match the default servlet's mapping.

> Or and this is wot I'm hoping.... does it mean one can "extend" it...
> as in... Class MagicDefault extends Default

Absolutely. The default servlet is
org.apache.catalina.servlets.DefaultServlet (at least in my TC 5.5 install).

> Anyway if it can be overriden in true class form without a recompile
> of Tomcat.... it gets very interesting?... if so please tell me
> how... thx

Yeah, you don't need to recompile Tomcat. Just write your own servlet
class to act as the default (you can subclass the above DefaultServlet
if you want) and then map it appropriately.

Note that depending on a particular version of TC for the DefaultServlet
might lock you into an undesirable position. I don't think that the
Tomcat folks see the DefaultServlet as part of any publicly-facing code,
so they may make changes at any point. You should be careful about this.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGTi1K9CaO5/Lv0PARAihdAKCj0Z955qzpQ0RYzfIv6T+exapppACfXeX4
Yh7NRb1pRrMOcWGxt51Nguw=
=izGB
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org