Tutorial :UnknownHostException while redirecting queries to google and getting results in JSon object


Loading classifier from D:\PROJECT\classifiers\NERDemo\classifiers\ner-eng-ie.crf-3-all2008.ser.gz ... done [2.0 sec].  Original Query was riot in India.  Parsing Queries and expanding tokens from the Ontologies..  {locations=[India], events=[riot]}  Search query is null  Something went wrong...    java.net.UnknownHostException: ajax.googleapis.com   at java.net.PlainSocketImpl.connect(Unknown Source)   at java.net.SocksSocketImpl.connect(Unknown Source)   at java.net.Socket.connect(Unknown Source)   at java.net.Socket.connect(Unknown Source)   at sun.net.NetworkClient.doConnect(Unknown Source)   at sun.net.www.http.HttpClient.openServer(Unknown Source)   at sun.net.www.http.HttpClient.openServer(Unknown Source)   at sun.net.www.http.HttpClient.<init>(Unknown Source)   at sun.net.www.http.HttpClient.New(Unknown Source)   at sun.net.www.http.HttpClient.New(Unknown Source)   at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)   at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)   at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)   at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)   at org.girs2.SearchHandler.makeQuery(SearchHandler.java:35)   at org.girs2.GIRS.search(GIRS.java:37)   at org.girs2.GIRS.main(GIRS.java:62)  Exception in thread "main" java.lang.NullPointerException   at org.girs2.GIRS.search(GIRS.java:44)   at org.girs2.GIRS.main(GIRS.java:62)  


Looks like you probably have or had a DNS lookup failure. This tells you what happened:

java.net.UnknownHostException: ajax.googleapis.com  

If you always get this exception and you can otherwise access this host by name, then I don't know what this could be, but odds are that this was a temporary DNS failure.

What should you do when you get this Exception? Well, if the address is one that you fully expect you should be able to get to -- such as this one -- then when you catch the Exception, you sleep for a while (perhaps 10 or 15 seconds, maybe even 30 or 60 seconds, depending on your application's needs) and try again.

If after several retries -- don't just retry forever! -- you still cannot reach the site, then log a reasonable complaint or otherwise complain that you cannot reach the site and have your application exit.

There's not much you can do when DNS fails except give up or wait and try again.


probably you're behind a firewall.
Try to connect to ajax.googleapis.com, something like

    ping ajax.googleapis.com  

do you get an IP-Number, something like
do you get some server reply?

If none works,try http://ajax.googleapis.com/ on your browser.

If it don't work (showing Google page), your connection to the network is broken: no connection to DNS or to the site.

If it works, you're probably behind a firewall, you'll need a proxy. Get the proxy settings (host and port) from your browser and use them to run your application: see Chapter 2.1

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »