I solved the problem by using Apache Http Client instead of
ClientResource from RESTlet.
I tested both ClientResource and Apache HTTP for the same RESTlet-based web service on remote Linux server. The former took about 10 seconds and the
latter less than 1 second. And I don't know why.
public class Test
{
public static void main(String [] args)
{
HttpClient httpClient = HttpClientBuilder.create().build(); //Use this instead
try {
HttpPost request = new HttpPost("http://hostname:port/testService");
StringEntity params =new StringEntity("{\"key\" : \"value\"}");
request.addHeader("content-type", "application/json");
request.addHeader("Accept", "application/json");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
String json_string = EntityUtils.toString(response.getEntity());
System.out.println(json_string);
}catch (Exception ex) {
// handle exception here
} finally {
httpClient.getConnectionManager().shutdown(); //Deprecated
}
}
}