Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get the virtual host name from the tomcat server.xml using java

 
Sunny Bhinde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In the Tomcat server.xml there are multiple host(virtual host),so now using java code i need get all the Host in arraylist.
I am unable to find out the proper solutions.Is there any that can help me out?
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing which comes to mind is reading the file, and parsing out what you want.
 
Sunny Bhinde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Willam,
I need to get host name let take an example:
if there are 3 virtual host in the server.xml i.e
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
</Host>
<Host name="abc.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
</Host>
<Host name="xyz.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
</Host>

so now i need array contains the host name i.e {"localhost","abc.com ","xyz.com"}

I hope you got
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18014
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting the virtual host names as a general collection from the Tomcat server.xml file is relatively straightforward. You can do anything from a mindless "grep" to a full-blown XSLT or Digester app.

Getting the virtual host names that a single webapp is running under from inside the webapp is quite a different story.

Most Tomcat users think of webapps in terms of exploded WAR files, so there's one instance of the WAR directory for each deployed instance of that webapp. However, that's a Tomcat quirk. You can (and I routinely do) deploy a WAR in the strict J2EE sense of an actual WAR file. For example, I can deploy the file "/opt/javaranch/webapps/forum.war" as many times as I want into as many hosts as I want under as many Contexts as I want in as many Tomcat instances as I want (allowing for hardware limitations). There's absolutely no way that the webapp itself can enumerate all the virtualhost names that it is running under - especially in cases where there are several different Tomcat JVMs using it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic