Frage

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

War es hilfreich?

Lösung

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,

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top