title: wait for a long HTTP response in java
body: <p>I hava a java application that calls a service.  The service call will take about 5-10 minutes to complete its operation and return a status log as a response.  (The reason behind the long duration is to copy files/images from one server to another).  In the meantime any other call made to the service will be rejected with an error response.  What's the best way to wait for this usually long response?</p>
  
  <p>I tried the following request with no luck:</p>
  
  <p>1.HTTPUrlConnection:</p>
  
  <pre><code>HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setRequestMethod("GET");
  conn.setReadTimeout(10 * 60000);
  conn.setConnectTimeout(10 * 60000);
  conn.connect();
  try {
      conn.getInputStream();
  } catch (Exception e) {
    //error handling
  }
  </code></pre>
  
  <p>results: after 5 minutes or so the request fails, error message indicating the service is already in progress.  Seems like request is being call twice to the service after some kind of timeout.</p>
  
  <p>2.HttpClient</p>
  
  <pre><code>HttpClient client = new HttpClient ();
  GetMethod method = new GetMethod(requestUrl);
  
  try {
      int statusCode = client.executeMethod(method);
      if(statusCode == HttpStatus.SC_OK) {
          // success
      } else {
          String errorMessage = method.getResponseBodyAsString();
          //error handling
      }
  }
  </code></pre>
  
  <p>results: after 5 minutes or so, the httpClient fails with an "Connection Reset" error.</p>
  
  <p>Note that I'm able to run the url request on a browser, and is able to get a successful response back.  Did I miss anything?</p>
  
  <p>Thanks. </p>