From d7717df0f80aac77eec9ba0345ea7f4487143f75 Mon Sep 17 00:00:00 2001
From: wuxw7 <wuxw7@asiainfo.com>
Date: 星期日, 25 十一月 2018 01:05:24 +0800
Subject: [PATCH] 修改域名bug
---
java110-service/src/main/java/com/java110/service/aop/PageProcessAspect.java | 76 +++++++++++++++++++++++++++++++------
1 files changed, 63 insertions(+), 13 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 eac4f31..66814dd 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,8 +1,11 @@
package com.java110.service.aop;
-import com.java110.common.factory.PageDataFactory;
+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.core.factory.GenerateCodeFactory;
+import com.java110.common.util.StringUtil;
import com.java110.entity.service.PageData;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
@@ -11,9 +14,14 @@
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
+import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.Map;
/**
* 鏁版嵁鍒濆鍖�
@@ -22,7 +30,7 @@
@Aspect
@Component
public class PageProcessAspect {
- @Pointcut("execution(public * com.java110..*.*Controller.*(..))")
+ @Pointcut("execution(public * com.java110..*.*Controller.*(..)) || execution(public * com.java110..*.*Rest.*(..))")
public void dataProcess(){}
/**
@@ -37,8 +45,10 @@
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
+ PageData pd = null;
if("POST".equals(request.getMethod())){
- BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
+ InputStream in = request.getInputStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
//reader.
StringBuffer sb = new StringBuffer();
String str = "";
@@ -47,10 +57,39 @@
}
str = sb.toString();
if(Assert.isPageJsonObject(str)){
- PageData pd = PageDataFactory.newInstance().builder(str).setTransactionId(SequenceUtil.getPageTransactionId());
- request.setAttribute("pd",pd);
+ pd = PageDataFactory.newInstance().builder(str).setTransactionId(GenerateCodeFactory.getPageTransactionId());
}
}
+ //瀵� get鎯呭喌涓嬬殑鍙傛暟杩涜灏佽
+ if(pd == null){
+ pd = PageDataFactory.newInstance().setTransactionId(GenerateCodeFactory.getPageTransactionId());
+ 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){
+ String value = "";
+ 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);
+ }
+ continue;
+ }
+ pd.setParam(paramObj);
+ }
+ }
+
+ 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);
+
+ }
+ request.setAttribute(CommonConstant.CONTEXT_PAGE_DATA,pd);
}
@@ -61,25 +100,36 @@
//鍚庣疆寮傚父閫氱煡
@AfterThrowing("dataProcess()")
- public void throwss(JoinPoint jp){
+ public void throwException(JoinPoint jp){
}
//鍚庣疆鏈�缁堥�氱煡,final澧炲己锛屼笉绠℃槸鎶涘嚭寮傚父鎴栬�呮甯搁��鍑洪兘浼氭墽琛�
@After("dataProcess()")
- public void after(JoinPoint jp){
+ public void after(JoinPoint jp) throws IOException {
// 鎺ユ敹鍒拌姹傦紝璁板綍璇锋眰鍐呭
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
- HttpServletRequest request = attributes.getRequest();
- PageData pd =request.getAttribute("pd") != null ?(PageData)request.getAttribute("pd"):null ;
- //淇濆瓨鏃ュ織澶勭悊
- if(pd != null){
+ HttpServletRequest request = attributes.getRequest();
+ PageData pd =request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA) != null ?(PageData)request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA):null ;
+ //淇濆瓨鏃ュ織澶勭悊
+ if(pd == null){
+ return ;
}
+
+ if(!StringUtil.isNullOrNone(pd.getToken())) {
+ HttpServletResponse response = attributes.getResponse();
+ Cookie cookie = new Cookie(CommonConstant.COOKIE_AUTH_TOKEN, pd.getToken());
+ cookie.setHttpOnly(true);
+ cookie.setPath("/");
+ response.addCookie(cookie);
+ response.flushBuffer();
+ }
+
}
//鐜粫閫氱煡,鐜粫澧炲己锛岀浉褰撲簬MethodInterceptor
@Around("dataProcess()")
- public Object arround(ProceedingJoinPoint pjp) {
+ public Object around(ProceedingJoinPoint pjp) {
try {
Object o = pjp.proceed();
return o;
--
Gitblit v1.8.0