You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Shannon Bradshaw <br...@infolab.ils.nwu.edu> on 2000/09/29 20:52:22 UTC

Different URLs for different instances of the same servlet

I'm building an application for which I need to treat servlets as both
servlets called from a Web browser and RMI-accessible objects to be called
from other components in a distributed system.  I'd like to write a servlet
class for which I can run instances that persist for the duration of a user
session and can be referenced with urls distinguished from one another using
a session identifier.  The HttpSession API won't work for me as I need the
objects to be more than simply attribute holders, and want each "Session
Servlet" to run in parallel with the others.

I have been experimenting with Tomcat, but have found not workable solution.
Does anyone know if there is a way of creating multiple instances of a
servlet that are referenced using distinct urls in Tomcat?  Is there some
other container that permits this?

Thanks,
-Shannon


RE: Different URLs for different instances of the same servlet

Posted by Shannon Bradshaw <br...@infolab.ils.nwu.edu>.
Thanks for the quick response.

Also, thanks for the architecture suggestion.

-Shannon

> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
> Sent: Friday, September 29, 2000 2:09 PM
> To: tomcat-user@jakarta.apache.org
> Subject: Re: Different URLs for different instances of the same servlet
>
>
> Shannon Bradshaw wrote:
>
> > I'm building an application for which I need to treat servlets as both
> > servlets called from a Web browser and RMI-accessible objects
> to be called
> > from other components in a distributed system.  I'd like to
> write a servlet
> > class for which I can run instances that persist for the
> duration of a user
> > session and can be referenced with urls distinguished from one
> another using
> > a session identifier.  The HttpSession API won't work for me as
> I need the
> > objects to be more than simply attribute holders, and want each "Session
> > Servlet" to run in parallel with the others.
> >
> > I have been experimenting with Tomcat, but have found not
> workable solution.
> > Does anyone know if there is a way of creating multiple instances of a
> > servlet that are referenced using distinct urls in Tomcat?  Is
> there some
> > other container that permits this?
> >
>
> If you create individual servlet definitions in web.xml (i.e.
> separate <servlet>
> tags), you will have separate servlet instances even if it is the
> same servlet
> class.  Then, you can use individual <servlet-mapping> entries to
> establish
> individual URL paths. Note, though, that the servlet
> specification gives you
> *zero* guarantees about how long your servlet instances will persist.
>
> However, I strongly urge you to reconsider your architecture.
>
> What it sounds like you are trying to do is create some server
> functionality
> that is available to both HTTP clients and RMI clients, right?  A better
> approach would be to encapsulate the shared part of the functionality into
> JavaBeans that are not cognizant of how they are being called.
> Then, create a
> servlet that translates request parameters into appropriate
> method calls on
> these beans, and an RMI server class that does the same thing.
>
> Trying to use the same physical object for both client interfaces
> violates basic
> object oriented design principles, where you want each object to
> have one and
> only one purpose in life.  If you separate the functionality as
> suggested above,
> you will find things are tremendously easier to implement and maintain.
>
> >
> > Thanks,
> > -Shannon
>
> Craig McClanahan
>
> ====================
> See you at ApacheCon Europe <http://www.apachecon.com>!
> Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
> Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
>                                     Applications to Tomcat
>
>
>


Re: Different URLs for different instances of the same servlet

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Shannon Bradshaw wrote:

> I'm building an application for which I need to treat servlets as both
> servlets called from a Web browser and RMI-accessible objects to be called
> from other components in a distributed system.  I'd like to write a servlet
> class for which I can run instances that persist for the duration of a user
> session and can be referenced with urls distinguished from one another using
> a session identifier.  The HttpSession API won't work for me as I need the
> objects to be more than simply attribute holders, and want each "Session
> Servlet" to run in parallel with the others.
>
> I have been experimenting with Tomcat, but have found not workable solution.
> Does anyone know if there is a way of creating multiple instances of a
> servlet that are referenced using distinct urls in Tomcat?  Is there some
> other container that permits this?
>

If you create individual servlet definitions in web.xml (i.e. separate <servlet>
tags), you will have separate servlet instances even if it is the same servlet
class.  Then, you can use individual <servlet-mapping> entries to establish
individual URL paths. Note, though, that the servlet specification gives you
*zero* guarantees about how long your servlet instances will persist.

However, I strongly urge you to reconsider your architecture.

What it sounds like you are trying to do is create some server functionality
that is available to both HTTP clients and RMI clients, right?  A better
approach would be to encapsulate the shared part of the functionality into
JavaBeans that are not cognizant of how they are being called.  Then, create a
servlet that translates request parameters into appropriate method calls on
these beans, and an RMI server class that does the same thing.

Trying to use the same physical object for both client interfaces violates basic
object oriented design principles, where you want each object to have one and
only one purpose in life.  If you separate the functionality as suggested above,
you will find things are tremendously easier to implement and maintain.

>
> Thanks,
> -Shannon

Craig McClanahan

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat