Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

InputStream in = uConnect.getInputStream(); error

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
It would be kind if anybody could tell me why i am getting :java.io.FileNotFoundException:
on line
InputStream in = uConnect.getInputStream();
-----------------------------------------------
I am created a URL object and passing that URL object in a URLConnection object.
String page_to_connect = "http://cd2iis02/inbi/admin/updatestatus.cfm?domain="+sdomain_name+"&requestid="+sreq_id+"&status="+status+"&msg="+ smessage;
URL serverUrl = new URL(page_to_connect);
URLConnection uConnect = serverUrl.openConnection();
uConnect.setDoOutput(true);
uConnect.setUseCaches(false);
PrintStream out = new PrintStream(uConnect.getOutputStream());
out.close();
//Filenotfound exception is thrown at the below line**
InputStream in = uConnect.getInputStream();// error at this line
StringBuffer response = new StringBuffer();
int chr;
while((chr=in.read())!=-1) { // this is line number 94
response.append((char)chr);
}
in.close();
String sResponse = response.toString();

Can anyone tell me why is this exception coming ,Its not finding the file . Is there any way to rectify this error.
Any replies will be appreciated
Thanks
Regards,
John
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by L.John:
Hi,
It would be kind if anybody could tell me why i am getting :java.io.FileNotFoundException:
on line
InputStream in = uConnect.getInputStream();


See wether you r trying to invoke doGet or doPost .... i think doGet is not Possible by this try doPost once i hope ur code will work ......
 
L.John
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pradeepta,
Thanks for replying to my query. Actually this is not a servlet but a java class, so i am not using doGet method in this.
What i wanted to do was to get the values and send it to the webpage on the server which is accepting HTTP Request only.
Luckily i came to know of another alternative i.e using sockets , I used Socket class specifying the hostaddress and port number and then used the following:
InputStreamReader in = new InputStreamReader(clientsocket.getInputStream());
OR
InputStream in = clientsocket.getInputStream();
then
BufferedReader br = new BufferedReader(in);
PrintWriter out = new PrintWriter(clientsocket.getOutputStream(),true);
String url = "GET /the directory_path.cfm?name="+_name+"&requestid="+lreq_id+"&status="+lStatus+"&msg="+encodedMessage+HttpVersion;

This is the way for sending HTTP request , which i came to know .
and then using either a byte class printing the response out to the browser after appending it to a string.
Kindly let me know if there could be a better way to do this .
Many thanks,
Regards,
John
 
Pradeepta Bhattacharya
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear John:
Thanks For Letting me know the soln.
Bye
Pradeepta
 
L.John
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pradeepta,
It would be kind of you if you can help me with a better way using Bufferred Input and output Stream class for the below functionality:
clientsocket = new Socket(shost,iport);
InputStream in = clientsocket.getInputStream();
OutputStream out = clientsocket.getOutputStream();
/**
* Here i am sending a HTTP request to this URL along with 4
* variables
*/
String url = "GET /info/admin/updatestatus.cfm?name="+s_name+"&requestid="+lreq_id+"&status="+lStatus+"&msg="+encodedMessage+HttpVersion;
byte buf[] = url.getBytes();
out.write(buf);
out.flush();
StringBuffer response = new StringBuffer();
int chr;
while((chr=in.read())!=-1) {
response.append((char)chr);// sresponse is stringbuffer
}
String sResponse = response.toString();
System.out.println(sResponse);
How can i proceed further usinga bufferredInpout and out Stream and get the same functionality working ?
Thanking you in advance ,
Regards,
John

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic