0

I have an Apache tapestry application which is running under Jetty server. As such port number of the running HTTP server can be obtained during a request from the request object. But I need to find out the port number at which the server is running during program start up (somewhere in AppModule). Is there some way to get this information programmatically? I tried to access @Symbol(SymbolConstants.HOSTPORT) String hostPort in a service but this doesn't work. It simply gives 0. Apparently 0 means that I should be looking up the port number from request.

The reason I need it is because I need to write this information in some database which is accessible to other services such that they are aware of the port / ip address at which this application is running and can call it up.

Shailesh Kumar
  • 6,457
  • 8
  • 35
  • 60

1 Answers1

0

I'm pretty certain you cannot programmatically determine the servlet container's port from anything in the javax.servlet package, except for ServletRequest ie getLocalPort().

Tapestry does not provide any extra handles to your application container not already in the servlet spec.

Therefore you will need to wait for the first request to come in and store the port used (recommended), or duplicate your port configuration - once in your container's configuration (jetty) and once somewhere in your application (AppModule, web.xml or other configuration files).

The third option (which is highly NOT recommended) would be to lookup your container's configuration from within your tapestry application. Please don't do this.

pstanton
  • 35,033
  • 24
  • 126
  • 168
  • see this answer for tomcat .. not sure if you can do something similar for jetty? http://stackoverflow.com/questions/7481432/i-need-to-know-the-http-and-https-port-my-java-webapp-is-running-on-webapp-start – pstanton Nov 22 '12 at 11:12