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?
I tried the following request with no luck:
1.HTTPUrlConnection:
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
}
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.
2.HttpClient
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
}
}
results: after 5 minutes or so, the httpClient fails with an "Connection Reset" error.
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?
Thanks.