Commit 1df4d739 authored by yanghailong's avatar yanghailong

增加debug模式。

parent effd9974
...@@ -6,25 +6,15 @@ import com.iloomo.util.RedisUtil; ...@@ -6,25 +6,15 @@ import com.iloomo.util.RedisUtil;
import com.iloomo.util.Tools; import com.iloomo.util.Tools;
import com.netflix.zuul.ZuulFilter; import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.http.ServletInputStreamWrapper;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StreamUtils;
import javax.annotation.Resource;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.StringUtils;
/** /**
* @author * @author
* @version 1.0 * @version 1.0
...@@ -34,9 +24,10 @@ import org.apache.commons.lang3.StringUtils; ...@@ -34,9 +24,10 @@ import org.apache.commons.lang3.StringUtils;
*/ */
@Component @Component
public class PreFilter extends ZuulFilter { public class PreFilter extends ZuulFilter {
private static String KEY = "KLF7KGtS9eZx7DWQ"; private static String KEY = "KLF7KGtS9eZx7DWQ";
private static String IV = "SRl2wsWc9OV3zzch";
private static String IV = "SRl2wsWc9OV3zzch";
@Override @Override
public String filterType() {//拦截类型设置 public String filterType() {//拦截类型设置
return "pre"; //标准拦截 return "pre"; //标准拦截
...@@ -52,6 +43,8 @@ public class PreFilter extends ZuulFilter { ...@@ -52,6 +43,8 @@ public class PreFilter extends ZuulFilter {
return true; return true;
} }
@org.springframework.beans.factory.annotation.Value("${iloomo.debug}")
private String iloomoDebug;
@Override @Override
public Object run() { public Object run() {
...@@ -78,64 +71,65 @@ public class PreFilter extends ZuulFilter { ...@@ -78,64 +71,65 @@ public class PreFilter extends ZuulFilter {
if (requestQueryParams == null) { if (requestQueryParams == null) {
requestQueryParams = new HashMap<String, List<String>>(); requestQueryParams = new HashMap<String, List<String>>();
} }
if (path.matches(Config.NO_ALL_INTERCEPTOR_PATH)) { if ("false".equals(iloomoDebug)) {
//不需要token和appid if (path.matches(Config.NO_ALL_INTERCEPTOR_PATH)) {
} else { //不需要token和appid
String loomoAppId = pageData.getString("loomoApp_id");
String token = pageData.getString("token");
if (path.matches(Config.NO_APP_ID_INTERCEPTOR_PATH)) {
//不需要app_id的
} else { } else {
if (Tools.notEmpty(loomoAppId)) {//企业后台登录的 String loomoAppId = pageData.getString("loomoApp_id");
String businessId = RedisUtil.get(loomoAppId); String token = pageData.getString("token");
if (businessId == null) { if (path.matches(Config.NO_APP_ID_INTERCEPTOR_PATH)) {
json.put("msg", "非法loomoApp_id"); //不需要app_id的
ctx.setResponseBody(json.toString()); } else {
ctx.setSendZuulResponse(false); if (Tools.notEmpty(loomoAppId)) {//企业后台登录的
String businessId = RedisUtil.get(loomoAppId);
if (businessId == null) {
json.put("msg", "非法loomoApp_id");
ctx.setResponseBody(json.toString());
ctx.setSendZuulResponse(false);
} else {
List<String> appIdArrayList = new ArrayList<String>();
appIdArrayList.add(loomoAppId);
requestQueryParams.put("loomoApp_id", appIdArrayList);
List<String> arrayList = new ArrayList<String>();
arrayList.add(businessId);
requestQueryParams.put("business_id", arrayList);
decode = true;
}
} else if (Tools.notEmpty(token)) {
String userId = RedisUtil.get(token);
if (userId == null) {
json.put("msg", "非法token");
ctx.setResponseBody(json.toString());
ctx.setSendZuulResponse(false);
}
} else { } else {
List<String> appIdArrayList = new ArrayList<String>(); json.put("msg", "非法非法");
appIdArrayList.add(loomoAppId);
requestQueryParams.put("loomoApp_id", appIdArrayList);
List<String> arrayList = new ArrayList<String>();
arrayList.add(businessId);
requestQueryParams.put("business_id", arrayList);
decode = true;
}
}else if(Tools.notEmpty(token)){
String userId = RedisUtil.get(token);
if (userId == null) {
json.put("msg", "非法token");
ctx.setResponseBody(json.toString()); ctx.setResponseBody(json.toString());
ctx.setSendZuulResponse(false); ctx.setSendZuulResponse(false);
} }
} }
else { if (path.matches(Config.NO_TOKEN_INTERCEPTOR_PATH)) {
json.put("msg", "非法非法"); //不需要token的。
ctx.setResponseBody(json.toString()); } else {
ctx.setSendZuulResponse(false); String userIdToken = pageData.getString("token");
} if (Tools.notEmpty(userIdToken)) { //验证token
} String userId = RedisUtil.get(userIdToken);
if (path.matches(Config.NO_TOKEN_INTERCEPTOR_PATH)) { if (userId == null) {
//不需要token的。 json.put("msg", "非法token");
} else { ctx.setResponseBody(json.toString());
String userIdToken = pageData.getString("token"); ctx.setSendZuulResponse(false);
if (Tools.notEmpty(userIdToken)) { //验证token } else {
String userId = RedisUtil.get(userIdToken); decode = true;
if (userId == null) { }
json.put("msg", "非法token"); } else {
json.put("msg", "");
ctx.setResponseBody(json.toString()); ctx.setResponseBody(json.toString());
ctx.setSendZuulResponse(false); ctx.setSendZuulResponse(false);
} else {
decode = true;
} }
} else {
json.put("msg", "");
ctx.setResponseBody(json.toString());
ctx.setSendZuulResponse(false);
} }
}
ctx.setRequestQueryParams(requestQueryParams); ctx.setRequestQueryParams(requestQueryParams);
}
} }
ctx.setRequestQueryParams(requestQueryParams); ctx.setRequestQueryParams(requestQueryParams);
return null; return null;
......
...@@ -137,4 +137,6 @@ hystrix: ...@@ -137,4 +137,6 @@ hystrix:
enabled: true enabled: true
isolation: isolation:
thread: thread:
timeoutInMilliseconds: 10000 timeoutInMilliseconds: 10000
\ No newline at end of file iloomo:
debug: ture
\ No newline at end of file
...@@ -3,7 +3,6 @@ package com.iloomo.util; ...@@ -3,7 +3,6 @@ package com.iloomo.util;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.iloomo.constant.SysConstant; import com.iloomo.constant.SysConstant;
import org.codehaus.jackson.map.util.JSONPObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -109,19 +108,7 @@ public class AppUtil { ...@@ -109,19 +108,7 @@ public class AppUtil {
return listReturn; return listReturn;
} }
/**
* @param pd
* @param map
* @return
*/
public static Object returnObject(PageData pd, Map map){
if(pd.containsKey("callback")){
String callback = pd.get("callback").toString();
return new JSONPObject(callback, map);
}else{
return map;
}
}
public static String getJson(boolean success,Object msg, PageData pageData){ public static String getJson(boolean success,Object msg, PageData pageData){
Map<String,Object> map = new HashMap<String,Object>(); Map<String,Object> map = new HashMap<String,Object>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment