• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thoughts on handling RemoteException

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am in the process of trying all kinds of "stupid user" input on the setup dialog part of my application. I have a custom Dialog class to display error messages to the user if validation fails on the port, server address and database location. The server and the local client work fine (the main GUI will not start until valid input is received). I ran into a situation with the Network client that had me perplexed for a bit. If I input http://www.yahoo.com as the Ip Address, it passed validation, as it should, it's a valid IP addres, just not for my application. I then tried to input a good address and apparently the application had gotten too far and I got null pointer exception from Event Dispatcher (Swing). My solution, documented in choices.txt was to have my dialog show that a problem had occurred while connecting to the remote system and that the system was going to shut down. I also instructed them to start back up again with a different IP address. I know others have had issues validating the IP address, and it is my feeling that System.exit(0) is generally bad. I found no other good way to recover from this situation and documented that it is warranted for this particular situation. Any thoughts?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anne,

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.

Kind regards,
Roel
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anne, in my app, i store the server's IP address in the properties file when starting the RMI server. Then in my remote interface, I have a isValidConnection() method checking if the client entered IP and port match with the server IP and port stored in the properties file. If match, open the JFrame. If not match pop up error dialog and the setup window remain open. It is like web form validation. The problem may be once you get an exception, you may exit that method hence closing the setup window.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, Anne!

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.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi (great and wise) Roberto,

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?

Kind regards,
Roel
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, my good buddy Roel!

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
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



Hello Anne,

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
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic