|
@@ -3,9 +3,11 @@ package com.qmth.themis.business.util;
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.common.contanst.Constants;
|
|
import com.qmth.themis.common.contanst.Constants;
|
|
import com.qmth.themis.common.enums.ExceptionResultEnum;
|
|
import com.qmth.themis.common.enums.ExceptionResultEnum;
|
|
|
|
+import com.qmth.themis.common.enums.Platform;
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
@@ -57,17 +59,21 @@ public class ServletUtil {
|
|
*
|
|
*
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static String getRequestPlatform() {
|
|
+ public static Platform getRequestPlatform() {
|
|
HttpServletRequest request = getRequest();
|
|
HttpServletRequest request = getRequest();
|
|
|
|
|
|
- String platform = request.getHeader(Constants.HEADER_PLATFORM);
|
|
+ String value = request.getHeader(Constants.HEADER_PLATFORM);
|
|
|
|
|
|
- if (Objects.isNull(platform)) {
|
|
+ if (Objects.isNull(value)) {
|
|
- platform = request.getParameter(Constants.HEADER_PLATFORM);
|
|
+ value = request.getParameter(Constants.HEADER_PLATFORM);
|
|
- if (Objects.isNull(platform)) {
|
|
+ if (Objects.isNull(value)) {
|
|
throw new BusinessException(ExceptionResultEnum.PLATFORM_INVALID);
|
|
throw new BusinessException(ExceptionResultEnum.PLATFORM_INVALID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ Platform platform = Platform.findByName(value);
|
|
|
|
+ if (platform == null) {
|
|
|
|
+ throw new BusinessException(ExceptionResultEnum.PLATFORM_INVALID);
|
|
|
|
+ }
|
|
return platform;
|
|
return platform;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -79,10 +85,10 @@ public class ServletUtil {
|
|
public static String getRequestDeviceId() {
|
|
public static String getRequestDeviceId() {
|
|
HttpServletRequest request = getRequest();
|
|
HttpServletRequest request = getRequest();
|
|
|
|
|
|
- String deviceId = request.getHeader(Constants.HEADER_DEVICE_ID);
|
|
+ String deviceId = StringUtils.trimToNull(request.getHeader(Constants.HEADER_DEVICE_ID));
|
|
|
|
|
|
if (Objects.isNull(deviceId)) {
|
|
if (Objects.isNull(deviceId)) {
|
|
- deviceId = request.getParameter(Constants.HEADER_DEVICE_ID);
|
|
+ deviceId = StringUtils.trimToNull(request.getParameter(Constants.HEADER_DEVICE_ID));
|
|
if (Objects.isNull(deviceId)) {
|
|
if (Objects.isNull(deviceId)) {
|
|
throw new BusinessException(ExceptionResultEnum.DEVICE_ID_INVALID);
|
|
throw new BusinessException(ExceptionResultEnum.DEVICE_ID_INVALID);
|
|
}
|
|
}
|
|
@@ -95,7 +101,7 @@ public class ServletUtil {
|
|
*
|
|
*
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static String getRequestTime() {
|
|
+ public static long getRequestTime() {
|
|
HttpServletRequest request = getRequest();
|
|
HttpServletRequest request = getRequest();
|
|
|
|
|
|
String time = request.getHeader(Constants.HEADER_TIME);
|
|
String time = request.getHeader(Constants.HEADER_TIME);
|
|
@@ -106,7 +112,11 @@ public class ServletUtil {
|
|
throw new BusinessException(ExceptionResultEnum.TIME_INVALID);
|
|
throw new BusinessException(ExceptionResultEnum.TIME_INVALID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return time;
|
|
+ try {
|
|
|
|
+ return Long.parseLong(time);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new BusinessException(ExceptionResultEnum.TIME_INVALID);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -211,7 +221,8 @@ public class ServletUtil {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static HttpServletRequest getRequest() {
|
|
public static HttpServletRequest getRequest() {
|
|
- ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
+ ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
|
|
|
|
+ .getRequestAttributes();
|
|
return servletRequestAttributes.getRequest();
|
|
return servletRequestAttributes.getRequest();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -221,7 +232,8 @@ public class ServletUtil {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static HttpServletResponse getResponse() {
|
|
public static HttpServletResponse getResponse() {
|
|
- ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
+ ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
|
|
|
|
+ .getRequestAttributes();
|
|
return servletRequestAttributes.getResponse();
|
|
return servletRequestAttributes.getResponse();
|
|
}
|
|
}
|
|
|
|
|