How to override the read timeout set to 60 seconds when using Application class

83 views
Skip to first unread message

Marek Nemečkay

unread,
Nov 21, 2023, 11:32:47 AM11/21/23
to Restlet Framework
Hello,

we're facing here a problem with long term request, which gets a read timeout (java.net.SocketTimeoutException: Read timed out) leading the an HTTP ERROR 1001: Communication Error (1001) - The connector failed to complete the communication with the server

Out server application is implemented as a class derived from org.restlet.Application and configured via org.restlet.ext.spring.SpringServerServlet in web.xml and Spring context.

We can that there are 2 Client objects being created at the application start (first request) where an implicit read timeout is being set to 60 seconds in org.restlet.Component during the execution of the method startClients(). But it is impossible to override this timeout settings. Any idea how this timeout could be adapted?

Thanks and BR,
Marek

Thierry Boileau

unread,
Dec 27, 2023, 10:45:55 AM12/27/23
to Restlet Framework, marek.n...@gmail.com
Hello Marek,

The general documentation about client connectors is available here.
You will find sample code that describe how to update the parameters of the client object.
Then in order to know which parameter to setup you need to refer either to the "common" parameters (check doc above, but timeout is not referred there) or to the parameters that are specific to the Restlet extension that implement the Client connectod.
They are listed here. by following the links you will see the javadocs that define the available parameters.
For instance, here are listed the parameters of the Apache HttpClient extension: https://javadocs.restlet.talend.com/2.4/jse/ext/org/restlet/ext/httpclient/HttpClientHelper.html

I hope this will help you.

Best regars,
Thierry Boileau

Marek Nemečkay

unread,
Jan 10, 2024, 11:24:35 AM1/10/24
to Restlet Framework, thbo...@gmail.com, Marek Nemečkay
Hello  Thierry,

exactly all these parameters we've already tried:

getContext().getParameters().add("readTimeout", String.valueOf(this.proxyReadTimeoutMs));
getContext().getParameters().add("socketTimeout", String.valueOf(this.proxyReadTimeoutMs));
getContext().getParameters().add("socketConnectTimeoutMs", String.valueOf(this.proxyConnectTimeoutMs));

getContext().getClientDispatcher().getContext().getParameters().add("readTimeout", String.valueOf(this.proxyReadTimeoutMs));
getContext().getClientDispatcher().getContext().getParameters().add("socketTimeout", String.valueOf(this.proxyReadTimeoutMs));
getContext().getClientDispatcher().getContext().getParameters().add("socketConnectTimeoutMs", String.valueOf(this.proxyConnectTimeoutMs));

Unfortunately none of these works, the actual read timeout is hardcoded in org.restlet.engine.connector.HttpClientHelper:

public int getReadTimeout() {
return Integer.parseInt(this.getHelpedParameters().getFirstValue("readTimeout", "60000"));
}

The list of HelpedParameters is always empty, so the default value is used. 

BR,
Marek

Marek Nemečkay

unread,
Jan 11, 2024, 12:01:57 PM1/11/24
to Restlet Framework, Marek Nemečkay, thbo...@gmail.com
Hello  Thierry,

I think the problem is maybe related to the actual usage of the Restlet framework. We've all our code implemented in an inherited class from org.restlet.Application and this class is loaded via the SpringServerServlet configured in web.xml:

<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.spring.SpringServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>proxyRestProvider</param-value>
</init-param>
<init-param>
<param-name>org.restlet.clients</param-name>
<param-value>HTTP HTTPS</param-value>
</init-param>
</servlet> 

All the default clients are already loaded and the configuration is impossible to change, tried also this:

for (ConnectorHelper<Client> c : Engine.getInstance().getRegisteredClients()) {
if (c instanceof org.restlet.ext.httpclient.HttpClientHelper || c instanceof org.restlet.engine.connector.HttpClientHelper) {
c.getHelpedParameters().add("socketTimeout", String.valueOf(this.proxyReadTimeoutMs));
c.getHelpedParameters().add("readTimeout", String.valueOf(this.proxyReadTimeoutMs));
c.getHelpedParameters().add("http.socket.timeout", String.valueOf(this.proxyReadTimeoutMs));
}
}

Did not work.

BR,
Marek

Thierry Boileau

unread,
Feb 4, 2024, 4:26:32 PM2/4/24
to Marek Nemečkay, Restlet Framework
Hello Marek

you were right, the issue comes from the way the application is configured.
I send you a sample project (not a Spring based project, but it should be the same).
The way that gives more control on connectors is the one referenced as "mode #2" in the Javadoc of the ServerServlet.

Tell if its ok for you. I'll be more reactive this time...

Best regards,
Thierry Boileau

RestletHelloWorld.zip

Marek Nemečkay

unread,
Feb 15, 2024, 3:21:19 AM2/15/24
to Restlet Framework, thbo...@gmail.com, Restlet Framework, Marek Nemečkay
Thank you  Thierry,

will have a look at this solution, so far we've just created a workaround to hardcode a different timeout with the HttpClientHelper:

public class MyHttpClientHelper extends HttpClientHelper {

private int readTimeout = 3600000;

public MyHttpClientHelper(Client client) {
super(client);
}

public MyHttpClientHelper(Client client, int readTimeout) {
super(client);
this.readTimeout = readTimeout;
}

@Override
public int getReadTimeout() {
return readTimeout;
}
}

Reply all
Reply to author
Forward
0 new messages