The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

"Virtual Hosting" and servlets.

(I hope this is the right forum...)

I am writing a Java servlet that will be dynamically adding(and subtracting) arbitrary domain names to the list it will answer to.

The thing is, its not entirely clear how to tell the servlet container I want to do this. In particular, I want 1 servlet to answer these requests.

The digging I have done on Google has been ineffectual, and so far the only "solution" I have been toying with is to use something like Jetty and hook into it at a lower level API than the servlet API...
Confused by servlets...
Wednesday, April 16, 2008
 
 
Your request is vague. If you have two domains:

xyz.com

and

zys.com

...it's the dns that determines where they point to. If you have two domains like this:

xyz.com/xxx

and

xyz.com/yyy

...it's trivial to allow a servlet to either respond to or ignore requests based upon the path.
my name is here
Wednesday, April 16, 2008
 
 
I want the same servlet to respond to multiple domains. I understand that I need DNS to point at the same webserver, but I want 1 servlet to respond to:

xyz.com

and

zys.com

So, the same doPost/doGet methods in the same address space will respond to ALL requests directed to xyz.com (any path) and zys.com (any path), and be able to add more domains that it will respond to dynamically(so tomorrow, without restarting anything, I can add abc.com too).

The DNS part is not what I'm confused by, its how to get Tomcat or Jetty or some other container to respond to any domain and send the request to the same running servlet. And I would rather not use URL rewriting on the front end.
Confused by servlets...
Wednesday, April 16, 2008
 
 
Tomcat (and probably Jetty) will accept requests from any domain by default.  You don't need to do anything extra to support this.  This is probably why you're finding it difficult to get this question answered through Google searches.

Where virtual hosts come in is if you want DIFFERENT web applications to handle different domains on the same physical Tomcat installation.  Since you want the same servlet to handle all requests coming in to your Tomcat, you don't have to do anything.

So, set up Tomcat, and simply configure DNS to point all of your domain names to the same physical webserver's IP address, you should be golden.

You can test this on your development environment by making host file entries for several domains and pointing them to your Tomcat IP address, then opening those domains in your browser.  They should all open your web application.
Dan Fleet Send private email
Thursday, April 17, 2008
 
 
Your request is kind of confusing, but assuming Dan Fleet has correctly deciphered it, and your goal is to maintain a programmatic whitelist of domains to respond to, you could use http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletRequest.html#getRemoteHost() to get the hostname of your requester and check it against your whitelist, inside your servlet.
N Clow
Thursday, April 17, 2008
 
 
I think what he wants is this. If these two domains point to a tomcat server:

xxx.com

zzz.com

...he wants them to resolve to different webapps (by default they will default to ROOT). So,

xxx.com  ->  /webapps/xxx/

yyy.com  -.  /webapps/yyy/

I don't think this can be done easily. You might have to hook apache up to tomcat and use mod_rewrite, or hack up a solution where a jsp page at ROOT looks at the domain and forwards it.
my name is here
Thursday, April 17, 2008
 
 
Dan Fleet nailed it.

Thanks, that was exactly what I needed to know.

Including the part I hadn't ask, of how to test this setup :)

I'm sorry that my question was phrased awkward, but when you know what you want to do, but don't know how to phrase it, its rather hard to figure out what to search for.
Confused by servlets...
Thursday, April 17, 2008
 
 
"I don't think this can be done easily. "

While the original poster doesn't actually want separate webapps for separate domains, Tomcat does support virtual host out of the box for those users who DO want separate webapps to be mapped to separate domains.  Apache and URL rewriting is not needed.
Dan Fleet Send private email
Thursday, April 17, 2008
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz