有哈u云台控制接口

结构优化
648540858 2023-09-18 18:19:46 +08:00
parent df0b530ce4
commit 074dbd69a2
2 changed files with 14 additions and 23 deletions

View File

@ -1,12 +1,14 @@
package com.genersoft.iot.vmp.conf; package com.genersoft.iot.vmp.conf;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.HttpRequest; import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.json.JSONObject;
import org.mitre.dsmiley.httpproxy.ProxyServlet; import org.mitre.dsmiley.httpproxy.ProxyServlet;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -26,11 +28,13 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.ConnectException; import java.net.ConnectException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
* zlmassist
* @author lin * @author lin
*/ */
@SuppressWarnings(value = {"rawtypes", "unchecked"}) @SuppressWarnings(value = {"rawtypes", "unchecked"})
@ -84,28 +88,15 @@ public class ProxyServletConfig {
if (servletResponse.getStatus() == HttpServletResponse.SC_OK) { if (servletResponse.getStatus() == HttpServletResponse.SC_OK) {
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
if (entity != null) { if (entity != null) {
if (entity.isChunked()) { InputStream is = entity.getContent();
List<Byte> byteList = new ArrayList<>(); byte[] allBuffer = new byte[(int) entity.getContentLength()];
InputStream is = entity.getContent(); if (is.read(allBuffer) > -1) {
OutputStream os = servletResponse.getOutputStream(); JSONObject jsonObject = JSON.parseObject(allBuffer);
byte[] buffer = new byte[10240]; WVPResult<JSONObject> result = WVPResult.success(jsonObject);
ByteBuffer byteBuffer = new ByteBuffer() byte[] jsonBytes = JSON.toJSONBytes(result);
while(true) {
do {
int read;
if ((read = is.read(buffer)) == -1) {
return;
}
buffer
byteList.addAll(buffer.)
os.write(buffer, 0, read);
} while(!this.doHandleCompression && is.available() != 0);
os.flush();
}
} else {
OutputStream servletOutputStream = servletResponse.getOutputStream(); OutputStream servletOutputStream = servletResponse.getOutputStream();
entity.writeTo(servletOutputStream); servletResponse.setContentLength(jsonBytes.length);
servletOutputStream.write(jsonBytes);
} }
} }
} }

View File

@ -57,7 +57,7 @@ public class PtzController {
@Parameter(name = "horizonSpeed", description = "水平速度", required = true) @Parameter(name = "horizonSpeed", description = "水平速度", required = true)
@Parameter(name = "verticalSpeed", description = "垂直速度", required = true) @Parameter(name = "verticalSpeed", description = "垂直速度", required = true)
@Parameter(name = "zoomSpeed", description = "缩放速度", required = true) @Parameter(name = "zoomSpeed", description = "缩放速度", required = true)
@PostMapping("/control/{deviceId}/{channelId}") @RequestMapping(value = "/control/{deviceId}/{channelId}", method = {RequestMethod.GET, RequestMethod.POST})
public void ptz(@PathVariable String deviceId,@PathVariable String channelId, String command, int horizonSpeed, int verticalSpeed, int zoomSpeed){ public void ptz(@PathVariable String deviceId,@PathVariable String channelId, String command, int horizonSpeed, int verticalSpeed, int zoomSpeed){
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {