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

Getting java.net.ConnectException while accessing a webservice.  RSS feed

 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
We are trying to hit a webservice and expecting an xml response.The client is a java application.Please have a look on this code snippet of the client:



Here url is the URL object.Through java code we are getting this exception but if we pass this url directly to the browser,it returns the expected output.
Please help.
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the debug output tell you ? You have a lot of code there, but I don't see any logger ?
 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it simply says: Exception in thread "main" java.net.ConnectException: Connection timed out: connect
As far as i know,connection timed out exception occurs if
1. Url is wrong or
2.Firewall issues

But as i said this url works fine if i seperately gives it to the browser,i.e i can get the xml response so i don't think the url is wrong so is it any firewall issue?
Please respond

Thanks.
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add some logging statements into your code to record various details about what your code is doing, not the least of which is the URL that gets constructed. Breakdown your composite code and create an actual String object that you pass to URL constructor.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your browser is configured to reach external URLs with the help of a proxy server, then Java code won't be able to reach those URLs unless it is also told to use that same proxy server. So... is your browser configured like that?

And yes, like Roger says, put in some debug code to make sure your URL is really what you think it is. And don't be misled by browser features like automatically adding "http://" on the start of a URL if you forgot to include it; Java expects a proper URL.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!