List of utility methods to do HTTP Port Find
int | getFreePort() Get a free local port. ServerSocket ss; int freePort = 0; for (int i = 0; i < 10; i++) { freePort = (int) (10000 + Math.round(Math.random() * 10000)); freePort = freePort % 2 == 0 ? freePort : freePort + 1; try { ss = new ServerSocket(freePort); freePort = ss.getLocalPort(); ... |
int | getFreePort() Returns the free port on the local host. int port = -1; while (port <= 0) { Thread.sleep(100); ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(0); port = serverSocket.getLocalPort(); } finally { ... |
int | getFreePort(int port) get Free Port int limit = 65534; while (port < limit) { try { new ServerSocket(port).close(); return port; } catch (IOException e) { ++port; return -1; |
int | getFreePort(int pPort) Find a free port, starting from pport int port = 0; ServerSocket s = null; boolean found = false; while (!found) { try { s = new ServerSocket(pPort); if (s.isBound()) { port = s.getLocalPort(); ... |
int | getFreePortNoSych() Returns a free port ServerSocket socket = new ServerSocket(0); int port = socket.getLocalPort(); socket.close(); return port; |
int | getFreePortNumber(int defaultPortNumber) get Free Port Number int port = defaultPortNumber; ServerSocket socket = null; try { socket = new ServerSocket(0); port = socket.getLocalPort(); } catch (IOException e) { System.out.println("IOException occured while creating socket." + " Use a default port number " + port); } finally { ... |
int | getFreeServerPort(int port) Get a free server port that can be used. int resultPort = 0; ServerSocket s; try { s = new ServerSocket(port); resultPort = s.getLocalPort(); s.close(); } catch (IOException e) { resultPort = 0; ... |
String | getImportedXmlSchemaPath(String namespace, String portType, String operation) get Imported Xml Schema Path if (namespace == null || portType == null || operation == null) { throw new URISyntaxException(namespace + " " + portType + " " + operation, "The arguments can't be empty, please check"); StringBuilder builder = new StringBuilder(replaceAllLimited(new URI(namespace).getRawSchemeSpecificPart())); if (builder.length() > 0) { while (builder.charAt(0) == '/') { builder.deleteCharAt(0); ... |
int | getNextAvailable(int port) get Next Available int nextPort = port; while (!isAvailable(nextPort)) { nextPort++; return nextPort; |
int | getNextAvailablePort() get Next Available Port for (int index = 0; index < 5; index++) { try { ServerSocket socket = new ServerSocket(0); int unusedPort = socket.getLocalPort(); socket.close(); if (isValidPort(unusedPort)) { return unusedPort; } catch (IOException e) { throw new IllegalStateException("Can not find an open network port", e); throw new IllegalStateException("Can not find an open network port"); |