org.apache.axis2.util.Utils.getIpAddress()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(115)

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

Utils.getIpAddress介绍

[英]Returns the ip address to be used for the replyto epr CAUTION: This will go through all the available network interfaces and will try to return an ip address. First this will try to get the first IP which is not loopback address (127.0.0.1). If none is found then this will return this will return 127.0.0.1. This will notconsider IPv6 addresses.

TODO: - Improve this logic to genaralize it a bit more - Obtain the ip to be used here from the Call API
[中]返回用于replyto epr的ip地址警告:这将通过所有可用的网络接口,并尝试返回ip地址。首先,这将尝试获取不是环回地址(127.0.0.1)的第一个IP。如果没有找到,则返回127.0.0.1。这将不考虑IPv6地址。
TODO:-改进此逻辑,使其更通用一点-从调用API获取此处要使用的ip

代码示例

代码示例来源:origin: org.wso2.carbon.analytics/org.wso2.carbon.analytics.spark.core

private String getLocalHostname() throws SocketException {
//        this is removed because, NetworkUtils.getLocalHostname() would return the carbon.xml
//        hostname if provided. but in the spark environment, it would need a unique hostname DAS-171
//        return NetworkUtils.getLocalHostname();
    String localIP = System.getenv(AnalyticsConstants.SPARK_LOCAL_IP_PROP);
    if (localIP != null) {
      if (log.isDebugEnabled()) {
        log.debug("Spark host is set from the SPARK_LOCAL_IP property : " + localIP);
      }
      return localIP;
    } else {
      if (log.isDebugEnabled()) {
        log.debug("Spark host is set NOT set, hence using the node network interface");
      }
      return org.apache.axis2.util.Utils.getIpAddress();
    }
  }
}

代码示例来源:origin: org.apache.axis2/axis2-clustering

public static String getLocalHost(Parameter tcpListenHost){
  String host = null;
  if (tcpListenHost != null) {
    host = ((String) tcpListenHost.getValue()).trim();
  } else {
    try {
      host = Utils.getIpAddress();
    } catch (SocketException e) {
      String msg = "Could not get local IP address";
      log.error(msg, e);
    }
  }
  if (System.getProperty(ClusteringConstants.LOCAL_IP_ADDRESS) != null) {
    host = System.getProperty(ClusteringConstants.LOCAL_IP_ADDRESS);
  }
  return host;
}

代码示例来源:origin: apache/axis2-java

public static String getLocalHost(Parameter tcpListenHost){
  String host = null;
  if (tcpListenHost != null) {
    host = ((String) tcpListenHost.getValue()).trim();
  } else {
    try {
      host = Utils.getIpAddress();
    } catch (SocketException e) {
      String msg = "Could not get local IP address";
      log.error(msg, e);
    }
  }
  if (System.getProperty(ClusteringConstants.LOCAL_IP_ADDRESS) != null) {
    host = System.getProperty(ClusteringConstants.LOCAL_IP_ADDRESS);
  }
  return host;
}

代码示例来源:origin: org.apache.axis2/axis2-kernel

private String[] calculateEPRs() {
  try {
    String requestIP = org.apache.axis2.util.Utils.getIpAddress(getAxisConfiguration());
    return calculateEPRs(requestIP);
  } catch (SocketException e) {
    log.error("Cannot get local IP address", e);
  }
  return new String[0];
}

代码示例来源:origin: apache/axis2-java

private String[] calculateEPRs() {
  try {
    String requestIP = org.apache.axis2.util.Utils.getIpAddress(getAxisConfiguration());
    return calculateEPRs(requestIP);
  } catch (SocketException e) {
    log.error("Cannot get local IP address", e);
  }
  return new String[0];
}

代码示例来源:origin: org.apache.axis2/axis2-kernel

/**
 * First check whether the hostname parameter is there in AxisConfiguration (axis2.xml) ,
 * if it is there then this will retun that as the host name , o.w will return the IP address.
 */
public static String getIpAddress(AxisConfiguration axisConfiguration) throws SocketException {
  if(axisConfiguration!=null){
    Parameter param = axisConfiguration.getParameter(TransportListener.HOST_ADDRESS);
    if (param != null) {
      String  hostAddress = ((String) param.getValue()).trim();
      if(hostAddress!=null){
        return hostAddress;
      }
    }
  }
  return getIpAddress();
}

代码示例来源:origin: apache/axis2-java

@Override
protected void doInit() throws AxisFault {
  DatagramDispatcherCallback callback = new DatagramDispatcherCallback() {
    public void receive(DatagramEndpoint endpoint,
              byte[] data,
              int length,
              DatagramOutTransportInfo outInfo) {
      workerPool.execute(new ProcessPacketTask(endpoint, data, length, outInfo));
    }
  };
  try {
    dispatcher = createDispatcher(callback);
  } catch (IOException ex) {
    throw new AxisFault("Unable to create selector", ex);
  }
  
  try {
    defaultIp = org.apache.axis2.util.Utils.getIpAddress(cfgCtx.getAxisConfiguration());
  } catch (SocketException ex) {
    throw new AxisFault("Unable to determine the host's IP address", ex);
  }
}

代码示例来源:origin: apache/axis2-java

/**
 * First check whether the hostname parameter is there in AxisConfiguration (axis2.xml) ,
 * if it is there then this will retun that as the host name , o.w will return the IP address.
 */
public static String getIpAddress(AxisConfiguration axisConfiguration) throws SocketException {
  if(axisConfiguration!=null){
    Parameter param = axisConfiguration.getParameter(TransportListener.HOST_ADDRESS);
    if (param != null) {
      String  hostAddress = ((String) param.getValue()).trim();
      if(hostAddress!=null){
        return hostAddress;
      }
    }
  }
  return getIpAddress();
}

代码示例来源:origin: org.apache.axis2/axis2-transport-base

@Override
protected void doInit() throws AxisFault {
  DatagramDispatcherCallback callback = new DatagramDispatcherCallback() {
    public void receive(DatagramEndpoint endpoint,
              byte[] data,
              int length,
              DatagramOutTransportInfo outInfo) {
      workerPool.execute(new ProcessPacketTask(endpoint, data, length, outInfo));
    }
  };
  try {
    dispatcher = createDispatcher(callback);
  } catch (IOException ex) {
    throw new AxisFault("Unable to create selector", ex);
  }
  
  try {
    defaultIp = org.apache.axis2.util.Utils.getIpAddress(cfgCtx.getAxisConfiguration());
  } catch (SocketException ex) {
    throw new AxisFault("Unable to determine the host's IP address", ex);
  }
}

代码示例来源:origin: org.apache.axis2/axis2-transport-udp

@Override
  public EndpointReference[] getEndpointReferences(AxisService service, String ip) throws AxisFault {
    if (ip == null) {
      try {
        ip = Utils.getIpAddress(getListener().getConfigurationContext().getAxisConfiguration());
      } catch (SocketException ex) {
        throw new AxisFault("Unable to determine the host's IP address", ex);
      }
    }
    StringBuilder epr = new StringBuilder("udp://");
    epr.append(ip);
    epr.append(':');
    epr.append(getPort());
    // If messages are predispatched to a service, then WS-Addressing will be used and we
    // need to include the service path in the EPR.
    if (getService() == null) {
      epr.append('/');
      epr.append(getConfigurationContext().getServiceContextPath());
      epr.append('/');
      epr.append(service.getName());
    }
    epr.append("?contentType=");
    epr.append(getContentType());
    return new EndpointReference[] { new EndpointReference(epr.toString()) };
  }
}

代码示例来源:origin: org.apache.axis2.transport/axis2-transport-udp

@Override
  public EndpointReference[] getEndpointReferences(AxisService service, String ip) throws AxisFault {
    if (ip == null) {
      try {
        ip = Utils.getIpAddress(getListener().getConfigurationContext().getAxisConfiguration());
      } catch (SocketException ex) {
        throw new AxisFault("Unable to determine the host's IP address", ex);
      }
    }
    StringBuilder epr = new StringBuilder("udp://");
    epr.append(ip);
    epr.append(':');
    epr.append(getPort());
    // If messages are predispatched to a service, then WS-Addressing will be used and we
    // need to include the service path in the EPR.
    if (getService() == null) {
      epr.append('/');
      epr.append(getConfigurationContext().getServiceContextPath());
      epr.append('/');
      epr.append(service.getName());
    }
    epr.append("?contentType=");
    epr.append(getContentType());
    return new EndpointReference[] { new EndpointReference(epr.toString()) };
  }
}

代码示例来源:origin: apache/axis2-java

@Override
  public EndpointReference[] getEndpointReferences(AxisService service, String ip) throws AxisFault {
    if (ip == null) {
      try {
        ip = Utils.getIpAddress(getListener().getConfigurationContext().getAxisConfiguration());
      } catch (SocketException ex) {
        throw new AxisFault("Unable to determine the host's IP address", ex);
      }
    }
    StringBuilder epr = new StringBuilder("udp://");
    epr.append(ip);
    epr.append(':');
    epr.append(getPort());
    // If messages are predispatched to a service, then WS-Addressing will be used and we
    // need to include the service path in the EPR.
    if (getService() == null) {
      epr.append('/');
      epr.append(getConfigurationContext().getServiceContextPath());
      epr.append('/');
      epr.append(service.getName());
    }
    epr.append("?contentType=");
    epr.append(getContentType());
    return new EndpointReference[] { new EndpointReference(epr.toString()) };
  }
}

代码示例来源:origin: org.apache.axis2/axis2-transport-http

if (ip == null){
  try {
    ip = Utils.getIpAddress(configurationContext.getAxisConfiguration());
  } catch (SocketException ex) {
    AxisFault.makeFault(ex);

代码示例来源:origin: apache/axis2-java

if (ip == null){
  try {
    ip = Utils.getIpAddress(configurationContext.getAxisConfiguration());
  } catch (SocketException ex) {
    AxisFault.makeFault(ex);

代码示例来源:origin: org.apache.airavata/gfac-axis2-interface

Map<String, String> map = new HashMap<String, String>((Map) properties);
Registry registry = new JCRRegistry(new URI(map.get(ORG_APACHE_JACKRABBIT_REPOSITORY_URI)),map.get(JCR_CLASS),map.get(JCR_USER),map.get(JCR_PASS), map);
String localAddress = Utils.getIpAddress(context.getAxisConfiguration());
TransportInDescription transportInDescription = context.getAxisConfiguration().getTransportsIn()
    .get("http");

代码示例来源:origin: org.apache.axis2/axis2-transport-tcp

public EndpointReference[] getEndpointReferences(AxisService service,
                         String ip) throws AxisFault {
  if (host == null && ip == null) {
    try {
      ip = Utils.getIpAddress(getListener().getConfigurationContext().
          getAxisConfiguration());
    } catch (SocketException ex) {
      throw new AxisFault("Unable to determine the host's IP address", ex);
    }
  }
  String url = "tcp://" + (host != null ? host : ip) + ":" + port;
  String context = getListener().getConfigurationContext().getServiceContextPath();
  url +=  (context.startsWith("/") ? "" : "/") + context +
      (context.endsWith("/") ? "" : "/") +
      (getService() == null ? service.getName() : getServiceName());
  if (!contentType.equals(TCPConstants.TCP_DEFAULT_CONTENT_TYPE)) {
    url += "?contentType=" + contentType;
  }
  return new EndpointReference[] { new EndpointReference(url) };
}

代码示例来源:origin: apache/axis2-java

public EndpointReference[] getEndpointReferences(AxisService service,
                         String ip) throws AxisFault {
  if (host == null && ip == null) {
    try {
      ip = Utils.getIpAddress(getListener().getConfigurationContext().
          getAxisConfiguration());
    } catch (SocketException ex) {
      throw new AxisFault("Unable to determine the host's IP address", ex);
    }
  }
  String url = "tcp://" + (host != null ? host : ip) + ":" + port;
  String context = getListener().getConfigurationContext().getServiceContextPath();
  url +=  (context.startsWith("/") ? "" : "/") + context +
      (context.endsWith("/") ? "" : "/") +
      (getService() == null ? service.getName() : getServiceName());
  if (!contentType.equals(TCPConstants.TCP_DEFAULT_CONTENT_TYPE)) {
    url += "?contentType=" + contentType;
  }
  return new EndpointReference[] { new EndpointReference(url) };
}

代码示例来源:origin: org.apache.axis2/axis2-kernel

ip = hostIP;
} else {
  ip = Utils.getIpAddress(axisConfiguration);

代码示例来源:origin: apache/axis2-java

ip = hostIP;
} else {
  ip = Utils.getIpAddress(axisConfiguration);

代码示例来源:origin: org.apache.axis2/axis2-clustering

String host;
try {
  host = Utils.getIpAddress();
} catch (SocketException e) {
  String msg = "Could not get local IP address";

相关文章