Beispiel #1
1
  private String detectAgentUrl(
      HttpServer pServer, JolokiaServerConfig pConfig, String pContextPath) {
    serverAddress = pServer.getAddress();
    InetAddress realAddress;
    int port;
    if (serverAddress != null) {
      realAddress = serverAddress.getAddress();
      if (realAddress.isAnyLocalAddress()) {
        try {
          realAddress = NetworkUtil.getLocalAddress();
        } catch (IOException e) {
          try {
            realAddress = InetAddress.getLocalHost();
          } catch (UnknownHostException e1) {
            // Ok, ok. We take the original one
            realAddress = serverAddress.getAddress();
          }
        }
      }
      port = serverAddress.getPort();
    } else {
      realAddress = pConfig.getAddress();
      port = pConfig.getPort();
    }

    return String.format(
        "%s://%s:%d%s", pConfig.getProtocol(), realAddress.getHostAddress(), port, pContextPath);
  }
 /**
  * Description including agent URL
  *
  * @return agent url
  */
 @Override
 public String getDescription() {
   String hostDescr = host;
   try {
     if (hostDescr == null) {
       hostDescr = NetworkUtil.getLocalAddress().getHostName();
     }
   } catch (IOException e) {
     hostDescr = "localhost";
   }
   return "Jolokia Agent: http://" + hostDescr + ":" + getPort() + "/jolokia";
 }