Showing
7 changed files
with
477 additions
and
4 deletions
| @@ -95,7 +95,11 @@ | @@ -95,7 +95,11 @@ | ||
| 95 | <artifactId>hibernate-validator-annotation-processor</artifactId> | 95 | <artifactId>hibernate-validator-annotation-processor</artifactId> |
| 96 | </dependency> | 96 | </dependency> |
| 97 | 97 | ||
| 98 | - | 98 | + <dependency> |
| 99 | + <groupId>org.apache.httpcomponents</groupId> | ||
| 100 | + <artifactId>httpclient</artifactId> | ||
| 101 | + <version>4.5.14</version> | ||
| 102 | + </dependency> | ||
| 99 | 103 | ||
| 100 | <!--常用库依赖--> | 104 | <!--常用库依赖--> |
| 101 | <dependency> | 105 | <dependency> |
| @@ -59,5 +59,10 @@ public class LiveMonitorRoomController { | @@ -59,5 +59,10 @@ public class LiveMonitorRoomController { | ||
| 59 | return liveMonitorRoomService.delete(id); | 59 | return liveMonitorRoomService.delete(id); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | + @GetMapping("taskDetail") | ||
| 63 | + ResultBean taskDetail(@RequestParam(value = "id",required = true)Long id){ | ||
| 64 | + return liveMonitorRoomService.taskDetail(id); | ||
| 65 | + } | ||
| 66 | + | ||
| 62 | 67 | ||
| 63 | } | 68 | } |
| @@ -23,4 +23,7 @@ public interface LiveMonitorRoomService extends IService<LiveMonitorRoom> { | @@ -23,4 +23,7 @@ public interface LiveMonitorRoomService extends IService<LiveMonitorRoom> { | ||
| 23 | 23 | ||
| 24 | ResultBean delete(Long id); | 24 | ResultBean delete(Long id); |
| 25 | 25 | ||
| 26 | + | ||
| 27 | + ResultBean taskDetail(Long id); | ||
| 28 | + | ||
| 26 | } | 29 | } |
| 1 | package com.wondertek.service.impl; | 1 | package com.wondertek.service.impl; |
| 2 | import java.time.LocalDateTime; | 2 | import java.time.LocalDateTime; |
| 3 | -import java.util.List; | 3 | +import java.util.*; |
| 4 | 4 | ||
| 5 | +import com.alibaba.fastjson.JSON; | ||
| 6 | +import com.alibaba.fastjson.TypeReference; | ||
| 7 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 5 | import com.baomidou.mybatisplus.core.metadata.IPage; | 8 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 6 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 9 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| 7 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 10 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| @@ -13,10 +16,14 @@ import com.wondertek.entity.StreamTask; | @@ -13,10 +16,14 @@ import com.wondertek.entity.StreamTask; | ||
| 13 | import com.wondertek.mapper.LiveMonitorRoomMapper; | 16 | import com.wondertek.mapper.LiveMonitorRoomMapper; |
| 14 | import com.wondertek.service.LiveMonitorRoomService; | 17 | import com.wondertek.service.LiveMonitorRoomService; |
| 15 | import com.wondertek.service.StreamTaskService; | 18 | import com.wondertek.service.StreamTaskService; |
| 19 | +import com.wondertek.util.HttpClientUtils; | ||
| 20 | +import com.wondertek.util.JSONUtils; | ||
| 16 | import com.wondertek.util.PageBean; | 21 | import com.wondertek.util.PageBean; |
| 17 | import com.wondertek.util.ResultBean; | 22 | import com.wondertek.util.ResultBean; |
| 18 | import com.wondertek.vo.LMRoomListVo; | 23 | import com.wondertek.vo.LMRoomListVo; |
| 19 | import jakarta.annotation.Resource; | 24 | import jakarta.annotation.Resource; |
| 25 | +import org.apache.commons.lang3.StringUtils; | ||
| 26 | +import org.springframework.beans.factory.annotation.Value; | ||
| 20 | import org.springframework.stereotype.Service; | 27 | import org.springframework.stereotype.Service; |
| 21 | import org.springframework.util.CollectionUtils; | 28 | import org.springframework.util.CollectionUtils; |
| 22 | 29 | ||
| @@ -29,6 +36,10 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe | @@ -29,6 +36,10 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe | ||
| 29 | @Resource | 36 | @Resource |
| 30 | private StreamTaskService monitorMarkService; | 37 | private StreamTaskService monitorMarkService; |
| 31 | 38 | ||
| 39 | + | ||
| 40 | + @Value("${transcode.getTaskDetail}") | ||
| 41 | + private String getTaskDetail; | ||
| 42 | + | ||
| 32 | @Override | 43 | @Override |
| 33 | public PageBean queryPage(LMRoomDto lmRoomDto) { | 44 | public PageBean queryPage(LMRoomDto lmRoomDto) { |
| 34 | Page<LMRoomListVo> page = new Page<>(lmRoomDto.getPage(), lmRoomDto.getSize()); | 45 | Page<LMRoomListVo> page = new Page<>(lmRoomDto.getPage(), lmRoomDto.getSize()); |
| @@ -100,7 +111,6 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe | @@ -100,7 +111,6 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe | ||
| 100 | StreamTask streamTask = new StreamTask(); | 111 | StreamTask streamTask = new StreamTask(); |
| 101 | streamTask.setTaskId(crpDataVo.getTaskId()); | 112 | streamTask.setTaskId(crpDataVo.getTaskId()); |
| 102 | streamTask.setChannelId(crpDataVo.getChannelId()); | 113 | streamTask.setChannelId(crpDataVo.getChannelId()); |
| 103 | - streamTask.setRoomId(roomId); | ||
| 104 | streamTask.setTaskType(crpDataVo.getTaskType()); | 114 | streamTask.setTaskType(crpDataVo.getTaskType()); |
| 105 | streamTask.setCreatedBy(""); | 115 | streamTask.setCreatedBy(""); |
| 106 | streamTask.setCreatedTime(LocalDateTime.now()); | 116 | streamTask.setCreatedTime(LocalDateTime.now()); |
| @@ -153,4 +163,85 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe | @@ -153,4 +163,85 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe | ||
| 153 | 163 | ||
| 154 | return ResultBean.ok("删除成功"); | 164 | return ResultBean.ok("删除成功"); |
| 155 | } | 165 | } |
| 166 | + | ||
| 167 | + | ||
| 168 | + @Override | ||
| 169 | + public ResultBean taskDetail(Long id) { | ||
| 170 | + | ||
| 171 | + | ||
| 172 | + LiveMonitorRoom monitorRoom = getById(id); | ||
| 173 | + | ||
| 174 | + if(monitorRoom == null){ | ||
| 175 | + return ResultBean.error("房间不存在"); | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + Map<String, Object> result = JSON.parseObject(JSON.toJSONString(monitorRoom), new TypeReference<Map<String, Object>>() { | ||
| 179 | + }); | ||
| 180 | + | ||
| 181 | + | ||
| 182 | + List<Map<String, Object>> streamTaskMapList = new ArrayList<>(); | ||
| 183 | + | ||
| 184 | + | ||
| 185 | + List<StreamTask> taskList = monitorMarkService.list(new QueryWrapper<StreamTask>().eq("room_id", id)); | ||
| 186 | + | ||
| 187 | + if(!CollectionUtils.isEmpty(taskList)){ | ||
| 188 | + for (StreamTask streamTask : taskList) { | ||
| 189 | + String taskId = streamTask.getTaskId(); | ||
| 190 | + String outputDirCheck = streamTask.getOutputDir(); | ||
| 191 | + | ||
| 192 | + Map<String, Object> streamTaskMap = JSON.parseObject(JSON.toJSONString(streamTask), new TypeReference<Map<String, Object>>() { | ||
| 193 | + }); | ||
| 194 | + | ||
| 195 | + String reqUrl = getTaskDetail+"?taskId="+taskId; | ||
| 196 | + String res = HttpClientUtils.executeByGET(reqUrl); | ||
| 197 | + | ||
| 198 | + Map<Object,Object> output = new HashMap<>(); | ||
| 199 | + if(StringUtils.isNotBlank(res)){ | ||
| 200 | + Map<String, Object> resMap = JSON.parseObject(res, new TypeReference<Map<String, Object>>() { | ||
| 201 | + }); | ||
| 202 | + Object returnMessage = resMap.get("returnMessage"); | ||
| 203 | + Object resultCode = resMap.get("resultCode"); | ||
| 204 | + | ||
| 205 | + if(Objects.equals("0",resultCode) && Objects.equals("成功",returnMessage)){ | ||
| 206 | + | ||
| 207 | + if(resMap.get("taskInfo")!=null){ | ||
| 208 | + Map<String, Object> taskInfo = (Map<String, Object>) resMap.get("taskInfo"); | ||
| 209 | + if(taskInfo.get("taskList")!=null){ | ||
| 210 | + List<Map<String, Object>> tasks = (List<Map<String, Object>>) taskInfo.get("taskList"); | ||
| 211 | + | ||
| 212 | + for (Map<String, Object> item : tasks) { | ||
| 213 | + //输出地址 | ||
| 214 | + Object outGroupNo = item.get("outGroupNo"); | ||
| 215 | + List<Map<String, Object>> outputDirList= new ArrayList<>(); | ||
| 216 | + if(item.get("outPutList")!=null){ | ||
| 217 | + List<Map<String, Object>> outPutList = (List<Map<String, Object>>) item.get("outPutList"); | ||
| 218 | + for (Map<String, Object> opmap : outPutList) { | ||
| 219 | + Object outputDir = opmap.get("outputDir"); | ||
| 220 | + Map<String, Object> outputDirMap = new HashMap<>(); | ||
| 221 | + outputDirMap.put("outputDir", outputDir); | ||
| 222 | + outputDirMap.put("checked", false); | ||
| 223 | + if(outputDir.equals(outputDirCheck)){ | ||
| 224 | + outputDirMap.put("checked", true); | ||
| 225 | + } | ||
| 226 | + outputDirList.add(outputDirMap); | ||
| 227 | + } | ||
| 228 | + } | ||
| 229 | + output.put(outGroupNo,outputDirList); | ||
| 230 | + } | ||
| 231 | + } | ||
| 232 | + } | ||
| 233 | + } | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + streamTaskMap.put("output",output); | ||
| 237 | + | ||
| 238 | + streamTaskMapList.add(streamTaskMap); | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + result.put("taskList",streamTaskMapList); | ||
| 244 | + | ||
| 245 | + return ResultBean.ok(result); | ||
| 246 | + } | ||
| 156 | } | 247 | } |
| 1 | +package com.wondertek.util; | ||
| 2 | + | ||
| 3 | +import cn.hutool.http.HttpRequest; | ||
| 4 | +import cn.hutool.http.HttpResponse; | ||
| 5 | +import cn.hutool.http.HttpUtil; | ||
| 6 | +import cn.hutool.json.JSONUtil; | ||
| 7 | +import lombok.extern.slf4j.Slf4j; | ||
| 8 | + | ||
| 9 | +import org.apache.commons.lang3.StringUtils; | ||
| 10 | +import org.apache.http.NameValuePair; | ||
| 11 | +import org.apache.http.client.HttpClient; | ||
| 12 | +import org.apache.http.client.ResponseHandler; | ||
| 13 | +import org.apache.http.client.config.RequestConfig; | ||
| 14 | +import org.apache.http.client.entity.UrlEncodedFormEntity; | ||
| 15 | +import org.apache.http.client.methods.HttpGet; | ||
| 16 | +import org.apache.http.client.methods.HttpPost; | ||
| 17 | +import org.apache.http.impl.client.BasicResponseHandler; | ||
| 18 | +import org.apache.http.impl.client.DefaultHttpClient; | ||
| 19 | +import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; | ||
| 20 | + | ||
| 21 | +import java.nio.charset.Charset; | ||
| 22 | +import java.text.MessageFormat; | ||
| 23 | +import java.util.HashMap; | ||
| 24 | +import java.util.List; | ||
| 25 | +import java.util.Map; | ||
| 26 | +import java.util.concurrent.TimeUnit; | ||
| 27 | + | ||
| 28 | +@SuppressWarnings("deprecation") | ||
| 29 | +@Slf4j | ||
| 30 | +public class HttpClientUtils { | ||
| 31 | + private static HttpClient httpClient = null; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 生产HttpClient实例 | ||
| 35 | + * 公开,静态的工厂方法,需要使用时才去创建该单体 | ||
| 36 | + * | ||
| 37 | + * @return | ||
| 38 | + */ | ||
| 39 | + public static HttpClient getHttpClient() { | ||
| 40 | + if (httpClient == null) { | ||
| 41 | + httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager()); | ||
| 42 | + } | ||
| 43 | + return httpClient; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * POST方式调用 | ||
| 48 | + * | ||
| 49 | + * @param url | ||
| 50 | + * @param obj 参数为实体类对象 | ||
| 51 | + * @return 响应字符串 | ||
| 52 | + * @throws java.io.UnsupportedEncodingException | ||
| 53 | + */ | ||
| 54 | + public static String executeByPOST(String url, Object obj) { | ||
| 55 | + log.info("启动http请求,url:{},发送内容:{}", url, JSONUtil.toJsonStr(obj)); | ||
| 56 | + try { | ||
| 57 | + HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(obj)).timeout(10000).execute(); | ||
| 58 | + if (execute.isOk()) { | ||
| 59 | + String body = execute.body(); | ||
| 60 | + log.info("完成执行http请求,url:{},出参:{}", url, body); | ||
| 61 | + return body; | ||
| 62 | + } else { | ||
| 63 | + log.info("完成执行http请求,url:{},出参:{}", url, execute.body()); | ||
| 64 | + } | ||
| 65 | + } catch (Exception e) { | ||
| 66 | + log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, obj,e.getMessage()); | ||
| 67 | + | ||
| 68 | + } | ||
| 69 | + return null; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * POST方式调用 | ||
| 75 | + * | ||
| 76 | + * @param url | ||
| 77 | + * @param obj 参数为实体类对象 | ||
| 78 | + * @return 响应字符串 | ||
| 79 | + * @throws java.io.UnsupportedEncodingException | ||
| 80 | + */ | ||
| 81 | + public static String executeByPOST(String url, String obj) { | ||
| 82 | + log.info("启动http请求,url:{},发送内容:{}", url, obj); | ||
| 83 | + try { | ||
| 84 | + HttpResponse execute = HttpRequest.post(url).body(obj).timeout(10000).execute(); | ||
| 85 | + if (execute.isOk()) { | ||
| 86 | + String body = execute.body(); | ||
| 87 | + log.info("完成执行http请求,url:{},出参:{}", url, body); | ||
| 88 | + return body; | ||
| 89 | + } else { | ||
| 90 | + log.info("完成执行http请求,url:{},出参:{}", url, execute.body()); | ||
| 91 | + } | ||
| 92 | + } catch (Exception e) { | ||
| 93 | + log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, obj,e.getMessage()); | ||
| 94 | + } | ||
| 95 | + return null; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public static Map<String,String> executeByPOST(String info,String url, String obj) { | ||
| 99 | + log.info(info+"===>启动http请求,url:{},发送内容:{}", url, obj); | ||
| 100 | + Map<String,String> resMap= new HashMap<>(); | ||
| 101 | + try { | ||
| 102 | + HttpResponse execute = HttpRequest.post(url).body(obj).timeout(10000).execute(); | ||
| 103 | + if (execute.isOk()) { | ||
| 104 | + String body = execute.body(); | ||
| 105 | + log.info(info+"===>完成执行http请求,url:{},出参:{}", url, body); | ||
| 106 | + resMap.put("data",body); | ||
| 107 | + resMap.put("code","200"); | ||
| 108 | + } else { | ||
| 109 | + log.info(info+"===>完成执行http请求,url:{},出参:{}", url, execute.body()); | ||
| 110 | + resMap.put("data",execute.body()); | ||
| 111 | + resMap.put("code","500"); | ||
| 112 | + } | ||
| 113 | + } catch (Exception e) { | ||
| 114 | + log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, obj,e.getMessage()); | ||
| 115 | + } | ||
| 116 | + return null; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + public static String executeByPUT(String url, String obj) { | ||
| 120 | + log.info("启动http请求,url:{},发送内容:{}", url, obj); | ||
| 121 | + try { | ||
| 122 | + HttpResponse execute = HttpRequest.put(url).body(obj).timeout(10000).execute(); | ||
| 123 | + if (execute.isOk()) { | ||
| 124 | + String body = execute.body(); | ||
| 125 | + log.info("完成执行http请求,url:{},出参:{}", url, body); | ||
| 126 | + return body; | ||
| 127 | + } else { | ||
| 128 | + log.info("完成执行http请求,url:{},出参:{}", url, execute.body()); | ||
| 129 | + } | ||
| 130 | + } catch (Exception e) { | ||
| 131 | + log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, obj,e.getMessage()); | ||
| 132 | + } | ||
| 133 | + return null; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public static String executeByDELETE(String url, String obj) { | ||
| 137 | + log.info("启动http请求,url:{},发送内容:{}", url, obj); | ||
| 138 | + try { | ||
| 139 | + HttpResponse execute = HttpRequest.delete(url).body(obj).timeout(10000).execute(); | ||
| 140 | + if (execute.isOk()) { | ||
| 141 | + String body = execute.body(); | ||
| 142 | + log.info("完成执行http请求,url:{},出参:{}", url, body); | ||
| 143 | + return body; | ||
| 144 | + } else { | ||
| 145 | + log.info("完成执行http请求,url:{},出参:{}", url, execute.body()); | ||
| 146 | + } | ||
| 147 | + } catch (Exception e) { | ||
| 148 | + log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, obj,e.getMessage()); | ||
| 149 | + } | ||
| 150 | + return null; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + | ||
| 154 | + /** | ||
| 155 | + * POST方式调用 | ||
| 156 | + * | ||
| 157 | + * @param url | ||
| 158 | + * @param params 参数为NameValuePair键值对对象 | ||
| 159 | + * @return 响应字符串 | ||
| 160 | + * @throws java.io.UnsupportedEncodingException | ||
| 161 | + */ | ||
| 162 | + public static String executeByPOST(String url, List<NameValuePair> params) { | ||
| 163 | + HttpClient httpclient = getHttpClient(); | ||
| 164 | + | ||
| 165 | + HttpPost post = new HttpPost(url); | ||
| 166 | + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(180000).build(); | ||
| 167 | + post.setConfig(requestConfig); | ||
| 168 | + | ||
| 169 | + ResponseHandler<String> responseHandler = new BasicResponseHandler(); | ||
| 170 | + String responseJson = null; | ||
| 171 | + try { | ||
| 172 | + if (params != null) { | ||
| 173 | + post.setEntity(new UrlEncodedFormEntity(params)); | ||
| 174 | + } | ||
| 175 | + responseJson = httpclient.execute(post, responseHandler); | ||
| 176 | + log.info("HttpClient POST请求结果:" + responseJson); | ||
| 177 | + } catch (Exception e) { | ||
| 178 | + log.info("HttpClient POST请求异常:" + e.getMessage()); | ||
| 179 | + } finally { | ||
| 180 | + httpclient.getConnectionManager().closeExpiredConnections(); | ||
| 181 | + httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS); | ||
| 182 | + } | ||
| 183 | + return responseJson; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + | ||
| 187 | + /** | ||
| 188 | + * POST方式调用 | ||
| 189 | + * | ||
| 190 | + * @param url | ||
| 191 | + * @param xml 请求Json字符串 | ||
| 192 | + * @param headerMap 自定义头 | ||
| 193 | + * @return 响应字符串 | ||
| 194 | + * @throws java.io.UnsupportedEncodingException | ||
| 195 | + */ | ||
| 196 | + public static String executeByPOST(String url, String xml, Map<String,String> headerMap) { | ||
| 197 | + log.info("启动http请求,url:{},发送内容:{},请求头:{}", url, xml, JSONUtil.toJsonStr(headerMap)); | ||
| 198 | + try { | ||
| 199 | + HttpRequest request = HttpRequest.post(url); | ||
| 200 | + if(null != headerMap) { | ||
| 201 | + request.headerMap(headerMap, true); | ||
| 202 | + } | ||
| 203 | + HttpResponse execute = request.body(xml).timeout(10000).execute(); | ||
| 204 | + String body = execute.body(); | ||
| 205 | + log.info("完成执行http请求,url:{},出参:{}", url, body); | ||
| 206 | + return body; | ||
| 207 | + } catch (Exception e) { | ||
| 208 | + log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, xml,e.getMessage()); | ||
| 209 | + throw e; | ||
| 210 | + } | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + public static String executeByGET(String url, Object[] params) { | ||
| 214 | + HttpClient httpclient = getHttpClient(); | ||
| 215 | + | ||
| 216 | + String messages = MessageFormat.format(url, params); | ||
| 217 | + | ||
| 218 | + HttpGet get = new HttpGet(messages); | ||
| 219 | + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(180000).build(); | ||
| 220 | + get.setConfig(requestConfig); | ||
| 221 | + ResponseHandler<String> responseHandler = new BasicResponseHandler(); | ||
| 222 | + String responseJson = null; | ||
| 223 | + try { | ||
| 224 | + responseJson = httpclient.execute(get, responseHandler); | ||
| 225 | + } catch (Exception e) { | ||
| 226 | + log.info("HttpClient GET请求异常,url:{},error:{}", messages, e.getMessage()); | ||
| 227 | + } finally { | ||
| 228 | + httpclient.getConnectionManager().closeExpiredConnections(); | ||
| 229 | + httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS); | ||
| 230 | + } | ||
| 231 | + return responseJson; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + | ||
| 235 | + | ||
| 236 | + public static String executeByGET(String url) { | ||
| 237 | + | ||
| 238 | + String responseBody = null; | ||
| 239 | + try { | ||
| 240 | + log.info(">>>HTTP get请求,请求URL:" + url); | ||
| 241 | + HttpRequest httpGet = HttpUtil.createGet(url); | ||
| 242 | + httpGet.setConnectionTimeout(2000).setReadTimeout(5000); | ||
| 243 | + HttpResponse response = httpGet.execute(); | ||
| 244 | + response.charset(Charset.defaultCharset()); | ||
| 245 | + if (response.isOk()) { | ||
| 246 | + responseBody = response.body(); | ||
| 247 | + if (StringUtils.isNotBlank(responseBody)) { | ||
| 248 | + log.info(">>>HTTP get请求,请求成功" + ",请求结果长度:" + responseBody.length()); | ||
| 249 | + } | ||
| 250 | + } | ||
| 251 | + } catch (Exception e) { | ||
| 252 | + log.warn("HTTP get请求URL:" + url + ",请求异常:" + e.getMessage()); | ||
| 253 | + } | ||
| 254 | + return responseBody; | ||
| 255 | + | ||
| 256 | + /* | ||
| 257 | + * HttpClient httpclient = getHttpClient(); | ||
| 258 | + * | ||
| 259 | + * HttpParams params = httpClient.getParams(); | ||
| 260 | + * params.setParameter(ClientPNames.HANDLE_REDIRECTS, false); | ||
| 261 | + * | ||
| 262 | + * HttpGet get = new HttpGet(url); | ||
| 263 | + * RequestConfig requestConfig = | ||
| 264 | + * RequestConfig.custom().setConnectTimeout(2000).setSocketTimeout(5000).build() | ||
| 265 | + * ; | ||
| 266 | + * get.setConfig(requestConfig); | ||
| 267 | + * ResponseHandler<String> responseHandler = new BasicResponseHandler(); | ||
| 268 | + * String responseJson = null; | ||
| 269 | + * try { | ||
| 270 | + * responseJson = httpclient.execute(get, responseHandler); | ||
| 271 | + * log.info(">>>HttpClient请求URL:"+url+ ",请求结果长度:"+ responseJson.length()); | ||
| 272 | + * } catch (Exception e) { | ||
| 273 | + * log.warn("HttpClient请求URL:"+url+",请求异常:" + e.getMessage()); | ||
| 274 | + * } finally { | ||
| 275 | + * httpclient.getConnectionManager().closeExpiredConnections(); | ||
| 276 | + * httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS); | ||
| 277 | + * } | ||
| 278 | + * return responseJson; | ||
| 279 | + */ | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + /** 仅限用于get请求,传递媒资id列表,其他格式未必适合 | ||
| 283 | + * get请求传参,传入url和list数组 | ||
| 284 | + * 如:http://localhost:8920/oes-csas-manage/es-operate/sync5?assetIds=20210261500049,20210261500053 | ||
| 285 | + * @Param [url, assetIdList] | ||
| 286 | + * @return java.lang.String | ||
| 287 | + **/ | ||
| 288 | + public static String executeByGET(String url, List<Long> assetIdList) { | ||
| 289 | + HttpClient httpclient = getHttpClient(); | ||
| 290 | + StringBuilder buffer = new StringBuilder(); | ||
| 291 | + for (Long assetId : assetIdList) { | ||
| 292 | + buffer.append(assetId).append(","); | ||
| 293 | + } | ||
| 294 | + String substring = buffer.substring(0, buffer.length()-1); | ||
| 295 | +// String messages = MessageFormat.format(url, substring); | ||
| 296 | + String messages = url+substring; | ||
| 297 | + log.info("get请求 messages = " + messages); | ||
| 298 | + HttpGet get = new HttpGet(messages); | ||
| 299 | + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(180000).build(); | ||
| 300 | + get.setConfig(requestConfig); | ||
| 301 | + ResponseHandler<String> responseHandler = new BasicResponseHandler(); | ||
| 302 | + String responseJson = null; | ||
| 303 | + try { | ||
| 304 | + responseJson = httpclient.execute(get, responseHandler); | ||
| 305 | + } catch (Exception e) { | ||
| 306 | + log.info("HttpClient GET请求异常:" + e.getMessage()); | ||
| 307 | + } finally { | ||
| 308 | + httpclient.getConnectionManager().closeExpiredConnections(); | ||
| 309 | + httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS); | ||
| 310 | + } | ||
| 311 | + return responseJson; | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + /** | ||
| 315 | + * 带cookie的get请求 | ||
| 316 | + * | ||
| 317 | + * @param url 请求路径 | ||
| 318 | + * @param cookie cookie | ||
| 319 | + * @return 请求结果 | ||
| 320 | + */ | ||
| 321 | + public static String executeByGET(String url, String cookie) { | ||
| 322 | + | ||
| 323 | + String responseBody = null; | ||
| 324 | + try { | ||
| 325 | + log.info(">>>带cookie的HTTP请求,请求URL:" + url); | ||
| 326 | + HttpRequest httpGet = HttpUtil.createGet(url); | ||
| 327 | + httpGet.cookie(cookie); | ||
| 328 | + httpGet.setConnectionTimeout(2000).setReadTimeout(5000); | ||
| 329 | + HttpResponse response = httpGet.execute(); | ||
| 330 | + response.charset(Charset.defaultCharset()); | ||
| 331 | + if (response.isOk()) { | ||
| 332 | + responseBody = response.body(); | ||
| 333 | + if (StringUtils.isNotBlank(responseBody)) { | ||
| 334 | + log.info(">>>带cookie的HTTP请求,请求成功" + ",请求结果长度:" + responseBody.length()); | ||
| 335 | + } | ||
| 336 | + } | ||
| 337 | + } catch (Exception e) { | ||
| 338 | + log.warn("HttpClient请求URL:" + url + ",请求异常:" + e.getMessage()); | ||
| 339 | + } | ||
| 340 | + return responseBody; | ||
| 341 | + | ||
| 342 | + /* | ||
| 343 | + * HttpClient httpclient = getHttpClient(); | ||
| 344 | + * | ||
| 345 | + * HttpParams params = httpClient.getParams(); | ||
| 346 | + * params.setParameter(ClientPNames.HANDLE_REDIRECTS, false); | ||
| 347 | + * | ||
| 348 | + * HttpGet get = new HttpGet(url); | ||
| 349 | + * RequestConfig requestConfig = | ||
| 350 | + * RequestConfig.custom().setConnectTimeout(2000).setSocketTimeout(5000).build() | ||
| 351 | + * ; | ||
| 352 | + * get.setConfig(requestConfig); | ||
| 353 | + * ResponseHandler<String> responseHandler = new BasicResponseHandler(); | ||
| 354 | + * String responseJson = null; | ||
| 355 | + * try { | ||
| 356 | + * get.setHeader("Cookie",cookie); | ||
| 357 | + * responseJson = httpclient.execute(get, responseHandler); | ||
| 358 | + * log.info(">>>HttpClient请求URL:"+url+ ",请求结果长度:"+ responseJson.length()); | ||
| 359 | + * } catch (Exception e) { | ||
| 360 | + * log.warn("HttpClient请求URL:"+url+",请求异常:" + e.getMessage()); | ||
| 361 | + * } finally { | ||
| 362 | + * httpclient.getConnectionManager().closeExpiredConnections(); | ||
| 363 | + * httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS); | ||
| 364 | + * } | ||
| 365 | + * return responseJson; | ||
| 366 | + */ | ||
| 367 | + } | ||
| 368 | + | ||
| 369 | +} |
| @@ -61,6 +61,7 @@ mybatis-plus: | @@ -61,6 +61,7 @@ mybatis-plus: | ||
| 61 | 61 | ||
| 62 | transcode: | 62 | transcode: |
| 63 | delayTimeUrl: http://192.168.1.41:8080/transcode/delayTime # 延迟接口 | 63 | delayTimeUrl: http://192.168.1.41:8080/transcode/delayTime # 延迟接口 |
| 64 | + getTaskDetail: http://192.168.1.237:9002/api/v1/getTaskDetail | ||
| 64 | 65 | ||
| 65 | crp: | 66 | crp: |
| 66 | log: | 67 | log: |
| @@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
| 15 | `mix_output_url`, | 15 | `mix_output_url`, |
| 16 | `live_name` | 16 | `live_name` |
| 17 | FROM | 17 | FROM |
| 18 | - crp_live_monitor_room` | 18 | + `crp_live_monitor_room` |
| 19 | <where> | 19 | <where> |
| 20 | `del`=0 | 20 | `del`=0 |
| 21 | <if test="dto.name != null and dto.name != ''"> | 21 | <if test="dto.name != null and dto.name != ''"> |
-
Please register or login to post a comment