Java Utililty Methods HTTP Port Find

List of utility methods to do HTTP Port Find

Description

The list of methods to do HTTP Port Find are organized into topic(s).

Method

intgetNextAvailablePort(final int min, final int max, final Collection excepted)
get Next Available Port
int port = -1;
ServerSocket s = null;
for (int i = min; i <= max; i++) {
    try {
        s = create(new int[] { i });
        port = s.getLocalPort();
        if (excepted == null || !excepted.contains(port)) {
            break;
...
intgetNextAvailablePort(int port)
get Next Available Port
int offset = detectPortOffset(port);
if (offset < 0) {
    return port;
return port + offset;
StringgetNodeName(final String managementServerHostName, final int managementPort)
get Node Name
final String nodeName = getNodeName();
if (nodeName == null) {
    throw new IllegalStateException("jboss.node.name could not be determined");
return nodeName;
intgetNonPrivilegedPort()
assigns a port from the range of test ports
return getNextNonPrivilegedPort(); 
intgetOpenPort()
Get a random open port
ServerSocket socket = null;
try {
    socket = new ServerSocket(0);
    return socket.getLocalPort();
} finally {
    if (socket != null) {
        socket.close();
intgetPort(final int suggestedPort)
Return an open port on current machine.
ServerSocket openSocket;
try {
    openSocket = new ServerSocket(suggestedPort);
} catch (BindException ex) {
    openSocket = new ServerSocket(0);
final int port = openSocket.getLocalPort();
openSocket.close();
...
intgetPort(int port)
This method checks whether supplied port is free.
ServerSocket socket = null;
try {
    socket = new ServerSocket(port);
    return socket.getLocalPort();
} finally {
    if (socket != null) {
        try {
            socket.close();
...
intgetPort(Proxy proxy)
get Port
InetSocketAddress address = (InetSocketAddress) proxy.address();
return address.getPort();
intgetPort(String endpoint)
get port fragment from an endpoint
int port = 0;
try {
    URI uri = new URI(endpoint);
    port = uri.getPort();
} catch (Exception e) {
    port = 0;
return port;
...
intgetPort(String hostAndPort)
get Port
return Integer.parseInt(hostAndPort.split(":")[1]);