From cbc1f9db3d796683d88d6d30df3659984dfbeda3 Mon Sep 17 00:00:00 2001
From: webapp <webapp@home-server.attdns.com>
Date: 星期一, 30 九月 2019 22:56:12 +0800
Subject: [PATCH] 取消java110-common jar包,提升为CommonService服务,将之前的Java110-common内容变更为Java110-utils包
---
java110-service/src/main/java/com/java110/service/aop/PageProcessAspect.java | 153 +++++++++++++++++++++++++++++++++++---------------
1 files changed, 106 insertions(+), 47 deletions(-)
diff --git a/java110-service/src/main/java/com/java110/service/aop/PageProcessAspect.java b/java110-service/src/main/java/com/java110/service/aop/PageProcessAspect.java
index 26b0b19..e26ec42 100644
--- a/java110-service/src/main/java/com/java110/service/aop/PageProcessAspect.java
+++ b/java110-service/src/main/java/com/java110/service/aop/PageProcessAspect.java
@@ -1,15 +1,16 @@
package com.java110.service.aop;
import com.alibaba.fastjson.JSONObject;
-import com.java110.common.constant.CommonConstant;
-import com.java110.core.factory.PageDataFactory;
-import com.java110.common.util.Assert;
-import com.java110.common.util.SequenceUtil;
-import com.java110.common.util.StringUtil;
-import com.java110.entity.service.PageData;
+import com.java110.utils.constant.CommonConstant;
+import com.java110.utils.exception.FilterException;
+import com.java110.core.context.IPageData;
+import com.java110.utils.util.StringUtil;
+import com.java110.core.context.PageData;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -30,8 +31,12 @@
@Aspect
@Component
public class PageProcessAspect {
+
+ private static Logger logger = LoggerFactory.getLogger(PageProcessAspect.class);
+
@Pointcut("execution(public * com.java110..*.*Controller.*(..)) || execution(public * com.java110..*.*Rest.*(..))")
- public void dataProcess(){}
+ public void dataProcess() {
+ }
/**
* 鍒濆鍖栨暟鎹�
@@ -45,8 +50,11 @@
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
- PageData pd = null;
- if("POST".equals(request.getMethod())){
+ IPageData pd = null;
+ String reqData = "";
+ String userId = "";
+ String sessionId = request.getSession().getId();
+ if ("POST,PUT".contains(request.getMethod())) {
InputStream in = request.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
//reader.
@@ -55,41 +63,57 @@
while ((str = reader.readLine()) != null) {
sb.append(str);
}
- str = sb.toString();
- if(Assert.isPageJsonObject(str)){
- pd = PageDataFactory.newInstance().builder(str).setTransactionId(SequenceUtil.getPageTransactionId());
- }
+ reqData = sb.toString();
+
}
//瀵� get鎯呭喌涓嬬殑鍙傛暟杩涜灏佽
- if(pd == null){
- pd = PageDataFactory.newInstance().setTransactionId(SequenceUtil.getPageTransactionId());
- Map<String,String[]> params = request.getParameterMap();
- if(params != null && !params.isEmpty()) {
+ else {
+ Map<String, String[]> params = request.getParameterMap();
+ if (params != null && !params.isEmpty()) {
JSONObject paramObj = new JSONObject();
- for(String key : params.keySet()) {
- if(params.get(key).length>0){
+ for (String key : params.keySet()) {
+ if (params.get(key).length > 0) {
String value = "";
- for(int paramIndex = 0 ; paramIndex < params.get(key).length;paramIndex++) {
+ for (int paramIndex = 0; paramIndex < params.get(key).length; paramIndex++) {
value = params.get(key)[paramIndex] + ",";
}
- value = value.endsWith(",")?value.substring(0,value.length()-1):value;
- paramObj.put(key,value);
+ value = value.endsWith(",") ? value.substring(0, value.length() - 1) : value;
+ paramObj.put(key, value);
}
continue;
}
- pd.setParam(paramObj);
+ reqData = paramObj.toJSONString();
+ }
+ }
+ // 鑾峰彇 userId
+ if (request.getAttribute("claims") != null && request.getAttribute("claims") instanceof Map) {
+ Map<String, String> userInfo = (Map<String, String>) request.getAttribute("claims");
+ if (userInfo.containsKey(CommonConstant.LOGIN_USER_ID)) {
+ userId = userInfo.get(CommonConstant.LOGIN_USER_ID);
}
}
- if(request.getAttribute("claims") != null && request.getAttribute("claims") instanceof Map){
- Map<String,String> userInfo = (Map<String,String>)request.getAttribute("claims");
- if(userInfo.containsKey(CommonConstant.LOGIN_USER_ID)){
- pd.setUserId(userInfo.get(CommonConstant.LOGIN_USER_ID));
- }
- pd.setUserInfo(userInfo);
+ // 鑾峰彇缁勪欢鍚嶇О 鍜屾柟娉曞悕绉�
+ String url = request.getRequestURL() != null ? request.getRequestURL().toString() : "";
+ String componentCode = "";
+ String componentMethod = "";
+ if (url.contains("callComponent")) { //缁勪欢澶勭悊
+ String[] urls = url.split("/");
+ if (urls.length == 6) {
+ componentCode = urls[4];
+ componentMethod = urls[5];
+ }
+ } else if (url.contains("flow")) { //娴佺▼澶勭悊
+ String[] urls = url.split("/");
+
+ if (urls.length == 5) {
+ componentCode = urls[4];
+ }
}
- request.setAttribute(CommonConstant.CONTEXT_PAGE_DATA,pd);
+
+ pd = PageData.newInstance().builder(userId, this.getToken(request), reqData, componentCode, componentMethod, url, sessionId);
+ request.setAttribute(CommonConstant.CONTEXT_PAGE_DATA, pd);
}
@@ -100,7 +124,7 @@
//鍚庣疆寮傚父閫氱煡
@AfterThrowing("dataProcess()")
- public void throwException(JoinPoint jp){
+ public void throwException(JoinPoint jp) {
}
//鍚庣疆鏈�缁堥�氱煡,final澧炲己锛屼笉绠℃槸鎶涘嚭寮傚父鎴栬�呮甯搁��鍑洪兘浼氭墽琛�
@@ -110,13 +134,60 @@
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
- PageData pd =request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA) != null ?(PageData)request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA):null ;
+ PageData pd = request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA) != null ? (PageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA) : null;
//淇濆瓨鏃ュ織澶勭悊
- if(pd == null){
- return ;
+ if (pd == null) {
+ return;
}
- if(!StringUtil.isNullOrNone(pd.getToken())) {
+ //鍐檆ookies淇℃伅
+ writeCookieInfo(pd, attributes);
+
+ }
+
+ //鐜粫閫氱煡,鐜粫澧炲己锛岀浉褰撲簬MethodInterceptor
+ @Around("dataProcess()")
+ public Object around(ProceedingJoinPoint pjp) {
+ try {
+ Object o = pjp.proceed();
+ return o;
+ } catch (Throwable e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+
+ /**
+ * 鑾峰彇TOKEN
+ *
+ * @param request
+ * @return
+ */
+ private String getToken(HttpServletRequest request) throws FilterException {
+ String token = "";
+ if (request.getCookies() == null || request.getCookies().length == 0) {
+ return token;
+ }
+ for (Cookie cookie : request.getCookies()) {
+ if (CommonConstant.COOKIE_AUTH_TOKEN.equals(cookie.getName())) {
+ token = cookie.getValue();
+ }
+ }
+ return token;
+ }
+
+
+ /**
+ * 鍐檆ookie 淇℃伅
+ *
+ * @param pd 椤甸潰灏佽淇℃伅
+ * @param attributes
+ * @throws IOException
+ */
+ private void writeCookieInfo(IPageData pd, ServletRequestAttributes attributes) throws IOException {
+ // 杩欓噷鐩墠鍙啓鍒扮粍浠剁骇鍒紝濡傛灉闇�瑕� 鍐欐垚鏂规硶绾у埆
+ if (!StringUtil.isNullOrNone(pd.getToken()) && "login".equals(pd.getComponentCode())) {
HttpServletResponse response = attributes.getResponse();
Cookie cookie = new Cookie(CommonConstant.COOKIE_AUTH_TOKEN, pd.getToken());
cookie.setHttpOnly(true);
@@ -125,17 +196,5 @@
response.flushBuffer();
}
- }
-
- //鐜粫閫氱煡,鐜粫澧炲己锛岀浉褰撲簬MethodInterceptor
- @Around("dataProcess()")
- public Object around(ProceedingJoinPoint pjp) {
- try {
- Object o = pjp.proceed();
- return o;
- } catch (Throwable e) {
- e.printStackTrace();
- return null;
- }
}
}
--
Gitblit v1.8.0