aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Validation of server host string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Validation of server host string" Watch "Validation of server host string" New topic
Author

Validation of server host string

Jo�o Batista
Ranch Hand

Joined: May 25, 2008
Posts: 40
I was reviewing my code and noticed that I didn't include much validation on the server host string in my configuration dialog.

I decided the user was free to use anything (to allow host name instead of using IP).

But even if I just allow IP address, any valid IP is considered, thus when I attempt to connect to www.google.com, for instance, the application hangs in my lookup call.

How can I get around this?

Thanks in advance.
k kris
Greenhorn

Joined: Nov 09, 2006
Posts: 6
Hi Batista -

Are you using sockets or rmi?
On RMI I can comment:

The application doesn't hang. You get a . But it takes some time (around 1 min maybe which is adjustable.)

Usually you do something like this to get the remote object:


But when you try with google:

it appears to be hanged... but you get a after a while.

java.rmi.ConnectException: Connection refused to host: www.google.com; nested exception is:
java.net.ConnectException: Connection timed out: connect


Even with proper RMI Server there maybe a time lag if it's a remote machine and network traffic is high.

So I think you should change the mouse cursor to Hour-Glass informing the user that we are waiting for the server to respond and change it back when we get a response or exception.
k kris
Greenhorn

Joined: Nov 09, 2006
Posts: 6
Oops. Sorry there. I thought [CODE] works like <code> in HTML
I didn't know it was <p><hr><code>...</hr></code></p>
Soroj Margun
Ranch Hand

Joined: Jun 15, 2008
Posts: 44
Hi all,

For server host, I suggest you should validate it by using java.net.InetAddress class. This class can check both IP address and host name.

Hope this help.


SCJP 1.2; SCWCD 1.2,1.4; SCBCD 1.3; SCJD 5.0
Jo�o Batista
Ranch Hand

Joined: May 25, 2008
Posts: 40
Many thanks for the replies!
This forum rocks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validation of server host string