异常情况打印信息优化

This commit is contained in:
648540858
2022-09-23 23:08:58 +08:00
parent cd117ed228
commit 4c6c77be7a
26 changed files with 44 additions and 352 deletions

View File

@@ -17,49 +17,6 @@ public class GpsUtil {
public static BaiduPoint Wgs84ToBd09(String xx, String yy) {
// try {
// Socket s = new Socket("api.map.baidu.com", 80);
// BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream(), "UTF-8"));
// OutputStream out = s.getOutputStream();
// StringBuffer sb = new StringBuffer("GET /ag/coord/convert?from=0&to=4");
// sb.append("&x=" + xx + "&y=" + yy);
// sb.append("&callback=BMap.Convertor.cbk_3976 HTTP/1.1\r\n");
// sb.append("User-Agent: Java/1.6.0_20\r\n");
// sb.append("Host: api.map.baidu.com:80\r\n");
// sb.append("Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n");
// sb.append("Connection: Close\r\n");
// sb.append("\r\n");
// out.write(sb.toString().getBytes());
// String json = "";
// String tmp = "";
// while ((tmp = br.readLine()) != null) {
// // logger.info(tmp);
// json += tmp;
// }
//
// s.close();
// int start = json.indexOf("cbk_3976");
// int end = json.lastIndexOf("}");
// if (start != -1 && end != -1 && json.contains("\"x\":\"")) {
// json = json.substring(start, end);
// String[] point = json.split(",");
// String x = point[1].split(":")[1].replace("\"", "");
// String y = point[2].split(":")[1].replace("\"", "");
// BaiduPoint bdPoint= new BaiduPoint();
// bdPoint.setBdLng(new String(decode(x)));
// bdPoint.setBdLat(new String(decode(y)));
// return bdPoint;
// //return (new String(decode(x)) + "," + new String(decode(y)));
// } else {
// logger.info("gps坐标无效");
// }
// out.close();
// br.close();
// } catch (Exception e) {
// e.printStackTrace();
// }
double lng = Double.parseDouble(xx);
double lat = Double.parseDouble(yy);
Double[] gcj02 = Coordtransform.WGS84ToGCJ02(lng, lat);

View File

@@ -1,48 +0,0 @@
package com.genersoft.iot.vmp.utils;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class IpUtil {
public static String getIpAddr(HttpServletRequest request) {
String ipAddress = null;
try {
ipAddress = request.getHeader("x-forwarded-for");
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
if (ipAddress.equals("127.0.0.1")) {
// 根据网卡取本机配置的IP
InetAddress inet = null;
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
ipAddress = inet.getHostAddress();
}
}
// 对于通过多个代理的情况第一个IP为客户端真实IP,多个IP按照','分割
if (ipAddress != null && ipAddress.length() > 15) { // "***.***.***.***".length()
// = 15
if (ipAddress.indexOf(",") > 0) {
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
}
}
} catch (Exception e) {
ipAddress="";
}
// ipAddress = this.getRequest().getRemoteAddr();
return ipAddress;
}
}

View File

@@ -1,73 +0,0 @@
package com.genersoft.iot.vmp.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
/**
* 一个优秀的颓废程序猿
*/
@Component
public class JarFileUtils {
private static Logger log = LoggerFactory.getLogger(JarFileUtils.class);
private static Map<String, String> map = new HashMap<>();
public Map<String, String> readJarFile() {
JarFile jarFile = null;
BufferedReader br = null;
try {
// 获取jar的运行路径因linux下jar的路径为”file:/app/.../test.jar!/BOOT-INF/class!/“这种格式所以需要去掉”file:“和”!/BOOT-INF/class!/“
String jarFilePath = ClassUtils.getDefaultClassLoader().getResource("").getPath().replace("!/BOOT-INF/classes!/", "");
if (jarFilePath.startsWith("file")) {
jarFilePath = jarFilePath.substring(5);
}
log.debug("jarFilePath:" + jarFilePath);
// 通过JarFile的getJarEntry方法读取META-INF/MANIFEST.MF
jarFile = new JarFile(jarFilePath);
JarEntry entry = jarFile.getJarEntry("META-INF/MANIFEST.MF");
log.info("读取的内容:" + entry.toString());
// 如果读取到MANIFEST.MF文件内容则转换为string
if (entry != null) {
InputStream in = jarFile.getInputStream(entry);
StringBuilder sb = new StringBuilder();
br = new BufferedReader(new InputStreamReader(in));
String line = "";
while ((line = br.readLine()) != null) {
if (line != null && line.contains(":")) {
int index = line.indexOf(":");
map.put(line.substring(0, index).trim(), line.substring(index + 1, line.length()).trim());
}
}
return map;
}
} catch (IOException e) {
log.debug("读取MANIFEST.MF文件异常:" + e.getMessage());
} finally {
try {
if (null != br) {
br.close();
}
if (null != jarFile) {
jarFile.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return map;
}
}

View File

@@ -1,31 +0,0 @@
package com.genersoft.iot.vmp.utils;
import java.io.*;
public class SerializeUtils {
public static byte[] serialize(Object obj){
byte[] bytes = null;
try {
ByteArrayOutputStream baos=new ByteArrayOutputStream();;
ObjectOutputStream oos=new ObjectOutputStream(baos);
oos.writeObject(obj);
bytes=baos.toByteArray();
baos.close();
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
return bytes;
}
public static Object deSerialize(byte[] bytes){
Object obj=null;
try {
ByteArrayInputStream bais=new ByteArrayInputStream(bytes);
ObjectInputStream ois=new ObjectInputStream(bais);
obj=ois.readObject();
} catch (Exception e) {
e.printStackTrace();
}
return obj;
}
}