Commit 0656edcf authored by 技术部-任文超's avatar 技术部-任文超
parents 6b945e53 bae2a1c5
package cn.quantgroup.xyqb.config.web; package cn.quantgroup.xyqb.config.web;
import cn.quantgroup.xyqb.interceptors.ChannelIdInterceptor;
import cn.quantgroup.xyqb.interceptors.IPWhiteListInterceptor; import cn.quantgroup.xyqb.interceptors.IPWhiteListInterceptor;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -13,12 +12,11 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter ...@@ -13,12 +12,11 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@Configuration @Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter { public class InterceptorConfig extends WebMvcConfigurerAdapter {
@Value("${configserver.disable}") @Value("${configserver.disable}")
private Integer isDebug; private Integer isDebug;
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new IPWhiteListInterceptor(isDebug)).addPathPatterns("/innerapi/**"); registry.addInterceptor(new IPWhiteListInterceptor(isDebug)).addPathPatterns("/innerapi/**");
registry.addInterceptor(new ChannelIdInterceptor()).addPathPatterns("/**"); }
}
} }
package cn.quantgroup.xyqb.interceptors;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Created by Miraculous on 15/7/10.
*/
public class ChannelIdInterceptor implements HandlerInterceptor {
private static final String CHANNEL_ID = "channelId";
private static final String CREATED_FROM = "createdFrom";
private static final String APP_CHANNEL = "appChannel";
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
String channelId = request.getParameter(CHANNEL_ID);
if (channelId == null) {
channelId = (String) request.getAttribute(CHANNEL_ID);
}
if (channelId != null) {
request.getSession().setAttribute(CHANNEL_ID, channelId);
}
String createdFrom = request.getParameter(CREATED_FROM);
if (createdFrom == null) {
createdFrom = (String) request.getAttribute(CREATED_FROM);
}
if (createdFrom != null) {
request.getSession().setAttribute(CREATED_FROM, createdFrom);
}
String appChannel = request.getParameter(APP_CHANNEL);
if (appChannel == null) {
appChannel = (String) request.getAttribute(APP_CHANNEL);
}
if (appChannel != null) {
request.getSession().setAttribute(APP_CHANNEL, appChannel);
}
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object o, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object o, Exception e) throws Exception {
}
}
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