IzPack

PortProcessor does not catch invalid error

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Not A Bug
  • Affects Version/s: 4.0.1
  • Fix Version/s: 4.1.0
  • Component/s: Panels
  • Labels:
    None
  • Environment:
    Windows XP
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

I am trying to use one of the APIs from izPack in a UserInputPanel. In the spec file I have the following:

<field type="rule" align="right" variable="rmiport.value">

<spec txt=" RMIPort:" layout="N:5:5" set="0:1098"/>

<validator class="com.izforge.izpack.util.PortProcessor">

</validator>

</field>

PortProcessor is supposed to return a string of a valid port value. When a port that is in use is supplied the PortProcessor accepts it and returns it. Looking at the source code it seems that the code should be catching IOException instead of or in addition to BindException. The IOException will occur when the port is already bound and it is currently getting caught by Exception which simply returns the text field values via getReturnValue(...) because both host and port are set to null.

Activity

Hide
Hans Aikema added a comment -

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.

Show
Hans Aikema added a comment - 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.
Hide
Kami Shishegar added a comment -

Thanks for your response. I maybe using this incorrectly. I noticed that this was not derived from Validator class but from Processor instead. so I changed my code to:

Show
Kami Shishegar added a comment - Thanks for your response. I maybe using this incorrectly. I noticed that this was not derived from Validator class but from Processor instead. so I changed my code to:
Hide
Kami Shishegar added a comment -

cont...
<field type="rule" align="right" variable="rmiport.value">
<spec txt=" RMIPort:" layout="N:5:5" set="0:1098"/>

<processor class="com.izforge.izpack.panels.PortProcessor">
</processor>

however it does not see to have made a difference. I think the code is not getting invoked at all. no matter what value I put in for the variable it accepts it. I even changed the PortProcessor name to a non-existing name and it still did the same behavior!

What am I missing?

Show
Kami Shishegar added a comment - cont... <field type="rule" align="right" variable="rmiport.value"> <spec txt=" RMIPort:" layout="N:5:5" set="0:1098"/> <processor class="com.izforge.izpack.panels.PortProcessor"> </processor> however it does not see to have made a difference. I think the code is not getting invoked at all. no matter what value I put in for the variable it accepts it. I even changed the PortProcessor name to a non-existing name and it still did the same behavior! What am I missing?
Hide
Rob Seegel added a comment -

In order for the processor to evaluate the field, you must add the resultFormat="processed" to the spec element like so:

<field type="rule" align="right" variable="rmiport.value"&rt;
<spec txt=" RMIPort:" resultFormat="processed" layout="N:5:5" set="0:1098"/<
<processor class="com.izforge.izpack.panels.PortProcessor"&rt;
&rt;

Show
Rob Seegel added a comment - In order for the processor to evaluate the field, you must add the resultFormat="processed" to the spec element like so: <field type="rule" align="right" variable="rmiport.value"&rt; <spec txt=" RMIPort:" resultFormat="processed" layout="N:5:5" set="0:1098"/< <processor class="com.izforge.izpack.panels.PortProcessor"&rt; &rt;
Hide
Rob Seegel added a comment -

or this:

<field type="rule" align="right" variable="rmiport.value">
<spec txt=" RMIPort:" resultFormat="processed" layout="N:5:5" set="0:1098"/>
<processor class="com.izforge.izpack.panels.PortProcessor"/>
</field>

Show
Rob Seegel added a comment - or this: <field type="rule" align="right" variable="rmiport.value"> <spec txt=" RMIPort:" resultFormat="processed" layout="N:5:5" set="0:1098"/> <processor class="com.izforge.izpack.panels.PortProcessor"/> </field>
Hide
Julien Ponge added a comment -

Any news on this one?

Show
Julien Ponge added a comment - Any news on this one?
Hide
Kami Shishegar added a comment -

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;
}

}

Show
Kami Shishegar added a comment - 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; } }
Hide
Julien Ponge added a comment -

The issue is rescheduled to 4.1.0 as it could not make it for the 4.0.1 cutoff.

Show
Julien Ponge added a comment - The issue is rescheduled to 4.1.0 as it could not make it for the 4.0.1 cutoff.
Hide
Julien Ponge added a comment -

This issue has been originally scheduled for inclusion in version 4.1.0, to be released on october 2nd 2008.

If you believe that it cannot be resolved on time, then could you please move it to 4.2.0? Otherwise, I would appreciate if you could give me a time frame for scheduling purposes

Thanks a lot!

Show
Julien Ponge added a comment - This issue has been originally scheduled for inclusion in version 4.1.0, to be released on october 2nd 2008. If you believe that it cannot be resolved on time, then could you please move it to 4.2.0? Otherwise, I would appreciate if you could give me a time frame for scheduling purposes Thanks a lot!

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
Not Specified
Original Estimate - Not Specified
Remaining:
Not Specified
Remaining Estimate - Not Specified
Logged:
2h
Time Spent - 2 hours