Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.

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...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top