Re: Single virtual tomcat application which serves multiple contexts

2012-01-20 Thread Pid
On 20/01/2012 15:56, Egor Samarkhanov wrote:
 Hello !
 
 I have multiple clients:
   client 1 - 40 users
   client 2 - 50 users
   client 3 - 60 users
 
 And I have a web application that is supposed to serve the clients.
 The application is deployed into Tomcat. Each client has it's own database.
 
 What I want to implement is the single web application instance which
 servers all  the clients. The client (and the database to connect to)
 is identified by the context path from the URL.
 
 I.e. I imply the following scenario:
 
 1. Some user requestes the http://mydomain.com/client1/
 2. Tomcat invokes a single instance of my application (no matter
which  context is requested)
 3. My application processes the rest of the request thinking that it's
deployed to /client1 context path, i.e. all redirect or relative URLs
should be resolved against http://mydomain.com/client1/
 
 When the client 2 requests the http://mydomain.com/client2/, I want my
 application (the same instance) now process it just like if it was
 deployed to /client2 context path.
 
 Is this possible in Tomcat?

No, it's not.

If you want to build a multi-tenant application, you should:

1. Make your application the ROOT application.
2. Then use the first part of the path to determine which tenant.
3. Use the path data to select a configuration as required.

What is the benefit in making it one application?


p



-- 

[key:62590808]



signature.asc
Description: OpenPGP digital signature


Re: Single virtual tomcat application which serves multiple contexts

2012-01-20 Thread André Warnier

Egor Samarkhanov wrote:

Hello !

I have multiple clients:
  client 1 - 40 users
  client 2 - 50 users
  client 3 - 60 users

And I have a web application that is supposed to serve the clients.
The application is deployed into Tomcat. Each client has it's own database.

What I want to implement is the single web application instance which
servers all  the clients. The client (and the database to connect to)
is identified by the context path from the URL.

I.e. I imply the following scenario:

1. Some user requestes the http://mydomain.com/client1/
2. Tomcat invokes a single instance of my application (no matter
   which  context is requested)
3. My application processes the rest of the request thinking that it's
   deployed to /client1 context path, i.e. all redirect or relative URLs
   should be resolved against http://mydomain.com/client1/

When the client 2 requests the http://mydomain.com/client2/, I want my
application (the same instance) now process it just like if it was
deployed to /client2 context path.

Is this possible in Tomcat?


Personal opinion:

By putting some considerable effort into it, it is certainly possible to do something like 
that, by rewriting URLs and/or proxying and/or making all your pages refer to the context 
etc..


But the question is : why ?
If
- you have many, many clients
- or you application is so big that having multiple copies of it totally fills 
your disk
- or your application for client1 needs to share data with the application for 
client2
then it may be worth thinking about this.

But otherwise, you probably would immensely simplify your life by using a separate virtual 
host for each client, and have for each virtual host a separate appBase, in which you just 
deploy a copy of your application.


Think of the security issues otherwise, to avoid one client being ever able to access the 
data of another; or think of what happens when one of these clients in the future asks you 
for that little change just for him.. etc..


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Single virtual tomcat application which serves multiple contexts

2012-01-20 Thread Egor Samarkhanov
André,

Thanks for your notes! Please see my comments inline.

AW Personal opinion:

AW By putting some considerable effort into it, it is certainly possible to do 
something like 
AW that, by rewriting URLs and/or proxying and/or making all your pages refer 
to the context 
AW etc..

AW But the question is : why ?
AW If
AW - you have many, many clients
Yes, I do have really many clients, and hope to get even more.
And in future I'd like to implement a failover solution with Tomcat
cluster. If i have these many applications deployed, then they will
be deployed on all nodes. I guess it would be much better if one
node contains a single application which can serve any client
(plus session replication). This way the cluster would be more
effective.

AW - or you application is so big that having multiple copies of it totally 
fills your disk
It's pretty big, but the disk space is not the real concern, but
the memory. Many deployments of the same application consume lots of
PermGen.

AW - or your application for client1 needs to share data with the 
application for client2
No, it doesn't.

AW then it may be worth thinking about this.

AW But otherwise, you probably would immensely simplify your life by using a 
separate virtual 
AW host for each client, and have for each virtual host a separate appBase, in 
which you just 
AW deploy a copy of your application.

By the way, I was thinking about virtual hosts, but I didn't find any
solution yet to add new virtual hosts at runtime (to tomcat, or to apache
httpd).

AW Think of the security issues otherwise, to avoid one client being ever able 
to access the 
AW data of another;

Good point.

AW or think of what happens when one of these clients in the future asks you
AW for that little change just for him.. etc..

Yes, thinking about it all the time. But we didn't have such cases for
2 years, and if it happens - we would deploy the customized version to
some other, separate environment.


So, where do I start if I decide to go with the single virtual
application? Did someone try doing such things?



-- 
Best regards,
Egor Samarkhanov (ego...@actimind.com)
Actimind, Inc.


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Single virtual tomcat application which serves multiple contexts

2012-01-20 Thread André Warnier

Egor Samarkhanov wrote:

André,

Thanks for your notes! Please see my comments inline.

AW Personal opinion:

AW By putting some considerable effort into it, it is certainly possible to do something like 
AW that, by rewriting URLs and/or proxying and/or making all your pages refer to the context 
AW etc..


AW But the question is : why ?
AW If
AW - you have many, many clients
Yes, I do have really many clients, and hope to get even more.
And in future I'd like to implement a failover solution with Tomcat
cluster. If i have these many applications deployed, then they will
be deployed on all nodes. I guess it would be much better if one
node contains a single application which can serve any client
(plus session replication). This way the cluster would be more
effective.

AW - or you application is so big that having multiple copies of it totally 
fills your disk
It's pretty big, but the disk space is not the real concern, but
the memory. Many deployments of the same application consume lots of
PermGen.

AW - or your application for client1 needs to share data with the application for 
client2
No, it doesn't.

AW then it may be worth thinking about this.

AW But otherwise, you probably would immensely simplify your life by using a separate virtual 
AW host for each client, and have for each virtual host a separate appBase, in which you just 
AW deploy a copy of your application.


By the way, I was thinking about virtual hosts, but I didn't find any
solution yet to add new virtual hosts at runtime (to tomcat, or to apache
httpd).

AW Think of the security issues otherwise, to avoid one client being ever able to access the 
AW data of another;


Good point.

AW or think of what happens when one of these clients in the future asks you
AW for that little change just for him.. etc..

Yes, thinking about it all the time. But we didn't have such cases for
2 years, and if it happens - we would deploy the customized version to
some other, separate environment.


So, where do I start if I decide to go with the single virtual
application? Did someone try doing such things?

In that case, I would start with an Apache httpd front-end, connected to Tomcat via 
mod_proxy and mod_proxy_ajp, or via mod_jk.  You could then easily proxy any request to 
your single webapp running under Tomcat.

E.g.
http://front-end.company.com/client1/webapp - tomcat:/single_webapp
http://front-end.company.com/client2/webapp - tomcat:/single_webapp
...
http://front-end.company.com/clientn/webapp - tomcat:/single_webapp
and use combinations of Proxy rules, Rewrite rules, SetHeaders rules etc.. to make sure 
that when your webapp returns pages, they correctly continue to refer to client1, 
client2 etc..
You just have to make sure then that your webapp always has enough information available, 
to know for which client it is being called.


You can also do this with virtual hosts at the Apache level, all proxying to the same 
back-end tomcat.  And there are tricks at the Apache level to handle dynamic virtual hosts.



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org