From 46d1c007db671131c01b0414f8b821f58e1df883 Mon Sep 17 00:00:00 2001 From: Li Haoyu Date: Tue, 7 Jan 2020 10:15:39 +0800 Subject: [PATCH] sun.misc.BASE64Decoder依赖取消, 使用commons-codec.jar 的Base64 --- src/main/java/com/objecteye/controller/HumanVehicleAssociationController.java | 6 +++--- src/main/java/com/objecteye/controller/SpecialtyVehicleController.java | 30 +++++++----------------------- src/main/java/com/objecteye/entity/SyVehicleForbiddenTaskOutput.java | 2 -- src/main/java/com/objecteye/service/SpecialtyServices.java | 19 ------------------- src/main/java/com/objecteye/service/impl/SpecialtyServicesImpl.java | 17 ++--------------- src/main/java/com/objecteye/utils/GlobalUtil.java | 13 ++++++------- src/main/java/com/objecteye/utils/HttpClientUtils.java | 4 +--- src/main/java/com/objecteye/utils/VehicleDetailsUtils.java | 8 +++----- 8 files changed, 22 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/objecteye/controller/HumanVehicleAssociationController.java b/src/main/java/com/objecteye/controller/HumanVehicleAssociationController.java index 76c1997..28d641a 100644 --- a/src/main/java/com/objecteye/controller/HumanVehicleAssociationController.java +++ b/src/main/java/com/objecteye/controller/HumanVehicleAssociationController.java @@ -35,7 +35,7 @@ public class HumanVehicleAssociationController { if (pageResult == null || pageResult.getRow().size() == 0) { return CommonResult.success(201, "没有符合要求的数据", null); } - return CommonResult.success(pageResult, "数据查询成功!!"); + return CommonResult.success(pageResult); } catch (Exception e) { e.printStackTrace(); return CommonResult.failed(); @@ -53,7 +53,7 @@ public class HumanVehicleAssociationController { if (row == null || row.size() == 0) { return CommonResult.success(201, "没有符合要求的数据", searchPeopleOfhphmResult); } - return CommonResult.success(searchPeopleOfhphmResult, "数据查询成功!!"); + return CommonResult.success(searchPeopleOfhphmResult); } catch (Exception e) { e.printStackTrace(); return CommonResult.failed(); @@ -69,7 +69,7 @@ public class HumanVehicleAssociationController { if (faceInfoParam == null || faceInfoParam.size() == 0) { return CommonResult.success(201, "没有符合要求的数据", faceInfoParam); } - return CommonResult.success(faceInfoParam, "数据查询成功!!"); + return CommonResult.success(faceInfoParam); } catch (Exception e) { e.printStackTrace(); return CommonResult.failed(); diff --git a/src/main/java/com/objecteye/controller/SpecialtyVehicleController.java b/src/main/java/com/objecteye/controller/SpecialtyVehicleController.java index d79b9ff..b2bbb39 100644 --- a/src/main/java/com/objecteye/controller/SpecialtyVehicleController.java +++ b/src/main/java/com/objecteye/controller/SpecialtyVehicleController.java @@ -33,8 +33,7 @@ public class SpecialtyVehicleController { @RequestMapping("/slagCar/findByCondition") public JSONObject findByCondition(@RequestBody VehicleCondition vehicleCondition) { //渣土车查询 - JSONObject by = mongoTemplates.findBy(vehicleCondition, 2); - return by; + return mongoTemplates.findBy(vehicleCondition, 2); } @@ -47,8 +46,7 @@ public class SpecialtyVehicleController { @RequestMapping("/slagCar/findCoordinateByPic") public JSONObject siteByPic(@RequestParam("picfile") MultipartFile picfile, Integer vehicle_special_type_number) { //渣土车坐标 vehicle_special_type_number - JSONObject coordinateByPic = specialtyServices.findCoordinateByPic(picfile, vehicle_special_type_number); - return coordinateByPic; + return specialtyServices.findCoordinateByPic(picfile, vehicle_special_type_number); } @@ -72,8 +70,7 @@ public class SpecialtyVehicleController { */ @RequestMapping("/slagCar/findById") public JSONObject findById(@RequestBody Map map) { - JSONObject byPic = specialtyServices.findById(map.get("id")); - return byPic; + return specialtyServices.findById(map.get("id")); } /** @@ -83,15 +80,9 @@ public class SpecialtyVehicleController { */ @RequestMapping("/slagCar/findByGcxh") public JSONObject findByGcxh(int gcxh, MultipartFile picfile) { - JSONObject coordinateByPic = specialtyServices.findByGcxh(gcxh, picfile); - return coordinateByPic; - /* - //老接口 - JSONObject byPic = specialtyServices.findByGcxh1(gcxh, picfile); - return byPic;*/ + return specialtyServices.findByGcxh(gcxh, picfile); } - /** * 危化品车 * 通过车牌(支持模糊)、多条件查询车辆信息(平铺) @@ -101,8 +92,7 @@ public class SpecialtyVehicleController { @RequestMapping("/chemistryCar/findByCondition") public JSONObject chemistryFindByCondition(@RequestBody VehicleCondition vehicleCondition) { //危化品车查询 - JSONObject vehicleInfoRes = mongoTemplates.findBy(vehicleCondition, 1); - return vehicleInfoRes; + return mongoTemplates.findBy(vehicleCondition, 1); } /** @@ -119,7 +109,6 @@ public class SpecialtyVehicleController { } - /** * 测试 * @@ -129,12 +118,10 @@ public class SpecialtyVehicleController { public JSONObject test(Integer gcxh, @RequestParam("picfile") MultipartFile picfile) { - JSONObject coordinateByPic = specialtyServices.findByGcxh(gcxh, picfile); - return coordinateByPic; + return specialtyServices.findByGcxh(gcxh, picfile); } - /** * 测试 * @@ -142,11 +129,8 @@ public class SpecialtyVehicleController { */ @RequestMapping("/getResult") public Object getResult(@RequestBody Map body) { - //CustomAssert.checkHeader(header); CustomAssert.checkField(body, CustomParamCollections.VEHICLE_SINGLE_PARAM); CustomAssert.checkSimpleMapParam(body, CustomParamCollections.VEHICLE_SINGLE_PARAM); - Map colorAndBrand = specialtyServices.getColorAndBrand(body); - - return colorAndBrand; + return specialtyServices.getColorAndBrand(body); } } diff --git a/src/main/java/com/objecteye/entity/SyVehicleForbiddenTaskOutput.java b/src/main/java/com/objecteye/entity/SyVehicleForbiddenTaskOutput.java index cd07207..6724a6d 100644 --- a/src/main/java/com/objecteye/entity/SyVehicleForbiddenTaskOutput.java +++ b/src/main/java/com/objecteye/entity/SyVehicleForbiddenTaskOutput.java @@ -25,8 +25,6 @@ public class SyVehicleForbiddenTaskOutput implements Serializable { private String forbiddenDetailTime; - private String equipment; - private String status; private String warningNumber; diff --git a/src/main/java/com/objecteye/service/SpecialtyServices.java b/src/main/java/com/objecteye/service/SpecialtyServices.java index 3a6bc6f..e6b6902 100644 --- a/src/main/java/com/objecteye/service/SpecialtyServices.java +++ b/src/main/java/com/objecteye/service/SpecialtyServices.java @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject; import com.objecteye.pojo.VehicleCondition; import com.objecteye.pojo.VehicleInfoRes; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile; import java.util.Map; @@ -28,24 +27,6 @@ public interface SpecialtyServices { */ JSONObject findByPic(int number, double threshold, int currentpage, int pagevolume, MultipartFile picfile, Long starttime, Long endtime, Integer vehicle_special_type_number) throws InterruptedException; - - /** - * 危化品车 - * 通过车牌(支持模糊)、多条件查询车辆信息(平铺) - * - * @return - */ - VehicleInfoRes chemistryFindByCondition(VehicleCondition vehicleCondition); - - /** - * 危化品车 - * 通通过车辆特征码、时间、地点范围进行搜索 - * - * @return - */ - @RequestMapping("/chemistryCar/findByPic") - VehicleInfoRes chemistryFindByPic(int number, double threshold, int currentpage, int pagevolume, MultipartFile picfile, String starttime, String endtime); - /** * 通过图片返回每辆车的坐标 * diff --git a/src/main/java/com/objecteye/service/impl/SpecialtyServicesImpl.java b/src/main/java/com/objecteye/service/impl/SpecialtyServicesImpl.java index 9486b80..37ac5e3 100644 --- a/src/main/java/com/objecteye/service/impl/SpecialtyServicesImpl.java +++ b/src/main/java/com/objecteye/service/impl/SpecialtyServicesImpl.java @@ -9,6 +9,7 @@ import com.objecteye.exception.CustomXException; import com.objecteye.pojo.*; import com.objecteye.service.SpecialtyServices; import com.objecteye.utils.*; +import org.apache.commons.codec.binary.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -16,7 +17,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; -import sun.misc.BASE64Decoder; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -184,18 +184,6 @@ public class SpecialtyServicesImpl implements SpecialtyServices { return result; } - @Override - public VehicleInfoRes chemistryFindByCondition(VehicleCondition vehicleCondition) { - - return null; - } - - @Override - public VehicleInfoRes chemistryFindByPic(int number, double threshold, int currentpage, int pagevolume, MultipartFile picfile, String starttime, String endtime) { - - return null; - } - //通过转Base64的方式运行 @Override public JSONObject findCoordinateByPic(MultipartFile picfile, Integer vehicleSpecialTypeNumber) { @@ -322,10 +310,9 @@ public class SpecialtyServicesImpl implements SpecialtyServices { * @param base64String base64码字符串 **/ public BufferedImage changeBase64StringtoImage(String base64String) { - BASE64Decoder decoder = new BASE64Decoder(); BufferedImage buffer = null; try { - byte[] bytes = decoder.decodeBuffer(base64String); + byte[] bytes = Base64.decodeBase64(base64String); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); buffer = ImageIO.read(bais); } catch (IOException e) { diff --git a/src/main/java/com/objecteye/utils/GlobalUtil.java b/src/main/java/com/objecteye/utils/GlobalUtil.java index 156aba2..c35e288 100644 --- a/src/main/java/com/objecteye/utils/GlobalUtil.java +++ b/src/main/java/com/objecteye/utils/GlobalUtil.java @@ -14,7 +14,6 @@ import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.system.ApplicationHome; -import sun.misc.BASE64Decoder; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -30,8 +29,6 @@ import java.util.regex.Pattern; public class GlobalUtil { private static Logger logger = LoggerFactory.getLogger(GlobalUtil.class); - public final static String IPWITHDEPLOYLIST = "IpWithDeployList"; - public final static String EQUIPMENTIPANDID = "equipmentIpAndId"; public final static String PREVIEWIPLISTLIST = "previewIpList"; public final static String ALARMMSG = "alarmMsg"; public final static String DEPLOYIDANDENDTIME = "deployIdAndTime"; @@ -324,12 +321,12 @@ public class GlobalUtil { } public static boolean base64StrToImage(String imgStr, String path) { - if (imgStr == null) + if (imgStr == null) { return false; - BASE64Decoder decoder = new BASE64Decoder(); + } try { // 解密 - byte[] b = decoder.decodeBuffer(imgStr); + byte[] b = org.apache.commons.codec.binary.Base64.decodeBase64(imgStr); // 处理数据 for (int i = 0; i < b.length; ++i) { if (b[i] < 0) { @@ -423,7 +420,9 @@ public class GlobalUtil { e.printStackTrace(); } finally { try { - response.close(); + if (response != null) { + response.close(); + } } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/com/objecteye/utils/HttpClientUtils.java b/src/main/java/com/objecteye/utils/HttpClientUtils.java index 7cf7425..5bd7320 100644 --- a/src/main/java/com/objecteye/utils/HttpClientUtils.java +++ b/src/main/java/com/objecteye/utils/HttpClientUtils.java @@ -7,7 +7,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; -import sun.misc.BASE64Decoder; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -119,10 +118,9 @@ public class HttpClientUtils { * @param base64String base64码字符串 **/ public BufferedImage changeBase64StringtoImage(String base64String) { - BASE64Decoder decoder = new BASE64Decoder(); BufferedImage buffer = null; try { - byte[] bytes = decoder.decodeBuffer(base64String); + byte[] bytes = Base64.decodeBase64(base64String); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); buffer = ImageIO.read(bais); } catch (IOException e) { diff --git a/src/main/java/com/objecteye/utils/VehicleDetailsUtils.java b/src/main/java/com/objecteye/utils/VehicleDetailsUtils.java index c6aed09..af5952f 100644 --- a/src/main/java/com/objecteye/utils/VehicleDetailsUtils.java +++ b/src/main/java/com/objecteye/utils/VehicleDetailsUtils.java @@ -3,9 +3,9 @@ package com.objecteye.utils; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.objecteye.pojo.VehicleDetails; +import org.apache.commons.codec.binary.Base64; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import sun.misc.BASE64Encoder; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -402,20 +402,18 @@ public class VehicleDetailsUtils { * 从全景图中获取到抓拍车辆图的base64 */ public static String picToSnapshot(String url, int left, int top, int width, int height) { - // String path = "http://192.168.10.153:8880/192.168.10.78_01_20190927092803811_FACE_ALARM104.jpg"; String snapshotBase64 = null; ByteArrayOutputStream baos = null; try { URL path = new URL(url); - BufferedImage image = (BufferedImage) ImageIO.read(path); + BufferedImage image = ImageIO.read(path); BufferedImage subimage = image.getSubimage(left, top, width, height); baos = new ByteArrayOutputStream(); ImageIO.write(subimage, "jpg", baos); byte[] bytes = baos.toByteArray(); - BASE64Encoder encoder = new BASE64Encoder(); - String encode = encoder.encode(bytes); + String encode = Base64.encodeBase64String(bytes); snapshotBase64 = "data:image/jpeg;base64," + encode.replaceAll("\n", "").replaceAll("\r", ""); } catch (Exception e) { e.printStackTrace(); -- libgit2 0.21.4