Maybe use a threadpool, and kill the thread if you don't have a response
back in a specified time? Uses deprecated APIs, and Sun naturally says
"Don't do it this way, since it's useful" -- but it works, I've done it,
since I have to do the exact same thing at work.
>From: Greg Nudelman <[EMAIL PROTECTED]>
>Reply-To: "JDJList" <[EMAIL PROTECTED]>
>To: "JDJList" <[EMAIL PROTECTED]>
>Subject: [jdjlist] RE: HttpURLConnection timeout
>Date: Tue, 1 Oct 2002 17:18:27 -0700
>
>I am thouroughly fed up with this functionality. Disconnect() and = null do
>not work. Still hangs:
>
> ............................
> out = new DataOutputStream(rawOutStream);
> 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;
>
> public HttpURLDisconector(HttpURLConnection conn) {
> this.conn = conn;
> }
>
> public void run() {
> 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 timeout
>
>
>Thanks 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 timeout
>
>
>I 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 timeout
>
>
>
>Dear 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
>____________________________________________________
-----------------------------------------------
Joseph B. Ottinger [EMAIL PROTECTED]
http://enigmastation.com IT Consultant
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________