The question is: how do I retrieve the port number that play is listening on, no matter how it was defined (configuration, command line argument, or not at all).
Thi
I just found a way to get the port no matter how the port is specified. Use the reverse route to get an Call object, and the use the absoluteUrl() method to get the absolute url of your action, which contains port. Code snippet:
public class RouteController extends Controller {
public Promise getPortAction() {
Call call = com.mycom.routes.RouteController.getPortAction();
String absoluteUrl = call.absoluteURL(request());
//Here absoluteUrl would be like http://localhost:9002/...., 9002 would be the port.
...
} }