com.networknt.utility.Util.getInetAddress()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(2.3k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中com.networknt.utility.Util.getInetAddress()方法的一些代码示例,展示了Util.getInetAddress()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.getInetAddress()方法的具体详情如下:
包路径:com.networknt.utility.Util
类名称:Util
方法名:getInetAddress

Util.getInetAddress介绍

[英]Get InetAddress
[中]获取地址

代码示例

代码示例来源:origin: networknt/light-4j

public Map<String, Object> getHost(HttpServerExchange exchange) {
  Map<String, Object> hostMap = new LinkedHashMap<>();
  String ip = "unknown";
  String hostname = "unknown";
  InetAddress inetAddress = Util.getInetAddress();
  ip = inetAddress.getHostAddress();
  hostname = inetAddress.getHostName();
  hostMap.put("ip", ip);
  hostMap.put("hostname", hostname);
  hostMap.put("dns", exchange.getSourceAddress().getHostName());
  return hostMap;
}

代码示例来源:origin: networknt/light-4j

public MetricsHandler() {
  commonTags.put("apiName", Server.config.getServiceId());
  commonTags.put("environment", Server.config.getEnvironment());
  InetAddress inetAddress = Util.getInetAddress();
  // On Docker for Mac, inetAddress will be null as there is a bug.
  commonTags.put("ipAddress", inetAddress == null ? "unknown" : inetAddress.getHostAddress());
  commonTags.put("hostname", inetAddress == null ? "unknown" : inetAddress.getHostName()); // will be container id if in docker.
      
  if(logger.isDebugEnabled()) {
    logger.debug(commonTags.toString());
  }
}

代码示例来源:origin: networknt/light-4j

logger.info("Registry IP from STATUS_HOST_IP is " + ipAddress);
if (ipAddress == null) {
  InetAddress inetAddress = Util.getInetAddress();
  ipAddress = inetAddress.getHostAddress();
  logger.info("Could not find IP from STATUS_HOST_IP, use the InetAddress " + ipAddress);

代码示例来源:origin: com.networknt/metrics

public MetricsHandler() {
  commonTags.put("apiName", Server.config.getServiceId());
  commonTags.put("environment", Server.config.getEnvironment());
  InetAddress inetAddress = Util.getInetAddress();
  // On Docker for Mac, inetAddress will be null as there is a bug.
  commonTags.put("ipAddress", inetAddress == null ? "unknown" : inetAddress.getHostAddress());
  commonTags.put("hostname", inetAddress == null ? "unknown" : inetAddress.getHostName()); // will be container id if in docker.
      
  if(logger.isDebugEnabled()) {
    logger.debug(commonTags.toString());
  }
}

相关文章