Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to resolve UnknownHostException:  RSS feed

 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
friends i am writing one tester class for my project

my code is as follows

public class UrlReader {

private static void printMessage(Object obj){
System.out.println(obj);
}

private URLConnection getUrlConnection(String url) {
if(url==null || (url.trim()).equals("")){
throw new IllegalArgumentException("parameter passed as argument is null or Empty");
}

URLConnection urlConnection = null;
URL urlObject=null;
try {
urlObject = new URL(url);
urlConnection = urlObject.openConnection();
} catch (MalformedURLException e) { // new URL() failed
e.printStackTrace();
} catch (IOException e) { // openConnection() failed
e.printStackTrace();
}
printMessage("" + "no error");
return urlConnection;

}

private void printStream(InputStream inputStream) throws IOException{
if(inputStream==null){
throw new IllegalArgumentException("parameter passed as argument is null");
}

BufferedReader buffReader = new BufferedReader(new InputStreamReader(inputStream));

String inputLine;
try{
while ((inputLine = buffReader.readLine()) != null) {
System.out.println(inputLine);
}
}catch(IOException ioe){
printMessage("" + "in printStream");
ioe.printStackTrace();
}
buffReader.close();


}
public static void main(String[] args) throws Exception {
UrlReader ur=new UrlReader();
//URLConnection urc=ur.getUrlConnection("http://172.16.2.45:8081/EMS");
URLConnection urc=ur.getUrlConnection("http://www.springframework.org/docs/reference/mvc.html#mvc-themeresolver");

printMessage(" "+urc.getInputStream());
ur.printStream(urc.getInputStream());

i am just testing this code on 2 diff urls
1] one which is running on local machine http://172.16.2.45:8081/EMS
2] other one is springframework's url

when i am testing with url on my machine program work fine but when i was just trying to test my code for spring framwork 's link it
gives me following exception

Exception in thread "main" java.net.UnknownHostException: www.springframework.org
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 com.net.UrlReader.main(UrlReader.java:57)

how to do setting for it ???
i know this exception occur beacause of my class unable to get IP of the application which is not in LAN

how to get Ip of a site which is not in LAN


[ May 13, 2006: Message edited by: ganesh pol ]
 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plz help me to solve this problem
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!