I fixed the problem by using my own portprocessor and catching io exception. The izpack PortProcessor even with resultFormat="processed" does not work for me.
<field type="rule" align="right" variable="RMI.port">
<spec txt=" RMI Port:" layout="N:5:5" set="0:1098" resultFormat="processed"/>
<processor class="com.ca.install.PortProcessor"/>
</field>
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.UnknownHostException;
import com.izforge.izpack.panels.ProcessingClient;
import com.izforge.izpack.panels.Processor;
public class PortProcessor implements Processor {
public String process(ProcessingClient client) {
String host = "localhost";
String hostOrig = null;
int port = 0;
String portOrig = null;
boolean found = false;
InetAddress addr = null;
ServerSocket sock = null;
int fieldCount = client.getNumFields();
int portIndex = 0;
try {
if (fieldCount > 1) {
hostOrig = client.getFieldContents(0);
host = hostOrig;
portIndex++;
}
portOrig = client.getFieldContents(portIndex);
port = Integer.parseInt(portOrig);
} catch (Exception e) {
return "-1";
}
System.out.println("Using: "host":"+port);
while (!found && port < 65535) {
try {
addr = InetAddress.getByName(host);
sock = new ServerSocket(port, 0, addr);
if (sock.getLocalPort() >= 0) {
found = true;
System.out.println("Found Local Port: "+port);
} else {
port++;
System.out.println("Incremented Port: "+port);
}
} catch (UnknownHostException e) {
System.out.println("Unknown Host: "+host);
return createReturn(fieldCount, hostOrig, portOrig);
} catch (IOException e) {
System.out.println("IO Exception: "+port);
port++;
} finally {
try {
if (sock != null)
sock.close();
} catch (IOException e) {
}
}
}
return createReturn(fieldCount, host, Integer.toString(port));
}
private String createReturn(int fieldCount, String host, String port) {
String val = port;
if (fieldCount > 1) {
val = host+"*"+port;
}
System.out.println("Generated Return: "+val);
return val;
}
}
Added a testCase testing/showing the correctness of the current behaviour.
If the specified port is still available for the specified network address (defaulting to localhost) the port is accepted. If the specified port is not available the processor seeks an available port and returns that port.
In your case apparently a process is bound to the specified port for 'all available network interfaces'. In this case a socket can still be bound to localhost ('unbinding' localhost for the already running process).
If you need to validate for binding to 'all available network interfaces', you should include the host '0.0.0.0' (or '::' for IPv6) as a field for the ProcessingClient of the PortProcessor.