|
@@ -1,19 +1,18 @@
|
|
|
package com.persagy.apm.common.handler;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.persagy.apm.common.constant.AppContextConstants;
|
|
|
-import com.persagy.apm.common.context.AppContext;
|
|
|
-import com.persagy.apm.common.context.DefaultAppContext;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.persagy.apm.common.context.poems.PoemsContext;
|
|
|
-import com.persagy.apm.common.utils.SecureAES;
|
|
|
-import com.persagy.security.exception.AESDecryptException;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
|
|
|
|
+import javax.servlet.ServletInputStream;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @description:
|
|
@@ -24,7 +23,9 @@ import java.io.UnsupportedEncodingException;
|
|
|
*/
|
|
|
public class PoemsContextHandler extends HandlerInterceptorAdapter {
|
|
|
|
|
|
- /** 忽略的url - swagger的文档不校验 */
|
|
|
+ /**
|
|
|
+ * 忽略的url - swagger的文档不校验
|
|
|
+ */
|
|
|
private static final String[] IGNORE_URL = {".html", ".js", ".css", "/swagger-resources"};
|
|
|
|
|
|
@Override
|
|
@@ -33,11 +34,19 @@ public class PoemsContextHandler extends HandlerInterceptorAdapter {
|
|
|
if (StringUtils.containsAny(requestURI, IGNORE_URL)) {
|
|
|
return true;
|
|
|
}
|
|
|
- String userId = request.getParameter("userId");
|
|
|
- String loginDevice = request.getParameter("loginDevice");
|
|
|
- String pd = request.getParameter("pd");
|
|
|
|
|
|
- PoemsContext.setContext(userId, loginDevice, pd);
|
|
|
+ ServletInputStream inputStream = request.getInputStream();
|
|
|
+ String reqBodyStr = IOUtils.toString(inputStream, "utf-8");
|
|
|
+ if (StringUtils.isNotBlank(reqBodyStr)) {
|
|
|
+ //reqBodyStr转为Map对象
|
|
|
+ Map<String, Object> paramMap = new ObjectMapper().readValue(reqBodyStr, new TypeReference<HashMap<String, Object>>() {
|
|
|
+ });
|
|
|
+ String userId = (String) paramMap.get("userId");
|
|
|
+ String loginDevice = (String) paramMap.get("loginDevice");
|
|
|
+ String pd = (String) paramMap.get("pd");
|
|
|
+ PoemsContext.setContext(userId, loginDevice, pd);
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|