|
@@ -29,16 +29,20 @@ public class ZLMRESTfulUtils {
|
|
|
void run(JSONObject response);
|
|
|
}
|
|
|
|
|
|
- private OkHttpClient getClient(){
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private OkHttpClient getClient(Integer timeOut){
|
|
|
+ int timeout = timeOut != null ? timeOut : 5;
|
|
|
+ logger.info("改请求的超时时间为{}",timeout);
|
|
|
if (client == null) {
|
|
|
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
|
|
|
- //todo 暂时写死超时时间 均为5s
|
|
|
- // 设置连接超时时间
|
|
|
- httpClientBuilder.connectTimeout(5,TimeUnit.SECONDS);
|
|
|
- // 设置读取超时时间
|
|
|
- httpClientBuilder.readTimeout(10,TimeUnit.SECONDS);
|
|
|
+ // 设置超时时间
|
|
|
+ httpClientBuilder.connectTimeout(timeout,TimeUnit.SECONDS);
|
|
|
+ // 设置读取超时时间 多添加5秒
|
|
|
+ httpClientBuilder.readTimeout(timeout + 5,TimeUnit.SECONDS);
|
|
|
// 设置连接池
|
|
|
- httpClientBuilder.connectionPool(new ConnectionPool(16, 5, TimeUnit.MINUTES));
|
|
|
+ httpClientBuilder.connectionPool(new ConnectionPool(timeout+5, timeout, TimeUnit.MINUTES));
|
|
|
if (logger.isDebugEnabled()) {
|
|
|
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> {
|
|
|
logger.debug("http请求参数:" + message);
|
|
@@ -54,8 +58,11 @@ public class ZLMRESTfulUtils {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public JSONObject sendPost(MediaServerItem mediaServerItem, String api, Map<String, Object> param, RequestCallback callback) {
|
|
|
- OkHttpClient client = getClient();
|
|
|
+ public JSONObject sendPost(MediaServerItem mediaServerItem, String api, Map<String, Object> param, RequestCallback callback){
|
|
|
+ return sendPost(mediaServerItem,5,api,param,callback);
|
|
|
+ }
|
|
|
+ public JSONObject sendPost(MediaServerItem mediaServerItem,int timeout, String api, Map<String, Object> param, RequestCallback callback) {
|
|
|
+ OkHttpClient client = getClient(timeout);
|
|
|
|
|
|
if (mediaServerItem == null) {
|
|
|
return null;
|
|
@@ -83,15 +90,22 @@ public class ZLMRESTfulUtils {
|
|
|
.url(url)
|
|
|
.build();
|
|
|
if (callback == null) {
|
|
|
+// logger.info("按理来说,这是必然的选择");
|
|
|
try {
|
|
|
Response response = client.newCall(request).execute();
|
|
|
+ logger.error("执行访问zlm请求任务结束");
|
|
|
if (response.isSuccessful()) {
|
|
|
ResponseBody responseBody = response.body();
|
|
|
if (responseBody != null) {
|
|
|
+ logger.error("收到zlm返回值");
|
|
|
String responseStr = responseBody.string();
|
|
|
responseJSON = JSON.parseObject(responseStr);
|
|
|
+ }else{
|
|
|
+ logger.error("未收到zlm返回值");
|
|
|
}
|
|
|
+
|
|
|
}else {
|
|
|
+ logger.error("zlm 请求失败 原因不明 {}",response.message());
|
|
|
response.close();
|
|
|
Objects.requireNonNull(response.body()).close();
|
|
|
}
|
|
@@ -144,9 +158,6 @@ public class ZLMRESTfulUtils {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return responseJSON;
|
|
|
}
|
|
|
|
|
@@ -171,7 +182,7 @@ public class ZLMRESTfulUtils {
|
|
|
.build();
|
|
|
logger.info(request.toString());
|
|
|
try {
|
|
|
- OkHttpClient client = getClient();
|
|
|
+ OkHttpClient client = getClient(5);
|
|
|
Response response = client.newCall(request).execute();
|
|
|
if (response.isSuccessful()) {
|
|
|
if (targetPath != null) {
|
|
@@ -184,7 +195,6 @@ public class ZLMRESTfulUtils {
|
|
|
}
|
|
|
File snapFile = new File(targetPath + File.separator + fileName);
|
|
|
FileOutputStream outStream = new FileOutputStream(snapFile);
|
|
|
-
|
|
|
outStream.write(Objects.requireNonNull(response.body()).bytes());
|
|
|
outStream.flush();
|
|
|
outStream.close();
|
|
@@ -288,8 +298,8 @@ public class ZLMRESTfulUtils {
|
|
|
return sendPost(mediaServerItem, "stopSendRtp",param, null);
|
|
|
}
|
|
|
|
|
|
- public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object> param){
|
|
|
- return sendPost(mediaServerItem,"startSendRtpPassive" , param ,null);
|
|
|
+ public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object> param,int timeout){
|
|
|
+ return sendPost(mediaServerItem,timeout,"startSendRtpPassive" , param ,null);
|
|
|
}
|
|
|
|
|
|
public JSONObject restartServer(MediaServerItem mediaServerItem) {
|