tags:

views:

45

answers:

2

Hello,

I am using the method openStream with Java

in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));

How long is the method waiting of a response from the service where the URL is sended?

I am becoming same times errors messages like this and i don't know why.

java.net.UnknownHostException: dev.virtualearth.net

               at java.net.PlainSocketImpl.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 java.net.URL.openStream(Unknown Source)

Thanks

+1  A: 

openStream() method is a shortcut for URL.openConnection().getInputStream()

you can set the timeout by yourself:

URLConnection con = url.openConnection();
con.setConnectTimeout(XXX);

From the JDK: "If the timeout expires before the connection can be established, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout."

The default timeout is 0

Your Exception "Thrown to indicate that the IP address of a host could not be determined."

MrOhad
How can I fix this?
Haythem
+1  A: 

java.net.UnknownHostException: dev.virtualearth.net implies that your DNS configuration is incorrect since Java doesn't know how to resolve dev.virtualearth.net to an IP address. What is the string representation of the URL you are opening?

SB
I am using an URL Object. and the http://.. is giving me a response when I call it with my webbrowser. I think too it s a problem with the DNS configuration. Do you know what is this the problem exactly?
Haythem
Do you sometimes get the error when browsing as well?
SB
never get error with the webbrowser.
Haythem
Are you going through a HTTP proxy with your browser? If so, you need to configure that for the URL connection as well. You can find info about it at http://download-llnw.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
SB
Thank you. if it is a proxy setting Problem, why it was working same times before?
Haythem
That's unknown. What you can try is using the an IP that you know works, such as the one you get when you are able to ping it. If it works consistently, then you know you have a DNS error and it's probably some issue in the network. I imagine if you try enough, your browser will have the same errors you see - perhaps the browser is using a cached dns response as well.
SB