Our environment is setup with multiple apache httpd's that serve as reverse proxies to a various backend java servers (mostly tomcat servers).
We'd like to write a script to hit each individual ip address and check for a valid http response.
The httpd's are set up to use virtual hosts, so in order to validate the complete http/html response, we'll need to send http request to the domain name. In other words, sending a http request directly to a specific ip address would result in incorrect html http response from apache.
So, to summarize, we have multiple httpd's listening on multiple ip addresses. For example:
my.domain.com load balanced across:
192.168.11.1 192.168.11.2
We can programmatically update hosts file for each ip address and then make request to the domain name and check each individual ip address that way.
But, is there a way to make http request to a domain and have it resolve to a specific ip address without using hosts file? Maybe there's a java lib that can do this sort of thing programmatically?
Update: This article does a great job of explaining how to set up dns that you can control programmatically: http://rkuzmik.blogspot.com/2006/08/local-managed-dns-java_11.html. I implemented sun.net.spi.nameservice.NameService
, and sun.net.spi.nameservice.NameServiceDescriptor
and was able to specify custom dns entries that way.
One thing to note is that InetAddress
caches domain name/ip addresses aggressively. In other words, for example, once you create a InetAddress
object for my.domain.com
resolving to 127.0.0.1
, it's difficult or impossible to change it while the program is running because of InetAddress
cache.
I think you could also use this (which appears to be a wrapper around the sun stuff I used):
http://www.xbill.org/dnsjava/dnsjava-current/doc/org/xbill/DNS/spi/DNSJavaNameService.html