|  | @ -1,17 +1,19 @@
 | 
	
		
			
				|  |  | package com.yihu.hos.broker.services;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
	
		
			
				|  |  | import com.mongodb.client.MongoDatabase;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.common.classLoader.DynamicClassLoader;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.common.compiler.CamelCompiler;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.common.compiler.ClassParams;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.configurations.MongoConfiguration;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.common.constants.BrokerConstant;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.configurations.MongoConfiguration;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.models.SystemCamelContext;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.models.SystemClassMapping;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.models.bo.ServiceFlow;
 | 
	
		
			
				|  |  | import com.yihu.hos.core.constants.CoreConstant;
 | 
	
		
			
				|  |  | import com.yihu.hos.core.datatype.ClassFileUtil;
 | 
	
		
			
				|  |  | import com.yihu.hos.core.datatype.StringUtil;
 | 
	
		
			
				|  |  | import com.yihu.hos.core.encrypt.DES;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.models.SystemCamelContext;
 | 
	
		
			
				|  |  | import com.yihu.hos.broker.models.SystemClassMapping;
 | 
	
		
			
				|  |  | import com.yihu.hos.web.framework.model.Result;
 | 
	
		
			
				|  |  | import com.yihu.hos.web.framework.util.GridFSUtil;
 | 
	
		
			
				|  |  | import org.apache.camel.builder.RouteBuilder;
 | 
	
	
		
			
				|  | @ -24,34 +26,43 @@ import java.io.File;
 | 
	
		
			
				|  |  | import java.io.FileOutputStream;
 | 
	
		
			
				|  |  | import java.io.IOException;
 | 
	
		
			
				|  |  | import java.net.MalformedURLException;
 | 
	
		
			
				|  |  | import java.util.ArrayList;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created by lingfeng on 2016/8/4.
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | @Service("ESBCamelService")
 | 
	
		
			
				|  |  | @Service
 | 
	
		
			
				|  |  | public class ESBCamelService {
 | 
	
		
			
				|  |  |     public static final String BEAN_ID = "ESBCamelService";
 | 
	
		
			
				|  |  |     private static Logger logger = LogManager.getLogger(ESBCamelService.class);
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private MongoConfiguration mongoConfig;
 | 
	
		
			
				|  |  |     private String dbName = "upload";
 | 
	
		
			
				|  |  |     private static Logger logger = LogManager.getLogger(ESBCamelService.class);
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ObjectMapper objectMapper;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 当外界组件通知一个新的processor处理器被定义时,该事件被触发。
 | 
	
		
			
				|  |  |      * @param serviceFlow 本次processor处理器变化,所涉及的业务系统唯一标识。
 | 
	
		
			
				|  |  |      * @param packageName processor处理器定义涉及的class包名
 | 
	
		
			
				|  |  |      * @param className processor处理器定义涉及的class类名
 | 
	
		
			
				|  |  |      * @param path processor处理器定义涉及的class对应路径
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Result onProcessorAdded(String serviceFlow, String packageName, String className, String path) {
 | 
	
		
			
				|  |  |     public Result onProcessorAdded(String msg) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |                     || StringUtil.isEmpty(className) || StringUtil.isEmpty(path)) {
 | 
	
		
			
				|  |  |             ServiceFlow serviceFlow = objectMapper.readValue(msg, ServiceFlow.class);
 | 
	
		
			
				|  |  |             ArrayList<ServiceFlow.HandleFile> handleFiles = serviceFlow.getHandleFiles();
 | 
	
		
			
				|  |  |             if (handleFiles == null || handleFiles.size() == 0) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             FileOutputStream out = this.createClassfile(serviceFlow, packageName, className, BrokerConstant.PROCESSOR);
 | 
	
		
			
				|  |  |             String fileName = DES.decrypt(path, DES.COMMON_PASSWORD);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             ServiceFlow.HandleFile handleFile = handleFiles.get(0);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (handleFile == null || StringUtil.isEmpty(serviceFlow.getRouteCode()) || StringUtil.isEmpty(handleFile.getPackageName())
 | 
	
		
			
				|  |  |                     || StringUtil.isEmpty(handleFile.getPackageName()) || StringUtil.isEmpty(handleFile.getFilePath())) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             FileOutputStream out = this.createClassfile(serviceFlow.getRouteCode(), handleFile.getPackageName(), handleFile.getPackageName(), BrokerConstant.PROCESSOR);
 | 
	
		
			
				|  |  |             String fileName = DES.decrypt(handleFile.getFilePath(), DES.COMMON_PASSWORD);
 | 
	
		
			
				|  |  |             MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
 | 
	
		
			
				|  |  |             if (GridFSUtil.readFile(db, out, fileName)) {
 | 
	
		
			
				|  |  |                 return Result.success("新增处理器成功!");
 | 
	
	
		
			
				|  | @ -67,20 +78,33 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 当外界组件通知一个已有的processor处理器data部分发生变化时,该事件被触发。
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Result onProcessorDataChanged(String serviceFlow , String packageName , String className , String path) {
 | 
	
		
			
				|  |  |     public Result onProcessorDataChanged(String msg) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |             ServiceFlow serviceFlow = objectMapper.readValue(msg, ServiceFlow.class);
 | 
	
		
			
				|  |  |             ArrayList<ServiceFlow.HandleFile> handleFiles = serviceFlow.getHandleFiles();
 | 
	
		
			
				|  |  |             if (handleFiles == null || handleFiles.size() == 0) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             ServiceFlow.HandleFile handleFile = handleFiles.get(0);
 | 
	
		
			
				|  |  |             String routeCode = serviceFlow.getRouteCode();
 | 
	
		
			
				|  |  |             String packageName = handleFile.getPackageName();
 | 
	
		
			
				|  |  |             String className = handleFile.getClassName();
 | 
	
		
			
				|  |  |             String path = handleFile.getFilePath();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (StringUtil.isEmpty(routeCode) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |                     || StringUtil.isEmpty(className) || StringUtil.isEmpty(path)) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             FileOutputStream out = this.updateClassfile(serviceFlow, packageName, className, BrokerConstant.PROCESSOR);
 | 
	
		
			
				|  |  |             FileOutputStream out = this.updateClassfile(routeCode, packageName, className, BrokerConstant.PROCESSOR);
 | 
	
		
			
				|  |  |             String fileName = DES.decrypt(path, DES.COMMON_PASSWORD);
 | 
	
		
			
				|  |  |             MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
 | 
	
		
			
				|  |  |             if (GridFSUtil.readFile(db, out, fileName)) {
 | 
	
		
			
				|  |  |                 SystemCamelContext.getDefaultCamelContext().stopRoute(serviceFlow);
 | 
	
		
			
				|  |  |                 SystemCamelContext.getDefaultCamelContext().removeRoute(serviceFlow);
 | 
	
		
			
				|  |  |                 SystemCamelContext.getDefaultCamelContext().stopRoute(routeCode);
 | 
	
		
			
				|  |  |                 SystemCamelContext.getDefaultCamelContext().removeRoute(routeCode);
 | 
	
		
			
				|  |  |                 DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
 | 
	
		
			
				|  |  |                 Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE + className));
 | 
	
		
			
				|  |  |                 classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.PROCESSOR + className));
 | 
	
	
		
			
				|  | @ -101,17 +125,29 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 当外界组件通知一个已有的Processor路由定义被删除时,该事件被触发。
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Result onProcessorDataDelete(String serviceFlow, String packageName, String className) {
 | 
	
		
			
				|  |  |     public Result onProcessorDataDelete(String msg) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |             ServiceFlow serviceFlow = objectMapper.readValue(msg, ServiceFlow.class);
 | 
	
		
			
				|  |  |             ArrayList<ServiceFlow.HandleFile> handleFiles = serviceFlow.getHandleFiles();
 | 
	
		
			
				|  |  |             if (handleFiles == null || handleFiles.size() == 0) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             ServiceFlow.HandleFile handleFile = handleFiles.get(0);
 | 
	
		
			
				|  |  |             String routeCode = serviceFlow.getRouteCode();
 | 
	
		
			
				|  |  |             String packageName = handleFile.getPackageName();
 | 
	
		
			
				|  |  |             String className = handleFile.getClassName();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |                     || StringUtil.isEmpty(className)) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().stopRoute(serviceFlow);
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().removeRoute(serviceFlow);
 | 
	
		
			
				|  |  |             this.deleteClassfile(serviceFlow, packageName, className, BrokerConstant.PROCESSOR);
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().stopRoute(routeCode);
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().removeRoute(routeCode);
 | 
	
		
			
				|  |  |             this.deleteClassfile(routeCode, packageName, className, BrokerConstant.PROCESSOR);
 | 
	
		
			
				|  |  |             return Result.success("删除路由成功!");
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return Result.error("删除路由失败!");
 | 
	
	
		
			
				|  | @ -121,22 +157,35 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 当外界组件通知一个新的RouteDefine路由被定义时,该事件被触发
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Result onRouteDefineAdded(String serviceFlow, String packageName, String className, String path) {
 | 
	
		
			
				|  |  |     public Result onRouteDefineAdded(String msg) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |             ServiceFlow serviceFlow = objectMapper.readValue(msg, ServiceFlow.class);
 | 
	
		
			
				|  |  |             ArrayList<ServiceFlow.HandleFile> handleFiles = serviceFlow.getHandleFiles();
 | 
	
		
			
				|  |  |             if (handleFiles == null || handleFiles.size() == 0) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             ServiceFlow.HandleFile handleFile = handleFiles.get(0);
 | 
	
		
			
				|  |  |             String routeCode = serviceFlow.getRouteCode();
 | 
	
		
			
				|  |  |             String packageName = handleFile.getPackageName();
 | 
	
		
			
				|  |  |             String className = handleFile.getClassName();
 | 
	
		
			
				|  |  |             String path = handleFile.getFilePath();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |                     || StringUtil.isEmpty(className) || StringUtil.isEmpty(path)) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             // 第1、2两步处理过程,都是在这里完成
 | 
	
		
			
				|  |  |             FileOutputStream out = this.createClassfile(serviceFlow, packageName, className, BrokerConstant.ROUTE);
 | 
	
		
			
				|  |  |             FileOutputStream out = this.createClassfile(routeCode, packageName, className, BrokerConstant.ROUTE);
 | 
	
		
			
				|  |  |             String fileName = DES.decrypt(path, DES.COMMON_PASSWORD);
 | 
	
		
			
				|  |  |             MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
 | 
	
		
			
				|  |  |             if (GridFSUtil.readFile(db, out, fileName)) {
 | 
	
		
			
				|  |  |                 // 3、===============加载到CamelContext中
 | 
	
		
			
				|  |  |                 DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
 | 
	
		
			
				|  |  |                 Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE + className));
 | 
	
		
			
				|  |  |                 if(routeBuilderClass != null) {
 | 
	
		
			
				|  |  |                 if (routeBuilderClass != null) {
 | 
	
		
			
				|  |  |                     RouteBuilder routeBuilder = routeBuilderClass.newInstance();
 | 
	
		
			
				|  |  |                     SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
 | 
	
		
			
				|  |  |                 }
 | 
	
	
		
			
				|  | @ -153,22 +202,36 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 当外界组件通知一个已有的RouteDefine路由定义被改变时,主要就是路由定义内容被改变时,该事件被触发。
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Result onRouteDefineChanged(String serviceFlow, String packageName, String className, String path) {
 | 
	
		
			
				|  |  |     public Result onRouteDefineChanged(String msg) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             ServiceFlow serviceFlow = objectMapper.readValue(msg, ServiceFlow.class);
 | 
	
		
			
				|  |  |             ArrayList<ServiceFlow.HandleFile> handleFiles = serviceFlow.getHandleFiles();
 | 
	
		
			
				|  |  |             if (handleFiles == null || handleFiles.size() == 0) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             ServiceFlow.HandleFile handleFile = handleFiles.get(0);
 | 
	
		
			
				|  |  |             String routeCode = serviceFlow.getRouteCode();
 | 
	
		
			
				|  |  |             String packageName = handleFile.getPackageName();
 | 
	
		
			
				|  |  |             String className = handleFile.getClassName();
 | 
	
		
			
				|  |  |             String path = handleFile.getFilePath();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |                     || StringUtil.isEmpty(className) || StringUtil.isEmpty(path)) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().stopRoute(serviceFlow);
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().removeRoute(serviceFlow);
 | 
	
		
			
				|  |  |             FileOutputStream out = this.updateClassfile(serviceFlow, packageName, className, BrokerConstant.ROUTE);
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().stopRoute(routeCode);
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().removeRoute(routeCode);
 | 
	
		
			
				|  |  |             FileOutputStream out = this.updateClassfile(routeCode, packageName, className, BrokerConstant.ROUTE);
 | 
	
		
			
				|  |  |             String fileName = DES.decrypt(path, DES.COMMON_PASSWORD);
 | 
	
		
			
				|  |  |             MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
 | 
	
		
			
				|  |  |             if (GridFSUtil.readFile(db, out, fileName)) {
 | 
	
		
			
				|  |  |                 // 3、===============加载到CamelContext中
 | 
	
		
			
				|  |  |                 DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
 | 
	
		
			
				|  |  |                 Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE+className));
 | 
	
		
			
				|  |  |                 Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE + className));
 | 
	
		
			
				|  |  |                 if (routeBuilderClass != null) {
 | 
	
		
			
				|  |  |                     RouteBuilder routeBuilder = routeBuilderClass.newInstance();
 | 
	
		
			
				|  |  |                     SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
 | 
	
	
		
			
				|  | @ -184,17 +247,31 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 当外界组件通知一个已有的RouteDefine路由定义被删除时,该事件被触发。
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Result onRouteDefineDelete(String serviceFlow, String packageName, String className) {
 | 
	
		
			
				|  |  |     public Result onRouteDefineDelete(String msg) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |             ServiceFlow serviceFlow = objectMapper.readValue(msg, ServiceFlow.class);
 | 
	
		
			
				|  |  |             ArrayList<ServiceFlow.HandleFile> handleFiles = serviceFlow.getHandleFiles();
 | 
	
		
			
				|  |  |             if (handleFiles == null || handleFiles.size() == 0) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             ServiceFlow.HandleFile handleFile = handleFiles.get(0);
 | 
	
		
			
				|  |  |             String routeCode = serviceFlow.getRouteCode();
 | 
	
		
			
				|  |  |             String packageName = handleFile.getPackageName();
 | 
	
		
			
				|  |  |             String className = handleFile.getClassName();
 | 
	
		
			
				|  |  |             String path = handleFile.getFilePath();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |                     || StringUtil.isEmpty(className)) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().stopRoute(serviceFlow);
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().removeRoute(serviceFlow);
 | 
	
		
			
				|  |  |             this.deleteClassfile(serviceFlow, packageName, className, BrokerConstant.ROUTE);
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().stopRoute(routeCode);
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().removeRoute(routeCode);
 | 
	
		
			
				|  |  |             this.deleteClassfile(routeCode, packageName, className, BrokerConstant.ROUTE);
 | 
	
		
			
				|  |  |             return Result.success("删除路由成功!");
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return Result.error("删除路由失败!");
 | 
	
	
		
			
				|  | @ -204,14 +281,28 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 启动路由时,该事件被触发。
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Result onRouteDefineStart(String serviceFlow) {
 | 
	
		
			
				|  |  |     public Result onRouteDefineStart(String msg) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtil.isEmpty(serviceFlow)) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             ServiceFlow serviceFlow = objectMapper.readValue(msg, ServiceFlow.class);
 | 
	
		
			
				|  |  |             ArrayList<ServiceFlow.HandleFile> handleFiles = serviceFlow.getHandleFiles();
 | 
	
		
			
				|  |  |             if (handleFiles == null || handleFiles.size() == 0) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().startRoute(serviceFlow);
 | 
	
		
			
				|  |  |             ServiceFlow.HandleFile handleFile = handleFiles.get(0);
 | 
	
		
			
				|  |  |             String routeCode = serviceFlow.getRouteCode();
 | 
	
		
			
				|  |  |             String packageName = handleFile.getPackageName();
 | 
	
		
			
				|  |  |             String className = handleFile.getClassName();
 | 
	
		
			
				|  |  |             String path = handleFile.getFilePath();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (StringUtil.isEmpty(serviceFlow)) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().startRoute(routeCode);
 | 
	
		
			
				|  |  |             return Result.success("启动路由成功!");
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return Result.error("启动路由失败!");
 | 
	
	
		
			
				|  | @ -221,82 +312,55 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 停止路由时,该事件被触发。
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Result onRouteDefineStop(String serviceFlow) {
 | 
	
		
			
				|  |  |     public Result onRouteDefineStop(String msg) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtil.isEmpty(serviceFlow)) {
 | 
	
		
			
				|  |  |             ServiceFlow serviceFlow = objectMapper.readValue(msg, ServiceFlow.class);
 | 
	
		
			
				|  |  |             ArrayList<ServiceFlow.HandleFile> handleFiles = serviceFlow.getHandleFiles();
 | 
	
		
			
				|  |  |             if (handleFiles == null || handleFiles.size() == 0) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             ServiceFlow.HandleFile handleFile = handleFiles.get(0);
 | 
	
		
			
				|  |  |             String routeCode = serviceFlow.getRouteCode();
 | 
	
		
			
				|  |  |             String packageName = handleFile.getPackageName();
 | 
	
		
			
				|  |  |             String className = handleFile.getClassName();
 | 
	
		
			
				|  |  |             String path = handleFile.getFilePath();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (StringUtil.isEmpty(serviceFlow)) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().stopRoute(serviceFlow);
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().stopRoute(routeCode);
 | 
	
		
			
				|  |  |             return Result.success("停止路由成功!");
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return Result.error("停止路由失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Result onProcessorClassAdded(String msg) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             ServiceFlow serviceFlow = objectMapper.readValue(msg, ServiceFlow.class);
 | 
	
		
			
				|  |  |             ArrayList<ServiceFlow.HandleFile> handleFiles = serviceFlow.getHandleFiles();
 | 
	
		
			
				|  |  |             if (handleFiles == null || handleFiles.size() == 0) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             ServiceFlow.HandleFile handleFile = handleFiles.get(0);
 | 
	
		
			
				|  |  |             String routeCode = serviceFlow.getRouteCode();
 | 
	
		
			
				|  |  |             String packageName = handleFile.getPackageName();
 | 
	
		
			
				|  |  |             String className = handleFile.getClassName();
 | 
	
		
			
				|  |  |             String path = handleFile.getFilePath();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private FileOutputStream createClassfile(String serviceFlow, String packageName, String className, String type) throws MalformedURLException {
 | 
	
		
			
				|  |  |         // 1、============
 | 
	
		
			
				|  |  |         File systemClassFlowPath = new File(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath());
 | 
	
		
			
				|  |  |         // 记录到工具类中,以便其它线程需要时进行取用
 | 
	
		
			
				|  |  |         SystemClassMapping.getSystemClassNameMapping().put(serviceFlow + type + className, packageName + CoreConstant.DOT + className);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 2、============开始写入class文件
 | 
	
		
			
				|  |  |         FileOutputStream out = ClassFileUtil.createClassfile(systemClassFlowPath.toURI().toURL(), packageName, className);
 | 
	
		
			
				|  |  |         // 完成
 | 
	
		
			
				|  |  |         logger.info("===================" + packageName + CoreConstant.DOT + className + ".class 生成过程结束");
 | 
	
		
			
				|  |  |         return out;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private FileOutputStream updateClassfile(String serviceFlow, String packageName, String className, String type) throws MalformedURLException {
 | 
	
		
			
				|  |  |         // 1、============
 | 
	
		
			
				|  |  |         Map<String, String> systemClassNameMapping = SystemClassMapping.getSystemClassNameMapping();
 | 
	
		
			
				|  |  |         String systemClassName = systemClassNameMapping.get(serviceFlow + type + className);
 | 
	
		
			
				|  |  |         if(StringUtil.isEmpty(systemClassName)) {
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         File systemClassFlowPath = new File(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath());
 | 
	
		
			
				|  |  |         // 2、============开始写入class文件
 | 
	
		
			
				|  |  |         FileOutputStream out = ClassFileUtil.updateClassfile(systemClassFlowPath.toURI().toURL(), packageName, className);
 | 
	
		
			
				|  |  |         // 完成
 | 
	
		
			
				|  |  |         logger.info("===================" + packageName + CoreConstant.DOT + className + ".class 修改过程结束");
 | 
	
		
			
				|  |  |         return out;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private void deleteClassfile(String serviceFlow, String packageName, String className, String type) {
 | 
	
		
			
				|  |  |         // 1、============
 | 
	
		
			
				|  |  |         Map<String, String> systemClassNameMapping = SystemClassMapping.getSystemClassNameMapping();
 | 
	
		
			
				|  |  |         String systemClassName = systemClassNameMapping.get(serviceFlow + type + className);
 | 
	
		
			
				|  |  |         if(StringUtil.isEmpty(systemClassName)) {
 | 
	
		
			
				|  |  |             return;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String packagePath = StringUtil.replaceStrAll(packageName, ".", "/");
 | 
	
		
			
				|  |  |         String classPath = ClassLoader.getSystemResource("").getPath() + "/" + packagePath + "/" + className + ".class";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 2、============开始写入class文件
 | 
	
		
			
				|  |  |         ClassFileUtil.deleteClassfile(classPath);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 完成
 | 
	
		
			
				|  |  |         logger.info("===================" + packageName + CoreConstant.DOT + className + ".class 删除过程结束");
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /* **************************       修改任务cron生成新的camel文件 add by hzy   *********************************** */
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Result onProcessorClassAdded(String serviceFlow, String packageName, String className, String path) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |             if (StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |                     || StringUtil.isEmpty(className) || StringUtil.isEmpty(path)) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             return this.genProcessorFile(serviceFlow, packageName, className, path);
 | 
	
		
			
				|  |  |             return this.genProcessorFile(routeCode, packageName, className, path);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             logger.error(e);
 | 
	
	
		
			
				|  | @ -309,7 +373,7 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Result onRouteClassAdded(ClassParams params) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtil.isEmpty(params.getRouteId()) || StringUtil.isEmpty(params.getPackageName())
 | 
	
		
			
				|  |  |             if (StringUtil.isEmpty(params.getRouteId()) || StringUtil.isEmpty(params.getPackageName())
 | 
	
		
			
				|  |  |                     || StringUtil.isEmpty(params.getOldClassName()) || StringUtil.isEmpty(params.getFilePath())) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
	
		
			
				|  | @ -320,22 +384,21 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |             // 3、===============加载到CamelContext中
 | 
	
		
			
				|  |  |             ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
 | 
	
		
			
				|  |  |             Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) currentClassLoader.loadClass(SystemClassMapping.getSystemClassNameMapping().get(params.getRouteId() + BrokerConstant.ROUTE + params.getNewClassName()));
 | 
	
		
			
				|  |  |             if(routeBuilderClass != null) {
 | 
	
		
			
				|  |  |             if (routeBuilderClass != null) {
 | 
	
		
			
				|  |  |                 RouteBuilder routeBuilder = routeBuilderClass.newInstance();
 | 
	
		
			
				|  |  |                 SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             return Result.success("新增路由成功!");
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |            e.printStackTrace();
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             logger.error(e);
 | 
	
		
			
				|  |  |             return Result.error("新增路由失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Result onRouteClassChanged(ClassParams params) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtil.isEmpty(params.getRouteId()) || StringUtil.isEmpty(params.getPackageName())
 | 
	
		
			
				|  |  |             if (StringUtil.isEmpty(params.getRouteId()) || StringUtil.isEmpty(params.getPackageName())
 | 
	
		
			
				|  |  |                     || StringUtil.isEmpty(params.getOldClassName()) || StringUtil.isEmpty(params.getFilePath())) {
 | 
	
		
			
				|  |  |                 logger.error("必要的入参数据不正确,请检查!");
 | 
	
		
			
				|  |  |                 return Result.error("必要的入参数据不正确,请检查!");
 | 
	
	
		
			
				|  | @ -360,12 +423,15 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /* **************************       修改任务cron生成新的camel文件 add by hzy   *********************************** */
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Result genProcessorFile(String serviceFlow, String packageName, String className, String path) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             String filePath= CamelCompiler.genProcessClass(serviceFlow, path, packageName, className);
 | 
	
		
			
				|  |  |             if (filePath !=null){
 | 
	
		
			
				|  |  |             String filePath = CamelCompiler.genProcessClass(serviceFlow, path, packageName, className);
 | 
	
		
			
				|  |  |             if (filePath != null) {
 | 
	
		
			
				|  |  |                 return Result.success(filePath);
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 return Result.error("生成新文件失败1!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -385,6 +451,50 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private FileOutputStream createClassfile(String serviceFlow, String packageName, String className, String type) throws MalformedURLException {
 | 
	
		
			
				|  |  |         // 1、============
 | 
	
		
			
				|  |  |         File systemClassFlowPath = new File(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath());
 | 
	
		
			
				|  |  |         // 记录到工具类中,以便其它线程需要时进行取用
 | 
	
		
			
				|  |  |         SystemClassMapping.getSystemClassNameMapping().put(serviceFlow + type + className, packageName + CoreConstant.DOT + className);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 2、============开始写入class文件
 | 
	
		
			
				|  |  |         FileOutputStream out = ClassFileUtil.createClassfile(systemClassFlowPath.toURI().toURL(), packageName, className);
 | 
	
		
			
				|  |  |         // 完成
 | 
	
		
			
				|  |  |         logger.info("===================" + packageName + CoreConstant.DOT + className + ".class 生成过程结束");
 | 
	
		
			
				|  |  |         return out;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private FileOutputStream updateClassfile(String serviceFlow, String packageName, String className, String type) throws MalformedURLException {
 | 
	
		
			
				|  |  |         // 1、============
 | 
	
		
			
				|  |  |         Map<String, String> systemClassNameMapping = SystemClassMapping.getSystemClassNameMapping();
 | 
	
		
			
				|  |  |         String systemClassName = systemClassNameMapping.get(serviceFlow + type + className);
 | 
	
		
			
				|  |  |         if (StringUtil.isEmpty(systemClassName)) {
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         File systemClassFlowPath = new File(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath());
 | 
	
		
			
				|  |  |         // 2、============开始写入class文件
 | 
	
		
			
				|  |  |         FileOutputStream out = ClassFileUtil.updateClassfile(systemClassFlowPath.toURI().toURL(), packageName, className);
 | 
	
		
			
				|  |  |         // 完成
 | 
	
		
			
				|  |  |         logger.info("===================" + packageName + CoreConstant.DOT + className + ".class 修改过程结束");
 | 
	
		
			
				|  |  |         return out;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private void deleteClassfile(String serviceFlow, String packageName, String className, String type) {
 | 
	
		
			
				|  |  |         // 1、============
 | 
	
		
			
				|  |  |         Map<String, String> systemClassNameMapping = SystemClassMapping.getSystemClassNameMapping();
 | 
	
		
			
				|  |  |         String systemClassName = systemClassNameMapping.get(serviceFlow + type + className);
 | 
	
		
			
				|  |  |         if (StringUtil.isEmpty(systemClassName)) {
 | 
	
		
			
				|  |  |             return;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String packagePath = StringUtil.replaceStrAll(packageName, ".", "/");
 | 
	
		
			
				|  |  |         String classPath = ClassLoader.getSystemResource("").getPath() + "/" + packagePath + "/" + className + ".class";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 2、============开始写入class文件
 | 
	
		
			
				|  |  |         ClassFileUtil.deleteClassfile(classPath);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 完成
 | 
	
		
			
				|  |  |         logger.info("===================" + packageName + CoreConstant.DOT + className + ".class 删除过程结束");
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |