IP record, upgrade
							parent
							
								
									f55645e9cc
								
							
						
					
					
						commit
						ccd206bb24
					
				|  | @ -10,6 +10,17 @@ import javax.servlet.http.HttpServletRequest; | |||
| public abstract class WebUtils { | ||||
| 
 | ||||
| 
 | ||||
|     private static ThreadLocal<String> ipThreadLocal = new ThreadLocal<>(); | ||||
| 
 | ||||
| 
 | ||||
|     public static void setIp(String ip) { | ||||
|         ipThreadLocal.set(ip); | ||||
|     } | ||||
| 
 | ||||
|     public static String getIp() { | ||||
|         return ipThreadLocal.get(); | ||||
|     } | ||||
| 
 | ||||
|     //private
 | ||||
|     private WebUtils() { | ||||
|     } | ||||
|  | @ -36,7 +47,7 @@ public abstract class WebUtils { | |||
|     } | ||||
| 
 | ||||
|     private static boolean isUnAvailableIp(String ip) { | ||||
|         return (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)); | ||||
|         return StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | @ -25,7 +25,7 @@ public class MobileController { | |||
| 
 | ||||
|     @RequestMapping("user_info") | ||||
|     @ResponseBody | ||||
|     public UserJsonDto userInfo() throws Exception { | ||||
|     public UserJsonDto userInfo() { | ||||
|         return userService.loadCurrentUserJsonDto(); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -26,7 +26,7 @@ public class UnityController { | |||
| 
 | ||||
|     @RequestMapping("user_info") | ||||
|     @ResponseBody | ||||
|     public UserJsonDto userInfo() throws Exception { | ||||
|     public UserJsonDto userInfo() { | ||||
|         return userService.loadCurrentUserJsonDto(); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,35 @@ | |||
| package com.monkeyk.sos.web.filter; | ||||
| 
 | ||||
| import com.monkeyk.sos.web.WebUtils; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import org.springframework.web.filter.CharacterEncodingFilter; | ||||
| 
 | ||||
| import javax.servlet.FilterChain; | ||||
| import javax.servlet.ServletException; | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| import java.io.IOException; | ||||
| 
 | ||||
| /** | ||||
|  * 2016/1/30 | ||||
|  * | ||||
|  * @author Shengzhao Li | ||||
|  */ | ||||
| public class CharacterEncodingIPFilter extends CharacterEncodingFilter { | ||||
| 
 | ||||
|     private static final Logger LOG = LoggerFactory.getLogger(CharacterEncodingIPFilter.class); | ||||
| 
 | ||||
| 
 | ||||
|     @Override | ||||
|     protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { | ||||
|         recordIP(request); | ||||
|         super.doFilterInternal(request, response, filterChain); | ||||
|     } | ||||
| 
 | ||||
|     private void recordIP(HttpServletRequest request) { | ||||
|         final String ip = WebUtils.retrieveClientIp(request); | ||||
|         WebUtils.setIp(ip); | ||||
|         LOG.debug("Send request uri: {}, from IP: {}", request.getRequestURI(), ip); | ||||
|     } | ||||
| } | ||||
|  | @ -16,7 +16,7 @@ | |||
|     <!--Encoding filter--> | ||||
|     <filter> | ||||
|         <filter-name>encodingFilter</filter-name> | ||||
|         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> | ||||
|         <filter-class>com.monkeyk.sos.web.filter.CharacterEncodingIPFilter</filter-class> | ||||
|         <init-param> | ||||
|             <param-name>encoding</param-name> | ||||
|             <param-value>UTF-8</param-value> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Li Shengzhao
						Li Shengzhao