web页面集成
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.mitre.dsmiley.httpproxy.ProxyServlet;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.servlet.Servlet;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 对查询流媒体信息的请求进行反向代理
|
||||
*/
|
||||
@Configuration
|
||||
public class SolrProxyServletConfiguration {
|
||||
|
||||
// 读取配置文件中路由设置
|
||||
@Value("${proxy.servlet_url}")
|
||||
private String servlet_url;
|
||||
// 读取配置中代理目标地址
|
||||
@Value("${proxy.target_url}")
|
||||
private String target_url;
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public Servlet createProxyServlet(){
|
||||
// 创建新的ProxyServlet
|
||||
return new ProxyServlet();
|
||||
}
|
||||
@Bean
|
||||
public ServletRegistrationBean proxyServletRegistration(){
|
||||
ServletRegistrationBean registrationBean = new ServletRegistrationBean(createProxyServlet(), servlet_url);
|
||||
//设置网址以及参数
|
||||
Map<String, String> params = ImmutableMap.of(
|
||||
"targetUri", target_url,
|
||||
"log", "true");
|
||||
registrationBean.setInitParameters(params);
|
||||
return registrationBean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Enumeration;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/zlm")
|
||||
public class ZLMHTTPProxyController {
|
||||
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ZLMHTTPProxyController.class);
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorager storager;
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/**/**/**", produces = "application/json;charset=UTF-8")
|
||||
public Object proxy(HttpServletRequest request, HttpServletResponse response){
|
||||
|
||||
if (storager.getMediaInfo() == null) {
|
||||
return "未接入流媒体";
|
||||
}
|
||||
String requestURI = String.format("http://%s:%s%s?%s&%s",
|
||||
storager.getMediaInfo().getLocalIP(),
|
||||
storager.getMediaInfo().getHttpPort(),
|
||||
request.getRequestURI().replace("/zlm",""),
|
||||
storager.getMediaInfo().getHookAdminParams(),
|
||||
request.getQueryString()
|
||||
);
|
||||
// 发送请求
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
//将指定的url返回的参数自动封装到自定义好的对应类对象中
|
||||
Object result = null;
|
||||
try {
|
||||
result = restTemplate.getForObject(requestURI,Object.class);
|
||||
|
||||
}catch (HttpClientErrorException httpClientErrorException) {
|
||||
response.setStatus(httpClientErrorException.getStatusCode().value());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.utils.IpUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -22,6 +23,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @Description:针对 ZLMediaServer的hook事件监听
|
||||
* @author: swwheihei
|
||||
@@ -267,7 +270,7 @@ public class ZLMHttpHookListener {
|
||||
*/
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_server_started", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onServerStarted(@RequestBody JSONObject json){
|
||||
public ResponseEntity<String> onServerStarted(HttpServletRequest request, @RequestBody JSONObject json){
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_server_started API调用,参数:" + json.toString());
|
||||
|
||||
Reference in New Issue
Block a user