Reputation: 3036
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
Upvotes: 1
Views: 4143
Reputation: 1993
If your application is already accessed through that port, you can easily get it from HttpServletRequest
.
Upvotes: 1
Reputation: 114817
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...)
Upvotes: 0
Reputation: 33092
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.
Upvotes: 0