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