I validated the configuration settings: port number and ip address or hostname (more info on this one, can be found here).
If settings are valid, the connect button is enabled and when user clicks this button, I try to connect to the server and get my service. If that fails, I show an explaining message to the user and then exit the application with an error code. This behavior is also described in my user manual (but not in my choices.txt).
You could also keep showing the dialog until user hits cancel or connecting to server succeeds.
Just to give my insight, when the application starts in client mode, I display a small dialog that asks for the server's IP address and port number. In the IP address field, the user can only enter numbers and dots. Before anything, I verify if the given IP address is a valid one (and for that I use regular expression) and also if the given port number is valid. If so, then these values are stored in the local suncertify.properties file and the application starts normally; otherwise, I display an error message with a JOptionPane, saying that either the IP address or the port number is not valid.
I think Anne is pointing to a valid address (hostname or ip doesn't matter) and a valid port number, but at the combination of serverAddress + port no server is running. And how that situation should be handled.
So in your program I enter a valid ip address (10.1.10.1 for example) and a valid port number (1099), but the server is running on 10.1.10.2:1099 and your application can't start normally because there is no server. Or am I missing something?
Right... now I took the time to read carefully her post, it's just that things at work are currently awful, and I couldn't read it the way I should
Ok, if I understood correctly, the question is, given a valid IP address which does not have the server running, how the RemoteException should be handled, right? In my case, when I catch the RemoteException after trying to connect without success, I simply display a JOptionPane to the user, saying that the server may not be running in the given machine. But the application does not exit; it simply displays the message and waits for the user to provide other data.
Anne Crace wrote:Hi all. Quick update. I think K Tsang is right about what is actually occurring here. I have already exited the method. The problem only happens on subsequent clicks of the button. I am trying to take Roberto's approach of only accepting numeric IP addresses as I think it will eliminate most chances for bad input, and simplify things. I already have a PositiveIntTextField class, so I added an overloaded constructor and another Document model that takes numbers and dots. I have been having issues on getting it to accept the period or dot. char period = '.'; doesn't seem to work. The core of the problem is doing like K Tsang said and validating based on the value of what is in the properties file, even though right now it is the same one. I will test it at home on two computers to be sure it works as I don't quite trust localhost testing. It has worked in the past on two computers so it will work again, I'm sure.
For remote connection, I recall that RemoteException would only occur if the connection is attempted and failed. This means as long as you have not createRegistry for RMI say the RemoteException would not happen. As for other exceptions like FileNotFoundException ... don't put the logic in the your core method. Use a separate method to do say the database file validation so that if you say enter an incorrect file (like wrong magic cookie value) you can use a error JDialog prompting the error from that separate method rather than having the core method going into catch clause making you exiting your app or window.
Now for the text field validation, you may want to consider a DocumentListener for each field. Eg the port field, you can allow only up to 5 digits and above 1024. Now you use the DocumentListener to check such things when user input each key.
Also I suggest Roel's approach too by disabling the connect or ok button until all inputs are valid. My client setup class is huge.
IP regex thread here