Class NetworkUtil

java.lang.Object
org.jolokia.server.core.util.NetworkUtil

public final class NetworkUtil extends Object
Utility class for network related stuff
Since:
05.02.14
Author:
roland
  • Method Details

    • main

      public static void main(String[] args) throws UnknownHostException, SocketException
      Throws:
      UnknownHostException
      SocketException
    • getLocalAddress

      public static InetAddress getLocalAddress() throws UnknownHostException, SocketException
      Get a local, IP4 Address, preferable a non-loopback address which is bound to an interface.
      Returns:
      Throws:
      UnknownHostException
      SocketException
    • getLocalAddressWithMulticast

      public static InetAddress getLocalAddressWithMulticast() throws UnknownHostException, SocketException
      Get a local address which supports multicast. A loopback adress is returned, but only if not another is available
      Returns:
      a multicast enabled address of null if none could be found
      Throws:
      UnknownHostException
      SocketException
    • findLocalAddressViaNetworkInterface

      public static InetAddress findLocalAddressViaNetworkInterface()
    • isMulticastSupported

      public static boolean isMulticastSupported()
      Check, whether multicast is supported at all by at least one interface
      Returns:
      true if at least one network interface supports multicast
    • isMulticastSupported

      public static boolean isMulticastSupported(NetworkInterface pNif)
      Check whether the given interface supports multicast and is up
      Parameters:
      pNif - check whether the given interface supports multicast
      Returns:
      true if multicast is supported and the interface is up
    • isMulticastSupported

      public static boolean isMulticastSupported(InetAddress pAddr) throws SocketException
      Check whether the given address' interface supports multicast
      Parameters:
      pAddr - address to check
      Returns:
      true if the underlying networkinterface is up and supports multicast
      Throws:
      SocketException
    • getMulticastAddresses

      public static List<InetAddress> getMulticastAddresses()
      Get all local addresses on which a multicast can be send
      Returns:
      list of all multi cast capable addresses
    • getAgentId

      public static String getAgentId(int objectId, String type)
    • sanitizeLocalUrl

      public static String sanitizeLocalUrl(String pRequestURL)
      Examine the given URL and replace the host with a non-loopback host if possible. It is checked, whether the port is open as well.

      A replaced host uses the IP address instead of a (possibly non resolvable) name.

      Parameters:
      pRequestURL - url to examine and to update
      Returns:
      the 'sane' URL (or the original one if no san
    • dumpLocalNetworkInfo

      public static String dumpLocalNetworkInfo() throws UnknownHostException, SocketException
      Get the local network info as a string
      Returns:
      return a description of the current network setup of the local host.
      Throws:
      UnknownHostException
      SocketException
    • replaceExpression

      public static String replaceExpression(String pValue)
      Replace expression ${host} and ${ip} with the localhost name or IP in the given string. In addition the notation ${env:ENV_VAR} and ${prop:sysprop} can be used to refer to environment and system properties respectively.
      Parameters:
      pValue - value to examine
      Returns:
      the value with the variables replaced.
      Throws:
      IllegalArgumentException - when the expression is unknown or an error occurs when extracting the host name