|  | @ -14,6 +14,7 @@ import com.yihu.hos.models.SystemCamelContext;
 | 
	
		
			
				|  |  | import com.yihu.hos.models.SystemClassMapping;
 | 
	
		
			
				|  |  | import com.yihu.hos.web.framework.model.Result;
 | 
	
		
			
				|  |  | import com.yihu.hos.web.framework.util.GridFSUtil;
 | 
	
		
			
				|  |  | import org.apache.camel.Processor;
 | 
	
		
			
				|  |  | import org.apache.camel.builder.RouteBuilder;
 | 
	
		
			
				|  |  | import org.apache.log4j.LogManager;
 | 
	
		
			
				|  |  | import org.apache.log4j.Logger;
 | 
	
	
		
			
				|  | @ -24,6 +25,8 @@ import java.io.File;
 | 
	
		
			
				|  |  | import java.io.FileOutputStream;
 | 
	
		
			
				|  |  | import java.io.IOException;
 | 
	
		
			
				|  |  | import java.net.MalformedURLException;
 | 
	
		
			
				|  |  | import java.net.URL;
 | 
	
		
			
				|  |  | import java.net.URLClassLoader;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
	
		
			
				|  | @ -54,6 +57,11 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |             String fileName = DES.decrypt(path, DES.COMMON_PASSWORD);
 | 
	
		
			
				|  |  |             MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
 | 
	
		
			
				|  |  |             if (GridFSUtil.readFile(db, out, fileName)) {
 | 
	
		
			
				|  |  |                 File packageFile = new File(serviceFlow + StringUtil.replaceStrAll(packageName, ".", "/"));
 | 
	
		
			
				|  |  |                 ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
 | 
	
		
			
				|  |  |                 ClassLoader camelESBClassLoader = new URLClassLoader(new URL[]{packageFile.toURI().toURL()}, currentClassLoader);
 | 
	
		
			
				|  |  |                 Thread.currentThread().setContextClassLoader(camelESBClassLoader);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 return Result.success("新增处理器成功!");
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 return Result.error("新增处理器失败!");
 | 
	
	
		
			
				|  | @ -98,10 +106,30 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 当外界组件通知一个已有的Processor路由定义被删除时,该事件被触发。
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Result onProcessorDataDelete(String serviceFlow, String packageName, String className) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             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);
 | 
	
		
			
				|  |  |             return Result.success("删除路由成功!");
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return Result.error("删除路由失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 当外界组件通知一个新的RouteDefine路由被定义时,该事件被触发
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Result onRouteDefineAdded(String serviceFlow , String packageName , String className , String path) {
 | 
	
		
			
				|  |  |     public Result onRouteDefineAdded(String serviceFlow, String packageName, String className, String path) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
 | 
	
		
			
				|  |  |                     || StringUtil.isEmpty(className) || StringUtil.isEmpty(path)) {
 | 
	
	
		
			
				|  | @ -174,7 +202,7 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().stopRoute(serviceFlow);
 | 
	
		
			
				|  |  |             SystemCamelContext.getDefaultCamelContext().removeRoute(serviceFlow);
 | 
	
		
			
				|  |  |             this.deleteClassfile(serviceFlow, packageName, className, BrokerConstant.PROCESSOR);
 | 
	
		
			
				|  |  |             this.deleteClassfile(serviceFlow, packageName, className, BrokerConstant.ROUTE);
 | 
	
		
			
				|  |  |             return Result.success("删除路由成功!");
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return Result.error("删除路由失败!");
 | 
	
	
		
			
				|  | @ -231,17 +259,16 @@ public class ESBCamelService {
 | 
	
		
			
				|  |  |         return out;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private FileOutputStream updateClassfile(String serviceFlow, String packageName, String className, String type) {
 | 
	
		
			
				|  |  |     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;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String packagePath = StringUtil.replaceStrAll(packageName, ".", "/");
 | 
	
		
			
				|  |  |         String classPath = this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath() + packagePath + "/" + className + ".class";
 | 
	
		
			
				|  |  |         File systemClassFlowPath = new File(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath());
 | 
	
		
			
				|  |  |         // 2、============开始写入class文件
 | 
	
		
			
				|  |  |         FileOutputStream out = ClassFileUtil.updateClassfile(classPath);
 | 
	
		
			
				|  |  |         FileOutputStream out = ClassFileUtil.updateClassfile(systemClassFlowPath.toURI().toURL(), packageName, className);
 | 
	
		
			
				|  |  |         // 完成
 | 
	
		
			
				|  |  |         logger.info("===================" + packageName + CoreConstant.DOT + className + ".class 修改过程结束");
 | 
	
		
			
				|  |  |         return out;
 |