2

My application is deployed in websphere server and from java code, I need to get listening port of the server.

NOTE: I am using below line for getting internal host name of the system. InetAddress.getLocalHost().getHostName();

EDIT: Our server is running on local port 30036 and a local host name. We cannot connect this server using these host and port from out side. We have separate public host/port for outside connection. But in our scenario, we want to access a service running on the same server from the java code. Any way to get this internal port dynamically?

Tapas Jena
  • 1,069
  • 4
  • 14
  • 23
  • 1
    possible duplicate of [How to get Websphere 6.1 port number](http://stackoverflow.com/questions/264764/how-to-get-websphere-6-1-port-number) – Jan Chrbolka Apr 08 '15 at 02:21

1 Answers1

1

You should be able to access request.getLocalPort() in your service methods (get, post, service, etc). That will tell you what port the request came in on. It's possible it got changed during routing somewhere, and that the port the server is listening on isn't exactly what the client knows about, but if that's the case there's absolutely no where for the server to be able to know that.

Hailey
  • 318
  • 1
  • 6
  • `request.getLocalPort()` will return me the external port by which clients can connect. My requirement is to get internal port number on which server listening. – Tapas Jena Apr 08 '15 at 02:24
  • Do you have a reason to believe the two are different? Like, I don't see how it's useful to get an internal port -the only one that really matters is the one that clients connect to - it's a websever, eh? – Hailey Apr 08 '15 at 02:25
  • Enterprise servers run on different internal port and internal host for security reason. External host and external are used to connect form outside clients but you cannot connect from same server to same server by using external host/port. – Tapas Jena Apr 08 '15 at 02:35
  • 1
    Then your network is setup drastically different than mine (one of the 600 most valuable companies in the world). Running on internal ports for "security reasons" makes literally zero logical sense. If a user can connect, a user can connect, plain and simple. – Hailey Apr 08 '15 at 02:40
  • Confused between 'request.getLocalPort()' and 'request.getServerPort()'. Looks like 'request.getLocalPort()' is giving correct port. – Tapas Jena Apr 08 '15 at 04:36