tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Johnson <gre...@yahoo.com>
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
is
not exactly what I'm looking for...but it seems close. But, the disclaimer around this comment
is
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] http://www.yoavshapira.com in the
user
list

>Sometimes access directly into the Tomcat realm object is needed; to do, this the following
code
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:
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources-howto.html

JDBC resources and custom resources are treated in that document. But, is there a way to get
other
server objects? How would I find a list of the objects that might be available....and which
one
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 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message