Reputation: 11
I am using this method to set CONNECTION_TIMEOUT and SO_TIMEOUT
public void setConfig(ContentType contentType, Integer timeout) {
setConfig(SerenityRest.config()
.sslConfig(new SSLConfig().allowAllHostnames().relaxedHTTPSValidation())
.httpClient(HttpClientConfig.httpClientConfig()
.setParam(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout)
.setParam(CoreConnectionPNames.SO_TIMEOUT, timeout)))
.addHeader(HttpHeaders.CONTENT_TYPE, contentType.toString());
}
Upvotes: 1
Views: 593
Reputation: 1
Since 4.0 the org.apache.http.params.CoreConnectionPNames is deprecated and and the class has been removed, so you can't use the built-in constants anymore. if you have(4.3) use configuration classes provided 'org.apache.http.config' and 'org.apache.http.client.config'
You can re-write your code as given below:
public void setConfig(ContentType contentType, Integer timeout) {
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(timeout)
.setConnectTimeout(timeout)
.setConnectionRequestTimeout(timeout)
.build();
HttpClientConfig httpClientFactory = HttpClientConfig.httpClientConfig()
.httpClientFactory(() -> HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.build());
setConfig(SerenityRest.config()
.sslConfig(new SSLConfig().allowAllHostnames().relaxedHTTPSValidation())
.httpClient(httpClientFactory)
.addHeader(HttpHeaders.CONTENT_TYPE, contentType.toString());
}
Please accept the answer if it works for you. Thanks
Upvotes: 0
Reputation: 5072
org.apache.http.params.CoreConnectionPNames
is deprecated and the class was removed. This prevents you from using the pre-made constants.
According to Android Developer Reference for CoreConnectionPNames
:
SO_TIMEOUT
was "http.socket.timeout"
.
java.net.SocketOptions.SO_TIMEOUT
, but this is an int
so this may not be proper guidanceCONNECTION_TIMEOUT
was "http.connection.timeout"
.
Substituting these for the constants or creating your own constants can replace the original constants; however there is no guarantee these settings will be recognized going forward. This SO answer should provide guidance on how to proceed forward modernizing the timeout.
Broad guidance is to swap to applying org.apache.http.client.config.RequestConfig
.
RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout).build();
Upvotes: 0