views:

1959

answers:

1

I'm currently working on a WebSphere 6.1 Web Project.

In my java code, how can i get the current running application port?

+2  A: 

The servlet API gives you the local port in HttpServletRequest.

protected void doGet(HttpServletRequest request,
  HttpServletResponse response) throws ServletException, IOException {
 PrintWriter writer = response.getWriter();
 writer.write("" + request.getLocalPort());
 writer.close();
}

The ports are defined in the node's serverindex.xml (e.g. [WAS]/profiles/AppSrv01/config/cells/localhostNode01Cell/nodes/localhostNode01/serverindex.xml).

<specialEndpoints xmi:id="NamedEndPoint_1214751102556" endPointName="WC_defaulthost">
  <endPoint xmi:id="EndPoint_1214751102556" host="*" port="9080"/>

I'm not sure if the WAS JMX support exposes this information - you'd have to check the doc.

McDowell