我遵循了这里的建议:
http://wiki.cloudbees.com/bin/view/Main/Finding+out+app+port+and+hostname
public String getIp() throws UnknownHostException {
String hostName = InetAddress.getLocalHost().getHostName();
String urlToRead = "http://instance-data/latest/meta-data/public-hostname";
String iVeALsoTriedThis = "http://instance-data/latest/meta-data/" + hostName;
URL url;
HttpURLConnection conn;
BufferedReader rd;
String line;
String result = "";
try {
url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
result += line;
}
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
return hostName + " ------ " + result;
}
当在主页上使用一个简单的标签来获取详细信息时:
IP: <s:property value="ip"/>
我得到的结果是这样的:
IP:ip-10-34-128-137.eu-west-1.compute.internal ------ ec2-46-51-131-172.eu-west-1.compute.amazonaws.com
这不是我所期望的——即使我尝试访问 10.34.128.137 我也只是收到超时错误。ping 46.51.131.172 也会超时,尝试访问 ec2-46-51-131-172.eu-west-1.compute.amazonaws.com 也会导致超时。
我知道你们中的大多数人会认为这是微不足道的,但是 cloudbees 没有简单的方法可以从控制台识别您的应用程序的 IP,然后按照他们的(通常是明确的建议)我完全迷失了。
请问,我应该在这里做什么?
非常感谢,
肯