Re: Finding Server URL?

2005-06-24 Thread Brad Johanson
On 6/23/05, Michael Jouravlev [EMAIL PROTECTED] wrote:

 On 6/23/05, Brad Johanson [EMAIL PROTECTED] wrote:
  The problem I'm
  running into is how the singleton can find the root URL/server URL
  (and port) for the Tomcat server in which it is running (for example,
  http://167.7.9.95:8080 or http://www.foo-co.com).
 
 Maybe InetAddress can help you?

Thank you for the suggestion.  That will give me an IP address for the
machine (and DNS name if there is one) of one of the interfaces on the
machine (the primary?).  Like so:

String IP=InetAddress.getLocalHost().getHostAddress();

This is what I'm actually doing right now to get the main IP/DNS. 
What it doesn't give me is the port on which tomcat is listening. 
That is specified in the conf/server.xml file, but I can't figure out
how to access that information from within the servlet code.  For now
I'm passing it in as a system property, but this is not very elegant
or portable.  It would be nicer to just be able to ask Tomcat directly
since it is already configured somewhere in the tomcat active state.

-Brad

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Finding Server URL?

2005-06-23 Thread Brad Johanson
I hope this is the right place to post this-- I've searched the web,
usenet, and archives of this and the tomcat-user mailing list with no
success.

I have a Servlet I'm developing that uses a singleton to collect
network traffic information through socket-based non-web/servlet
mechanisms.  The singleton gets loaded at startup since the servlet
loads at startup.  Users access the servlet page to view the latest
stats which are retrieved from the singleton.

Now the problem:  the server may run on a variety of machines, and
clients use an out of band mechanism to retrieve the URL to use to
access the servlet.  They do this by contacting the singleton (which
has its own threads for socket based communication), then trigger
display of the returned URL in the local web browser.  The problem I'm
running into is how the singleton can find the root URL/server URL
(and port) for the Tomcat server in which it is running (for example,
http://167.7.9.95:8080 or http://www.foo-co.com).  Once I have that
information I can append the root-relative path to the actual servlet.

Does anybody have any suggestions on how to get this information?  I
need to be able to do so before any requests come in, since the first
request won't happen until the singleton sends out the address to use.
 There don't appear to be any methods of ServletContext() that yield
this information, nor do their to appear to be any servlet context
attributes set by tomcat with this information.  I can figure it out
from an HttpServletRequest object, but as I said, I won't receive one
of those until later.

If this is a bad idea for some reason, let me know, and please offer a
better way of going about this.

Thanks,

-Brad

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Finding Server URL?

2005-06-23 Thread Michael Jouravlev
Maybe InetAddress can help you?

On 6/23/05, Brad Johanson [EMAIL PROTECTED] wrote:
 The problem I'm
 running into is how the singleton can find the root URL/server URL
 (and port) for the Tomcat server in which it is running (for example,
 http://167.7.9.95:8080 or http://www.foo-co.com).

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]