I'm using the Restlet framework and specifically the class ClientResource
to send HTTP request to a server through its own get()
, post()
, put()
and delete()
methods. Since sometimes the server is offline and therefore unreachable, I would like to set a smaller timeout than the default. How can I do it?
At the moment I've tried in this way with no success:
ClientResource cr = new ClientResource(uri);
Context context = new Context();
context.getParameters().add("maxIoIdleTimeMs", "0");
context.getParameters().add("ioMaxIdleTimeMs", "0");
context.getParameters().add("socketTimeout", "1000");
cr.setNext(new Client(context, Protocol.HTTP));
cr.setRetryOnError(false);
...
Representation r = cr.get();
The result is the same of the default case, that is a timeout of about 60-90 seconds before the connection error exception is returned from the get()
method. My purpose is to anticipate it.
To set the timeout properly:
This code will throw a timeout exception as what you needed, increase the
socketTimeout
to at least 1000 to be able to retrieve the test API JSON response.Also, these versions was used: