Skip to content

Commit db18092

Browse files
author
Jérôme Louvel
committed
- Continued support for non-blocking HTTPS to the internal NIO connectors, client-side and server-side.
- Deprecated the Client#connectTimeout property as it is hard to find compared to other connector parameters. Also, it isn't available for all connectors so it can be confusing to expose it. Use the "socketConnectTimeoutMs" connector parameter instead or the "maxIoIdleTimeMs" parameter for internal NIO connectors.
1 parent 23899cf commit db18092

File tree

7 files changed

+59
-14
lines changed

7 files changed

+59
-14
lines changed

build/tmpl/text/changes.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Changes log
55

66
- @version-full@ (@release-date@)
77
- API changes
8+
- Deprecated the Client#connectTimeout property as it is hard to find
9+
compared to other connector parameters. Also, it isn't available for
10+
all connectors so it can be confusing to expose it.
11+
Use the "socketConnectTimeoutMs" connector parameter instead or
12+
the "maxIoIdleTimeMs" parameter for internal NIO connectors.
813
- Enhancements
914
- Added support for non-blocking HTTPS to the internal NIO connectors,
1015
client-side and server-side. Sponsored by NetDev.

modules/org.restlet.ext.httpclient/src/org/restlet/ext/httpclient/HttpClientHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ protected void configure(HttpParams params) {
223223
HttpClientParams.setCookiePolicy(params,
224224
CookiePolicy.BROWSER_COMPATIBILITY);
225225
HttpConnectionParams.setTcpNoDelay(params, getTcpNoDelay());
226-
HttpConnectionParams.setConnectionTimeout(params, getConnectTimeout());
226+
HttpConnectionParams.setConnectionTimeout(params, getSocketConnectTimeoutMs());
227227
HttpConnectionParams.setSoTimeout(params, getSocketTimeout());
228228

229229
String httpProxyHost = getProxyHost();

modules/org.restlet.ext.net/src/org/restlet/ext/net/FtpClientHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void handle(Request request, Response response) {
166166
int minorVersionNumber = SystemUtils.getJavaMinorVersion();
167167
if ((majorVersionNumber > 1)
168168
|| ((majorVersionNumber == 1) && (minorVersionNumber >= 5))) {
169-
connection.setConnectTimeout(getConnectTimeout());
169+
connection.setConnectTimeout(getSocketConnectTimeoutMs());
170170
connection.setReadTimeout(getReadTimeout());
171171
}
172172

modules/org.restlet.ext.net/src/org/restlet/ext/net/internal/HttpUrlConnectionCall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public HttpUrlConnectionCall(HttpClientHelper helper, String method,
102102
if ((majorVersionNumber > 1)
103103
|| ((majorVersionNumber == 1) && (minorVersionNumber >= 5))) {
104104
this.connection.setConnectTimeout(getHelper()
105-
.getConnectTimeout());
105+
.getSocketConnectTimeoutMs());
106106
this.connection.setReadTimeout(getHelper().getReadTimeout());
107107
}
108108

modules/org.restlet/src/org/restlet/Client.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ public Client(String protocolName) {
142142
* meaning an infinite timeout.
143143
*
144144
* @return The connection timeout.
145+
* @deprecated Use the equivalent "socketConnectTimeoutMs" connector parameter.
145146
*/
147+
@Deprecated
146148
public int getConnectTimeout() {
147149
return this.connectTimeout;
148150
}
@@ -178,11 +180,9 @@ public void handle(Request request, Response response) {
178180
getHelper().handle(request, response);
179181
} else {
180182
StringBuilder sb = new StringBuilder();
181-
sb
182-
.append("No available client connector supports the required protocol: ");
183+
sb.append("No available client connector supports the required protocol: ");
183184
sb.append("'").append(request.getProtocol().getName()).append("'.");
184-
sb
185-
.append(" Please add the JAR of a matching connector to your classpath.");
185+
sb.append(" Please add the JAR of a matching connector to your classpath.");
186186
response.setStatus(Status.CONNECTOR_ERROR_INTERNAL, sb.toString());
187187
}
188188
}
@@ -232,7 +232,9 @@ public boolean isAvailable() {
232232
*
233233
* @param connectTimeout
234234
* The connection timeout.
235+
* @deprecated Use the equivalent connector parameters.
235236
*/
237+
@Deprecated
236238
public void setConnectTimeout(int connectTimeout) {
237239
this.connectTimeout = connectTimeout;
238240
}

modules/org.restlet/src/org/restlet/engine/ClientHelper.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,23 @@
3333
import org.restlet.Client;
3434

3535
/**
36-
* Client connector helper.
36+
* Client connector helper. Base client helper based on NIO non blocking
37+
* sockets. Here is the list of parameters that are supported. They should be
38+
* set in the Client's context before it is started:
39+
* <table>
40+
* <tr>
41+
* <th>Parameter name</th>
42+
* <th>Value type</th>
43+
* <th>Default value</th>
44+
* <th>Description</th>
45+
* </tr>
46+
* <tr>
47+
* <td>socketConnectTimeoutMs</td>
48+
* <td>int</td>
49+
* <td>0</td>
50+
* <td>The socket connection timeout or 0 for unlimited wait.</td>
51+
* </tr>
52+
* </table>
3753
*
3854
* @author Jerome Louvel
3955
*/
@@ -54,8 +70,16 @@ public ClientHelper(Client client) {
5470
*
5571
* @return The connection timeout.
5672
*/
57-
public int getConnectTimeout() {
58-
return getHelped().getConnectTimeout();
73+
@SuppressWarnings("deprecation")
74+
public int getSocketConnectTimeoutMs() {
75+
int result = getHelped().getConnectTimeout();
76+
77+
if (getHelpedParameters().getNames().contains("socketConnectTimeoutMs")) {
78+
result = Integer.parseInt(getHelpedParameters().getFirstValue(
79+
"socketConnectTimeoutMs", "0"));
80+
}
81+
82+
return result;
5983
}
6084

6185
}

modules/org.restlet/src/org/restlet/engine/connector/ClientConnectionHelper.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@
8484
* <td>The port of the HTTP proxy.</td>
8585
* </tr>
8686
* <tr>
87+
* <td>socketConnectTimeoutMs</td>
88+
* <td>int</td>
89+
* <td>0</td>
90+
* <td>The socket connection timeout or 0 for unlimited wait.</td>
91+
* </tr>
92+
* <tr>
8793
* <td>socketKeepAlive</td>
8894
* <td>boolean</td>
8995
* <td>true</td>
@@ -503,12 +509,20 @@ public String getCertAlgorithm() {
503509
}
504510

505511
/**
506-
* Returns the connection timeout.
512+
* Returns the socket connection timeout.
507513
*
508-
* @return The connection timeout.
514+
* @return The socket connection timeout.
509515
*/
510-
public int getConnectTimeout() {
511-
return getHelped().getConnectTimeout();
516+
@SuppressWarnings("deprecation")
517+
public int getSocketConnectTimeoutMs() {
518+
int result = getHelped().getConnectTimeout();
519+
520+
if (getHelpedParameters().getNames().contains("socketConnectTimeoutMs")) {
521+
result = Integer.parseInt(getHelpedParameters().getFirstValue(
522+
"socketConnectTimeoutMs", "0"));
523+
}
524+
525+
return result;
512526
}
513527

514528
/**

0 commit comments

Comments
 (0)