|  |  |  | 
|---|
|  |  |  | import org.springframework.boot.web.servlet.ServletRegistrationBean; | 
|---|
|  |  |  | import org.springframework.context.annotation.Bean; | 
|---|
|  |  |  | import org.springframework.context.annotation.Configuration; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  | import org.springframework.util.StringUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.ServletException; | 
|---|
|  |  |  | 
|---|
|  |  |  | String queryStr = super.rewriteQueryStringFromRequest(servletRequest, queryString); | 
|---|
|  |  |  | MediaServerItem mediaInfo = getMediaInfoByUri(servletRequest.getRequestURI()); | 
|---|
|  |  |  | if (mediaInfo != null) { | 
|---|
|  |  |  | if (!StringUtils.isEmpty(queryStr)) { | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(queryStr)) { | 
|---|
|  |  |  | queryStr += "&secret=" + mediaInfo.getSecret(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | queryStr = "secret=" + mediaInfo.getSecret(); | 
|---|
|  |  |  | 
|---|
|  |  |  | MediaServerItem getMediaInfoByUri(String uri){ | 
|---|
|  |  |  | String[] split = uri.split("/"); | 
|---|
|  |  |  | String mediaServerId = split[2]; | 
|---|
|  |  |  | if ("default".equals(mediaServerId)) { | 
|---|
|  |  |  | if ("default".equalsIgnoreCase(mediaServerId)) { | 
|---|
|  |  |  | return mediaServerService.getDefaultMediaServer(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return mediaServerService.getOne(mediaServerId); | 
|---|
|  |  |  | 
|---|
|  |  |  | logger.error("[ZLM服务访问代理],错误:处理url信息时未找到流媒体信息=>{}", requestURI); | 
|---|
|  |  |  | return  url; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!StringUtils.isEmpty(mediaInfo.getId())) { | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(mediaInfo.getId())) { | 
|---|
|  |  |  | url = url.replace(mediaInfo.getId() + "/", ""); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return url.replace("default/", ""); | 
|---|
|  |  |  | 
|---|
|  |  |  | MediaServerItem mediaInfo = getMediaInfoByUri(servletRequest.getRequestURI()); | 
|---|
|  |  |  | String remoteHost = String.format("http://%s:%s", mediaInfo.getIp(), mediaInfo.getHttpPort()); | 
|---|
|  |  |  | if (mediaInfo != null) { | 
|---|
|  |  |  | if (!StringUtils.isEmpty(queryStr)) { | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(queryStr)) { | 
|---|
|  |  |  | queryStr += "&remoteHost=" + remoteHost; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | queryStr = "remoteHost=" + remoteHost; | 
|---|
|  |  |  | 
|---|
|  |  |  | MediaServerItem getMediaInfoByUri(String uri){ | 
|---|
|  |  |  | String[] split = uri.split("/"); | 
|---|
|  |  |  | String mediaServerId = split[2]; | 
|---|
|  |  |  | if ("default".equals(mediaServerId)) { | 
|---|
|  |  |  | if ("default".equalsIgnoreCase(mediaServerId)) { | 
|---|
|  |  |  | return mediaServerService.getDefaultMediaServer(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return mediaServerService.getOne(mediaServerId); | 
|---|
|  |  |  | 
|---|
|  |  |  | logger.error("[录像服务访问代理],错误:处理url信息时未找到流媒体信息=>{}", requestURI); | 
|---|
|  |  |  | return  url; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!StringUtils.isEmpty(mediaInfo.getId())) { | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(mediaInfo.getId())) { | 
|---|
|  |  |  | url = url.replace(mediaInfo.getId() + "/", ""); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return url.replace("default/", ""); | 
|---|