I am using the Apache Wink REST Client in my Java EE application running in WebSphere Liberty Profile to call external services. There are two separate services that I need to call. Calls to the first service always works.
Calls to the second service only work once, and from then on I always get a "Connection reset" error unless I recycle my WLP server. The only difference I see between the one that works and the one that doesn't, is that the failing one has the 'Connection: Keep-Alive' header in the response.
Could the Keep-Alive be causing the issue? Is there some way to handle or override that from the REST client? I have all the Wink REST client code in one method, and it never reuses any of the objects such as RestClient, Resource, ClientResponse, etc. - I always get new objects every time.
ClientResponse clientResponse = null;
try {
clientResponse = executeRestClientGet(serviceUrlPath, headers, mgrId);
int statusCode = clientResponse.getStatusCode();
String jsonString;
if (statusCode == Response.Status.OK.getStatusCode()) {
jsonString = clientResponse.getEntity(String.class);
try {
result = (JSONObject) JSON.parse(jsonString);
} catch (JSONException exc) {
...
}
} else {
...
}
private static ClientResponse executeRestClientGet(String serviceUrlPath, HashMap<String, String> headers,
String mgrId) {
ClientResponse clientResponse = null;
try {
RestClient restClient = new RestClient();
Resource resource = restClient.resource(serviceUrlPath);
addHeadersToResource(resource, headers, null);
clientResponse = resource.get();
} catch (Exception exc) {
...
}
return clientResponse;
}
