out.writeBytes(body);
out.flush();
out.close();
//Java timer
timer = new Timer();
timer.schedule(new HttpURLDisconector(conn), seconds*1000);
InputStream rawInStream = conn.getInputStream();
..........................
class HttpURLDisconector extends TimerTask {
HttpURLConnection conn;
this.conn = conn;
}
System.out.println("HttpURLDisconector: Time's up!");
try {
if(conn != null) {
System.out.println("HttpURLDisconector: not null!");
conn.disconnect();
System.out.println("HttpURLDisconector: disconnected");
conn = null;
System.out.println("HttpURLDisconector: nulled out");
} else {
System.out.println("HttpURLDisconector: NULL!");
}
} catch (Exception ioe) {
System.out.println("HttpURLDisconector: Exception in trying close connections/streams: " + ioe);
ioe.printStackTrace();
//eat it
}//end try/catch
System.out.println("HttpURLDisconector: Done");
}
}
____________________________________________________-----Original Message-----
From: Greg Nudelman
Sent: Tuesday, October 01, 2002 4:58 PM
To: JDJList
Subject: [jdjlist] RE: HttpURLConnection timeoutThanks Madhu, I believe you're right. Unfortunately, like I said in my post, this is an app server issue, not WebServer (like Apache).Anyone tried to use disconnect() method? I'm trying that now.I don't want to download third-party libraries for this, but I am about at my wit's end.G*d, is this not a classic example of Sun's pig-headedness? Did they not think someone's going to actually USE their classes? For something actually remotely USEFUL, like Web Services? How can they promote WS if they don't even provide a timeout on their connection API?????ARGH!!!!Greg____________________________________________________-----Original Message-----
From: Madhu Nama [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 01, 2002 4:32 PM
To: JDJList
Subject: [jdjlist] RE: HttpURLConnection timeoutI guess this is a configurable parameter on the WebServer.Checking with the admin docs of your WebServer might help...-Madhu.____________________________________________________-----Original Message-----
From: Greg Nudelman [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 01, 2002 4:10 PM
To: JDJList
Subject: [jdjlist] HttpURLConnection timeoutDear All:
How do I set the timeout for an HttpURLConnection running from a server? i.e. if it did not get the response back in stipulated time, drop the connection?
This is my server connection code, look for a FIXME note. I found lots of notes about the Servlet utilities for this, but little about the server-based URL connections.
Thanks!
Greg
//begin open URL
URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(POST);
conn.setAllowUserInteraction(false); // you may not ask the user
conn.setDoOutput(true); // we want to send things
conn.setDoInput(true); // we want recieve things
conn.setUseCaches(false); // turn off caching//the Content-type should be default, but we set it anyway
conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
//fixes Netscap bug?? Do we need this?
//conn.setRequestProperty("User-Agent","Mozilla/4.7 [en] (Win98; I)");
//the content-length should not be necessary, but we're cautious
conn.setRequestProperty("Content-length", Integer.toString(body.length()));OutputStream rawOutStream = conn.getOutputStream();
out = new DataOutputStream(rawOutStream);
out.writeBytes(body);
out.flush();
out.close();// get the input stream for reading the reply
// IMPORTANT! Your body will not get transmitted if you get the
// InputStream before completely writing out your output first!//FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! FIXME!! put some type of the timeout code here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?
InputStream rawInStream = conn.getInputStream();
in = new BufferedReader(new InputStreamReader(rawInStream));String inputLine;
while ((inputLine = in.readLine()) != null)
responseMessage.append(inputLine);in.close();
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________
