Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I tried to send an xml to an url its ,

 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to send an xml to an url its ,
throwing error when its tries to opens connection to the URL (url.openStream())

URL url = new URL("http://xx/yy?xml=test xml");
connection.setDoOutput(true);
connection.setDoInput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));


But when i tried to connect to the url directly from the browser i could able to connect.Only through the code i'm getting the error.






Please help me..
thanks you.
 
Joe Ess
Bartender
Posts: 9299
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP is a request-response protocol. Many servers will not start to process a request until the client opens the response. Try reading from your BufferedReader.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm reading only from,


BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));




 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You create the reader, but do you also read all data from it?
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i tried to read,



But i'm getting error at this place itself,
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the server reachable from the machine where this code is run? Meaning, can you retrieve that URL by copying it into a browser?
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
same url can be accessed and able to get reply from browser , the problem comes when trying to connect from code
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using a proxy in your browser? If so, you must also use that proxy in your code:

 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i'm using Proxy address for connecting to internet,

Is this is the way to set Proxy,



 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks alright to me.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but still its throwing same (timeout error) at this line,

 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because url.openStream() is shorthand for url.openConnection().getInputStream() - and therefore does not use the proxy. In my code example I've shown you to use connection.getInputStream() instead.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to get the proxy address dynamically.Because if i put the code in some other system the proxy may change.
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can get that without using either JNI or the registry.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The has been solved.thanks for your valueable input and time.
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you care to tell us how you did this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic