Package org.jolokia.server.core.util
Class NetworkUtil
java.lang.Object
org.jolokia.server.core.util.NetworkUtil
Utility class for network related stuff
- Since:
- 05.02.14
- Author:
- roland
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringGet the local network info as a stringstatic InetAddressstatic StringgetAgentId(int objectId, String type) static InetAddressGet a local, IP4 Address, preferable a non-loopback address which is bound to an interface.static InetAddressGet a local address which supports multicast.static List<InetAddress>Get all local addresses on which a multicast can be sendstatic booleanCheck, whether multicast is supported at all by at least one interfacestatic booleanisMulticastSupported(InetAddress pAddr) Check whether the given address' interface supports multicaststatic booleanCheck whether the given interface supports multicast and is upstatic voidstatic StringreplaceExpression(String pValue) Replace expression ${host} and ${ip} with the localhost name or IP in the given string.static StringsanitizeLocalUrl(String pRequestURL) Examine the given URL and replace the host with a non-loopback host if possible.
-
Method Details
-
main
- Throws:
UnknownHostExceptionSocketException
-
getLocalAddress
Get a local, IP4 Address, preferable a non-loopback address which is bound to an interface.- Returns:
- Throws:
UnknownHostExceptionSocketException
-
getLocalAddressWithMulticast
public static InetAddress getLocalAddressWithMulticast() throws UnknownHostException, SocketExceptionGet 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:
UnknownHostExceptionSocketException
-
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
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
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
Get all local addresses on which a multicast can be send- Returns:
- list of all multi cast capable addresses
-
getAgentId
-
sanitizeLocalUrl
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
Get the local network info as a string- Returns:
- return a description of the current network setup of the local host.
- Throws:
UnknownHostExceptionSocketException
-
replaceExpression
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
-