tags:

views:

362

answers:

5

Hi I have an application running in tomcat,as well as Weblogic and Websphere I need to determine which port the application is running and display on the UI Is there any JAVA api to find that

+1  A: 

If your application is already accessed through that port, you can easily get it from HTTPRequest.

inkredibl
A: 

Well, ServletRequest#getServerPort(), but in order to open your application the users must know the port in advance, so that wouldn't be very useful.

Bozho
The local port is probably not what he's looking for: http://www.coderanch.com/t/169457/Web-Component-Certification-SCWCD/certification/getLocalPort
Thomas Jung
ah, yes, thanks.
Bozho
A: 

As mentioned by inkredibl the ServletRequest method getServerPort provides this information:

Returns the port number to which the request was sent. It is the value of the part after ":" in the Host header value, if any, or the server port where the client connection was accepted on.

Thomas Jung
A: 

You can't ask a server from the outside for which ports are used by which application. (Ahh, you cam try, but it shouldn't tell). That's obviously a security feature (you could start a port scan, but I guess, that's not exactly what you want...or?)

So the only way out - the application needs to communicate its port number to outer space, either by a simple web page, where the actual port number is desplayed (human-machine-interface) or a separate webservice with a static port number, where a client can request the actual server properties (machine-machine-interface).

(Note: I assumed, the 'UI' is a client application...)

Andreas_D
A: 

Is there any Tomcat API or configuration available which can tell an application (probably on startup), what port its running on without a request??

Vinay Kumar