Check url existence without opening browser, in java
<p>I want to check the existence of a url and i tried with the following code in java,</p>

<pre><code>public boolean exists(String URLName) {
    try {
         if (!URLName.toUpperCase().contains("HTTP")) 
             URLName="http://"+URLName;
             URL url = new URL(URLName);
             System.setProperty("java.net.useSystemProxies", "true");
             HttpURLConnection urlConn = (HttpURLConnection)  url.openConnection();
                 urlConn.setConnectTimeout(9000);
         urlConn.setReadTimeout(9000);            
          urlConn.connect();                    
                         if(HttpURLConnection.HTTP_OK == urlConn.getResponseCode())
             return true;
else
             return false;
  }
 catch (SocketTimeoutException e){
        return false;
   }

 catch (Exception e) {
       e.printStackTrace();
       return false;
   }
}
</code></pre>

<p>The above code is working fine in windows but when the code is run through server (linux) i am getting the following error message,</p>

<pre><code>GConf Error: Failed to contact configuration server; some possible
causes are that you need to enable TCP/IP networking for ORBit, or
you have stale NFS locks due to a system crash. See
http://projects.gnome.org/gconf/ for information. (Details - 1:
Not running within active session)
GConf Error: Failed to contact configuration server; some possible
causes are that you need to enable TCP/IP networking for ORBit, or
you have stale NFS locks due to a system crash. See
http://projects.gnome.org/gconf/ for information. (Details - 1:
Not running within active session)
java.net.UnknownHostException: www.ep.gov
at
java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:177)
at
java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:366)
at java.net.Socket.connect(Socket.java:525)
at sun.net.NetworkClient.doConnect(NetworkClient.java :158)
at
sun.net.http://www.http.HttpClient.openServe...lient.java:394)
at
sun.net.http://www.http.HttpClient.openServe...lient.java:529)
at sun.net.www.http.HttpClient.&lt;init&gt;(HttpClient.java :233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at
sun.net.http://www.protocol.http.HttpURLConn...ction.java:860)
at
sun.net.http://www.protocol.http.HttpURLConn...ction.java:801)
at
sun.net.http://www.protocol.http.HttpURLConn...ction.java:726)
</code></pre>

<p>I got the below message from server admin</p>

<pre><code>It is working, while it was run in X session (GUI Mode).
But it is not working in non-GUI mode. Please try to change the coding to make use of non-GUI mode." It seems the above code is making use of GUI mode. 
</code></pre>

<p>I need an alternate code to check url existence without using GUI.</p>

<p>Regards
Linda</p>
