aspose file tools*
The moose likes Tomcat and the fly likes Get the virtual host name from the tomcat server.xml using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Get the virtual host name from the tomcat server.xml using java" Watch "Get the virtual host name from the tomcat server.xml using java" New topic
Author

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

Sunny Bhinde
Greenhorn

Joined: Aug 14, 2012
Posts: 3

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

Joined: Mar 16, 2001
Posts: 986

The first thing which comes to mind is reading the file, and parsing out what you want.


Please ignore post, I have no idea what I am talking about.
Sunny Bhinde
Greenhorn

Joined: Aug 14, 2012
Posts: 3
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

Joined: Jun 25, 2001
Posts: 16137
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get the virtual host name from the tomcat server.xml using java