|  |  |  | @ -1,6 +1,11 @@ | 
			
		
	
		
			
				
					|  |  |  |  | package com.gitee.sop.servercommon.interceptor; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import com.alibaba.fastjson.JSONObject; | 
			
		
	
		
			
				
					|  |  |  |  | import com.gitee.sop.servercommon.annotation.Open; | 
			
		
	
		
			
				
					|  |  |  |  | import com.gitee.sop.servercommon.bean.OpenContextImpl; | 
			
		
	
		
			
				
					|  |  |  |  | import com.gitee.sop.servercommon.bean.ServiceContext; | 
			
		
	
		
			
				
					|  |  |  |  | import com.gitee.sop.servercommon.util.OpenUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.web.method.HandlerMethod; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import javax.servlet.http.HttpServletRequest; | 
			
		
	
	
		
			
				
					|  |  |  | @ -16,6 +21,7 @@ public class ServiceContextInterceptor extends HandlerInterceptorAdapter { | 
			
		
	
		
			
				
					|  |  |  |  |         ServiceContext context = ServiceContext.getCurrentContext(); | 
			
		
	
		
			
				
					|  |  |  |  |         context.setRequest(request); | 
			
		
	
		
			
				
					|  |  |  |  |         context.setResponse(response); | 
			
		
	
		
			
				
					|  |  |  |  |         this.initOpenContextWithNoParam(context, request, handler); | 
			
		
	
		
			
				
					|  |  |  |  |         return true; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -23,4 +29,22 @@ public class ServiceContextInterceptor extends HandlerInterceptorAdapter { | 
			
		
	
		
			
				
					|  |  |  |  |     public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { | 
			
		
	
		
			
				
					|  |  |  |  |         ServiceContext.getCurrentContext().unset(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * 修复没有参数的情况下无法获取OpenContext | 
			
		
	
		
			
				
					|  |  |  |  |      * @param context ServiceContext | 
			
		
	
		
			
				
					|  |  |  |  |      * @param request HttpServletRequest | 
			
		
	
		
			
				
					|  |  |  |  |      * @param handler HandlerMethod | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     private void initOpenContextWithNoParam(ServiceContext context, HttpServletRequest request, Object handler) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (handler instanceof HandlerMethod) { | 
			
		
	
		
			
				
					|  |  |  |  |             HandlerMethod handlerMethod = (HandlerMethod) handler; | 
			
		
	
		
			
				
					|  |  |  |  |             Open open = handlerMethod.getMethodAnnotation(Open.class); | 
			
		
	
		
			
				
					|  |  |  |  |             if (open != null && handlerMethod.getMethodParameters().length == 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                 JSONObject requestParams = OpenUtil.getRequestParams(request); | 
			
		
	
		
			
				
					|  |  |  |  |                 OpenContextImpl openContext = new OpenContextImpl(requestParams); | 
			
		
	
		
			
				
					|  |  |  |  |                 context.setOpenContext(openContext); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |