1

I wish to get the server name and the current application's port on server startup. I managed to get the host name and address with:

hostName = InetAddress.getLocalHost().getHostName();
hostAddress = InetAddress.getLocalHost().getHostAddress();

But I can't get the port.

I am aware of ServletRequest getPort() method, but my application doesn't always runs with a request and sometimes actions are being executed via MQ. Therefor, I can't rely on requests.

I am using spring, if it matters.

Can anyone help me find the port?

Thank you,

Idob

Ido Barash
  • 4,856
  • 11
  • 41
  • 78
  • Do you mean that you want to know on which port the webserver runs in your app server? You do know that is different from the MQ port and any other service running in the app server? – Anders R. Bystrup Oct 09 '12 at 08:07
  • yes I do. Because my app runs on different servers and not always on the same port. I need a way to know that port. – Ido Barash Oct 09 '12 at 08:09
  • 1
    OK, please explain how your webapp receives requests via MQ and how that relates to which port HTTP runs on then? Also, why do you need to know the port number? – Anders R. Bystrup Oct 09 '12 at 08:11
  • It is a beat complicated and I cant expose this data here on the web. Company policy. But basically, there are two channels in: one is CXF service, and the other is the MQ which only other applications of our company use. – Ido Barash Oct 09 '12 at 08:15

1 Answers1

2

As I understand your problem you have a CXF servlet running on some port and you wish to obtain this port programmatically - and then you have some requests coming via MQ and since you mention an application server I will assume that these requests go to a message driven bean?

In your CXF servlet you will have access to the Request object and by inference the HTTP port number it runs on.

If your problem is to get data from the MDB to the CXF servlet and vice versa I suggest you look into the JNDI mechanism rather than relying on determining listening ports at runtime.

Cheers,

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55