CommonConstant.java
2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.huaheng.control.management.utils.constant;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.servlet.http.HttpServletRequest;
public interface CommonConstant {
/** RedisKey:任务信息(前缀) */
public static final String TASK_KEY_PREFIX = "CMC_TASK_INFO:";
/** RedisKey:任务执行顺序 */
public static final String TASK_ORDER_KEY = "CMC_TASK_EXECUTION_ORDER";
/** RedisKey:历史任务信息(前缀) */
public static final String HISTORY_TASK_KEY_PREFIX = "CMC_HISTORY_TASK_INFO:";
/** RedisKey:设备状态信息 */
public static final String EQUIPMENT_STATUS_INFO_KEY = "CMC_EQUIPMENT_STATUS_INFO";
/** 设备运行模式:自动 */
public static final String OPERATION_MODE_AUTO = "AUTO";
/** 设备运行模式:手动 */
public static final String OPERATION_MODE_MANUAL = "MANUAL";
/** 设备ID:WMS */
public static final String EQUIPMENT_ID_WMS = "WMS";
/** 设备ID:WCS */
public static final String EQUIPMENT_ID_WCS = "WCS";
public static final Integer SC_INTERNAL_SERVER_ERROR_500 = Integer.valueOf(500);
public static final Integer SC_OK_200 = Integer.valueOf(200);
public static final Integer SC_NO_AUTHZ = Integer.valueOf(401);
public static String getIpAddr(HttpServletRequest request) {
String 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") || ipAddress.equals("0:0:0:0:0:0:0:1")) {
// 根据网卡取本机配置的IP
InetAddress inet = null;
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
ipAddress = inet.getHostAddress();
}
}
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
// "***.***.***.***".length() = 15
if (ipAddress != null && ipAddress.length() > 15) {
if (ipAddress.indexOf(",") > 0) {
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
}
}
return ipAddress;
}
}