|
|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSON;
|
|
|
import com.xunmei.common.core.constant.Constants;
|
|
|
import com.xunmei.common.core.domain.R;
|
|
|
import com.xunmei.common.core.text.Convert;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.core.io.buffer.DataBuffer;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
@@ -31,6 +32,7 @@ import java.util.*;
|
|
|
*
|
|
|
* @author xunmei
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
public class ServletUtils {
|
|
|
/**
|
|
|
* 获取String参数
|
|
|
@@ -104,8 +106,12 @@ public class ServletUtils {
|
|
|
*/
|
|
|
public static HttpServletRequest getRequest() {
|
|
|
try {
|
|
|
- return getRequestAttributes().getRequest();
|
|
|
+ if (getRequestAttributes() != null) {
|
|
|
+ return getRequestAttributes().getRequest();
|
|
|
+ }
|
|
|
+ return SpringUtil.getBean(HttpServletRequest.class);
|
|
|
} catch (Exception e) {
|
|
|
+ log.error("获取request异常", e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
@@ -115,8 +121,12 @@ public class ServletUtils {
|
|
|
*/
|
|
|
public static HttpServletResponse getResponse() {
|
|
|
try {
|
|
|
- return getRequestAttributes().getResponse();
|
|
|
+ if (getRequestAttributes() != null) {
|
|
|
+ return getRequestAttributes().getResponse();
|
|
|
+ }
|
|
|
+ return SpringUtil.getBean(HttpServletResponse.class);
|
|
|
} catch (Exception e) {
|
|
|
+ log.error("获取response异常", e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|