tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Johnson <>
Subject What port am I running on?
Date Mon, 25 Apr 2005 21:32:22 GMT
If I am running some code on a tomcat server, and I don't have a request object available (for
instance, if I have a timed task that is not dependent on a request....), how can I
programmatically retrieve the port that requests are being served on?  In other words, how
can I
retrieve information about the server itself? After Googling around, I found an approach that
not exactly what I'm looking for...but it seems close. But, the disclaimer around this comment
that the code is "nonstandard".

>How do I get direct access to a Tomcat Realm?

>Credit: This code is from a post by Yoav Shapira [WWW] in the

>Sometimes access directly into the Tomcat realm object is needed; to do, this the following
can be used. Be aware, however, that by using this, your application is relying on a Tomcat
extension and is therefore non-standard.

Server server = ServerFactory.getServer();
//Note, this assumes the Container is "Catalina"
Service service = server.findService("Catalina");
Engine engine = (Engine) service.getContainer();
Host host = (Host) engine.findChild(engine.getDefaultHost());
//Note, this assumes your context is "myContext"
Context context = (Context) host.findChild("myContext");
Realm realm = context.getRealm();

So, what is the RIGHT way to get access to server objects? I have looked at this document:

JDBC resources and custom resources are treated in that document. But, is there a way to get
server objects? How would I find a list of the objects that might be available....and which
would have the port number? Or is there another solution, rather than JNDI?

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message