• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 28424
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic