// Path: src/main/java/org/smartloli/kafka/eagle/web/controller/aop/AccountInterceptor.java
// public class AccountInterceptor extends HandlerInterceptorAdapter {
// 
// 	/** Kafka service interface. */
// 	private KafkaService kafkaService = new KafkaFactory().create();
// 	private int count = 0;
// 
// 	@Override
// 	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 		try {
// 			Object object = request.getSession().getAttribute(ConstantUtils.SessionAlias.CLUSTER_ALIAS);
// 			if (object == null) {
// 				String[] clusterAliass = SystemConfigUtils.getPropertyArray("kafka.eagle.zk.cluster.alias", ",");
// 				String defaultClusterAlias = clusterAliass[0];
// 				request.getSession().setAttribute(ConstantUtils.SessionAlias.CLUSTER_ALIAS, defaultClusterAlias);
// 			}
// 			String formatter = SystemConfigUtils.getProperty("kafka.eagle.offset.storage");
// 			if ("kafka".equals(formatter) && count == 0) {
// 				HttpSession session = request.getSession();
// 				String clusterAlias = session.getAttribute(ConstantUtils.SessionAlias.CLUSTER_ALIAS).toString();
// 				String brokers = kafkaService.getAllBrokersInfo(clusterAlias);
// 				JSONArray kafkaBrokers = JSON.parseArray(brokers);
// 				String bootstrapServers = "";
// 				for (Object subObject : kafkaBrokers) {
// 					JSONObject kafkaBroker = (JSONObject) subObject;
// 					String host = kafkaBroker.getString("host");
// 					int port = kafkaBroker.getInteger("port");
// 					bootstrapServers += host + ":" + port + ",";
// 				}
// 				bootstrapServers = bootstrapServers.substring(0, bootstrapServers.length() - 1);
// 				//RpcClient.system(bootstrapServers);
// 				count++;
// 			}
// 		} catch (Exception e) {
// 			String[] clusterAliass = SystemConfigUtils.getPropertyArray("kafka.eagle.zk.cluster.alias", ",");
// 			String defaultClusterAlias = clusterAliass[0];
// 			request.getSession().setAttribute(ConstantUtils.SessionAlias.CLUSTER_ALIAS, defaultClusterAlias);
// 			e.printStackTrace();
// 		}
// 		return true;
// 	}
// 
// 	@Override
// 	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
// 		super.postHandle(request, response, handler, modelAndView);
// 	}
// 
// 	@Override
// 	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
// 		super.afterCompletion(request, response, handler, ex);
// 	}
// }


import org.smartloli.kafka.eagle.web.controller.aop.AccountInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
package org.smartloli.kafka.eagle.conf;


/**
 * @author yunnet
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
	
	@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
		super.addResourceHandlers(registry);
    }
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
// Path: src/main/java/org/smartloli/kafka/eagle/web/controller/aop/AccountInterceptor.java
// public class AccountInterceptor extends HandlerInterceptorAdapter {
// 
// 	/** Kafka service interface. */
// 	private KafkaService kafkaService = new KafkaFactory().create();
// 	private int count = 0;
// 
// 	@Override
// 	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 		try {
// 			Object object = request.getSession().getAttribute(ConstantUtils.SessionAlias.CLUSTER_ALIAS);
// 			if (object == null) {
// 				String[] clusterAliass = SystemConfigUtils.getPropertyArray("kafka.eagle.zk.cluster.alias", ",");
// 				String defaultClusterAlias = clusterAliass[0];
// 				request.getSession().setAttribute(ConstantUtils.SessionAlias.CLUSTER_ALIAS, defaultClusterAlias);
// 			}
// 			String formatter = SystemConfigUtils.getProperty("kafka.eagle.offset.storage");
// 			if ("kafka".equals(formatter) && count == 0) {
// 				HttpSession session = request.getSession();
// 				String clusterAlias = session.getAttribute(ConstantUtils.SessionAlias.CLUSTER_ALIAS).toString();
// 				String brokers = kafkaService.getAllBrokersInfo(clusterAlias);
// 				JSONArray kafkaBrokers = JSON.parseArray(brokers);
// 				String bootstrapServers = "";
// 				for (Object subObject : kafkaBrokers) {
// 					JSONObject kafkaBroker = (JSONObject) subObject;
// 					String host = kafkaBroker.getString("host");
// 					int port = kafkaBroker.getInteger("port");
// 					bootstrapServers += host + ":" + port + ",";
// 				}
// 				bootstrapServers = bootstrapServers.substring(0, bootstrapServers.length() - 1);
// 				//RpcClient.system(bootstrapServers);
// 				count++;
// 			}
// 		} catch (Exception e) {
// 			String[] clusterAliass = SystemConfigUtils.getPropertyArray("kafka.eagle.zk.cluster.alias", ",");
// 			String defaultClusterAlias = clusterAliass[0];
// 			request.getSession().setAttribute(ConstantUtils.SessionAlias.CLUSTER_ALIAS, defaultClusterAlias);
// 			e.printStackTrace();
// 		}
// 		return true;
// 	}
// 
// 	@Override
// 	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
// 		super.postHandle(request, response, handler, modelAndView);
// 	}
// 
// 	@Override
// 	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
// 		super.afterCompletion(request, response, handler, ex);
// 	}
// }


// Path: src/main/java/org/smartloli/kafka/eagle/conf/WebMvcConfig.java
import org.smartloli.kafka.eagle.web.controller.aop.AccountInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

package org.smartloli.kafka.eagle.conf;


/**
 * @author yunnet
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
	
	@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
		super.addResourceHandlers(registry);
    }
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new AccountInterceptor());