Commit b6507d76557c7780f2b6a8e7362d51ac51b1df31

Authored by 杨鸣坤
1 parent b71f9ae5

fix: 为 HTTP 请求添加超时配置

@@ -15,6 +15,7 @@ import org.apache.http.client.methods.CloseableHttpResponse; @@ -15,6 +15,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
15 import org.apache.http.client.methods.HttpPost; 15 import org.apache.http.client.methods.HttpPost;
16 import org.apache.http.entity.ContentType; 16 import org.apache.http.entity.ContentType;
17 import org.apache.http.entity.StringEntity; 17 import org.apache.http.entity.StringEntity;
  18 +import org.apache.http.client.config.RequestConfig;
18 import org.apache.http.impl.client.CloseableHttpClient; 19 import org.apache.http.impl.client.CloseableHttpClient;
19 import org.apache.http.impl.client.HttpClients; 20 import org.apache.http.impl.client.HttpClients;
20 import org.apache.http.message.BasicHeader; 21 import org.apache.http.message.BasicHeader;
@@ -196,7 +197,14 @@ public class DjxcDevicePullService { @@ -196,7 +197,14 @@ public class DjxcDevicePullService {
196 } 197 }
197 198
198 private String sendPost(HttpPost httpPost, String jsonData) { 199 private String sendPost(HttpPost httpPost, String jsonData) {
199 - CloseableHttpClient httpClient = HttpClients.createDefault(); 200 + RequestConfig requestConfig = RequestConfig.custom()
  201 + .setConnectTimeout(10000)
  202 + .setSocketTimeout(30000)
  203 + .setConnectionRequestTimeout(10000)
  204 + .build();
  205 + CloseableHttpClient httpClient = HttpClients.custom()
  206 + .setDefaultRequestConfig(requestConfig)
  207 + .build();
200 StringEntity entity = new StringEntity(jsonData, ContentType.create("application/json", Consts.UTF_8)); 208 StringEntity entity = new StringEntity(jsonData, ContentType.create("application/json", Consts.UTF_8));
201 httpPost.setEntity(entity); 209 httpPost.setEntity(entity);
202 String result = null; 210 String result = null;
@@ -15,6 +15,7 @@ import org.apache.http.client.methods.CloseableHttpResponse; @@ -15,6 +15,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
15 import org.apache.http.client.methods.HttpPost; 15 import org.apache.http.client.methods.HttpPost;
16 import org.apache.http.entity.ContentType; 16 import org.apache.http.entity.ContentType;
17 import org.apache.http.entity.StringEntity; 17 import org.apache.http.entity.StringEntity;
  18 +import org.apache.http.client.config.RequestConfig;
18 import org.apache.http.impl.client.CloseableHttpClient; 19 import org.apache.http.impl.client.CloseableHttpClient;
19 import org.apache.http.impl.client.HttpClients; 20 import org.apache.http.impl.client.HttpClients;
20 import org.apache.http.message.BasicHeader; 21 import org.apache.http.message.BasicHeader;
@@ -196,7 +197,14 @@ public class WwnjDevicePullService { @@ -196,7 +197,14 @@ public class WwnjDevicePullService {
196 } 197 }
197 198
198 private String sendPost(HttpPost httpPost, String jsonData) { 199 private String sendPost(HttpPost httpPost, String jsonData) {
199 - CloseableHttpClient httpClient = HttpClients.createDefault(); 200 + RequestConfig requestConfig = RequestConfig.custom()
  201 + .setConnectTimeout(10000)
  202 + .setSocketTimeout(30000)
  203 + .setConnectionRequestTimeout(10000)
  204 + .build();
  205 + CloseableHttpClient httpClient = HttpClients.custom()
  206 + .setDefaultRequestConfig(requestConfig)
  207 + .build();
200 StringEntity entity = new StringEntity(jsonData, ContentType.create("application/json", Consts.UTF_8)); 208 StringEntity entity = new StringEntity(jsonData, ContentType.create("application/json", Consts.UTF_8));
201 httpPost.setEntity(entity); 209 httpPost.setEntity(entity);
202 String result = null; 210 String result = null;