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

intgetValidZooKeeperPort()
Check from DEFAULT_ZK_PORT to (DEFAULT_ZK_PORT + TRY_PORT_COUNT) to see if there is valid port to launch embed zookeeper server.
int zkValidPort = INITAL_ZK_PORT;
int initialPort = DEFAULT_ZK_PORT;
if (System.currentTimeMillis() % 2 == 0) {
    zkValidPort += RANDOM.nextInt(100);
} else {
    zkValidPort -= RANDOM.nextInt(100);
for (int i = initialPort; i < (initialPort + TRY_PORT_COUNT); i++) {
...
URLgetWsdlLocation(String portPrefix)
get Wsdl Location
try {
    return new URL("http://localhost:9001/" + portPrefix + "PingService?wsdl");
} catch (MalformedURLException mue) {
    return null;
StringgetXmlReport(String fileName)
Ucitava dati izvestaj preko servleta.
String proxyHost = System.getProperty("proxyHost");
String proxyPort = System.getProperty("proxyHost");
System.setProperty("proxyHost", "");
System.setProperty("proxyPort", "");
System.setProperty("proxySet", "false");
StringBuffer buff = new StringBuffer();
try {
    URL url = new URL(reportServletUrl + "?reportFile=" + fileName);
...
booleanhasPermissionToBindPort(int port)
has Permission To Bind Port
ServerSocket s = null;
try {
    s = new ServerSocket(port);
    return true;
} catch (Exception e) {
    return false;
} finally {
    if (s != null)
...
booleanisActivePort(int port)
is Active Port
Socket socket = null;
boolean var3;
try {
    InetAddress localAddress = InetAddress.getLocalHost();
    socket = new Socket(localAddress, port);
    return true;
} catch (ConnectException var20) {
    var3 = false;
...
booleanisAlive(String hostname, int port, int retries)
is Alive
int cnt = 0;
System.out.println("Ping host:port " + hostname + ":" + port);
while (cnt <= retries) {
    System.out.println("ping [#" + cnt + "] ...");
    boolean reachable = isReachableByPing(hostname, port);
    if (reachable)
        return true;
    cnt++;
...
booleanisAvailablePort(int port)
is Available Port
ServerSocket ss = null;
try {
    ss = new ServerSocket(port);
    ss.bind(null);
    return true;
} catch (IOException e) {
    return false;
} finally {
...
booleanisBindable(int port)
is Bindable
try {
    ServerSocket ss = new ServerSocket(port);
    ss.close();
    ss = null;
    return true;
} catch (BindException be) {
    return false;
} catch (IOException e) {
...
booleanisBindedPort(String host, int port)
is Binded Port
boolean used = false;
Socket socket = new Socket();
try {
    InetSocketAddress ip = new InetSocketAddress(host, port);
    socket.connect(ip, 5 * 1000);
    used = true;
} catch (Exception ex) {
    ex.printStackTrace();
...
booleanisBound(int port)
Returns true if port is already bound by a process; otherwise returns false.
InetSocketAddress address = new InetSocketAddress(port);
return isBound(address);