setConnectionRequestTimeout for fix problem with hang
This commit is contained in:
parent
cc38a3c149
commit
b795c33d90
2
pom.xml
2
pom.xml
@ -22,7 +22,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<jersey.version>2.22.1</jersey.version>
|
||||
<httpcompontents.version>4.5.1</httpcompontents.version>
|
||||
<httpcompontents.version>4.5.2</httpcompontents.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -8,4 +8,5 @@ package org.telegram.telegrambots.api;
|
||||
*/
|
||||
public class Constants {
|
||||
public static final String BASEURL = "https://api.telegram.org/bot";
|
||||
public static final int SOCKET_TIMEOUT = 30 * 1000;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package org.telegram.telegrambots.updatesreceivers;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.entity.BufferedHttpEntity;
|
||||
@ -57,9 +58,17 @@ public class UpdatesThread {
|
||||
request.setOffset(lastReceivedUpdate + 1);
|
||||
CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionTimeToLive(20, TimeUnit.SECONDS).build();
|
||||
String url = Constants.BASEURL + token + "/" + GetUpdates.PATH;
|
||||
//config
|
||||
RequestConfig defaultRequestConfig = RequestConfig.custom().build();
|
||||
RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
|
||||
.setSocketTimeout(Constants.SOCKET_TIMEOUT)
|
||||
.setConnectTimeout(Constants.SOCKET_TIMEOUT)
|
||||
.setConnectionRequestTimeout(Constants.SOCKET_TIMEOUT).build();
|
||||
//http client
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
try {
|
||||
httpPost.addHeader("charset", "UTF-8");
|
||||
httpPost.setConfig(requestConfig);
|
||||
httpPost.setEntity(new StringEntity(request.toJson().toString(), ContentType.APPLICATION_JSON));
|
||||
HttpResponse response;
|
||||
response = httpclient.execute(httpPost);
|
||||
|
Loading…
Reference in New Issue
Block a user