Question

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

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

Was it helpful?

Solution

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.

OTHER TIPS

If you use RAD you can run administrative console from IDE and then discover all the ports used by WAS

http://pic.dhe.ibm.com/infocenter/radhelp/v9/index.jsp?topic=%2Fcom.ibm.sca.tools.doc%2Fsamples%2Ftopics%2Fwas_ports.html enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top