视频流token失效重试
This commit is contained in:
parent
951923b551
commit
1e321145ac
|
@ -41,6 +41,7 @@ import java.awt.image.BufferedImage;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -118,6 +119,8 @@ public class MonitorService {
|
|||
|
||||
static int keepaliveCount = 16;
|
||||
|
||||
private WeakReference<Timer> weakTimer;
|
||||
|
||||
@PostConstruct
|
||||
public CompletableFuture<String> init() {
|
||||
// 不要阻塞程序启动!!屮
|
||||
|
@ -133,6 +136,8 @@ public class MonitorService {
|
|||
|
||||
public String monitorLogin() {
|
||||
|
||||
|
||||
|
||||
String loginUrl = monitorDomain + "/videoService/accounts/authorize";
|
||||
HashMap<String, String> loginParam = new HashMap<>();
|
||||
loginParam.put("userName", userName);
|
||||
|
@ -182,6 +187,8 @@ public class MonitorService {
|
|||
|
||||
MonitorService thatMonitorService = this;
|
||||
|
||||
weakTimer.get().cancel();
|
||||
|
||||
//会话保活
|
||||
Timer timer = new Timer("monitor-capture-keepalive");
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
|
@ -215,8 +222,13 @@ public class MonitorService {
|
|||
|
||||
}
|
||||
}, 0, duration * 1000);
|
||||
|
||||
weakTimer = new WeakReference<Timer>(timer);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
|
@ -772,10 +784,22 @@ public class MonitorService {
|
|||
String url = monitorDomain + "/videoService/realmonitor/uri?scheme=HLS&channelId=" + code;
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("X-Subject-Token", token);
|
||||
int tryCount = 3;
|
||||
while (tryCount-- > 0){
|
||||
try {
|
||||
ResponseEntity<HashMap> forEntity = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity(headers), HashMap.class);
|
||||
HashMap body = forEntity.getBody();
|
||||
String file = (String) body.get("url");
|
||||
return file;
|
||||
}catch (HttpClientErrorException.Unauthorized e){
|
||||
log.error("token失效,重新登录");
|
||||
init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public void videoService(String parentId, String path) throws InterruptedException {
|
||||
|
|
Loading…
Reference in New Issue