|
@ -13,7 +13,6 @@ import com.yihu.hos.core.encrypt.DES;
|
|
|
import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
|
|
|
import com.yihu.hos.web.framework.model.Result;
|
|
|
import com.yihu.hos.web.framework.model.bo.ServiceFlow;
|
|
|
import com.yihu.hos.web.framework.util.GridFSUtil;
|
|
|
import org.apache.log4j.LogManager;
|
|
|
import org.apache.log4j.Logger;
|
|
|
import org.bson.Document;
|
|
@ -21,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URL;
|
|
@ -236,14 +236,19 @@ public class ESBCamelService {
|
|
|
FileOutputStream outputStream = ClassFileUtil.createFile(resource, handleFile.getPackageName(), handleFile.getClassName(), ClassFileUtil.CLASS_FILE);
|
|
|
|
|
|
String fileName = DES.decrypt(handleFile.getFilePath(), DES.COMMON_PASSWORD);
|
|
|
MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
|
|
|
// MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
|
|
|
|
|
|
// boolean read = GridFSUtil.readFile(db, outputStream, fileName);
|
|
|
//从中心下载
|
|
|
String downUrl = centerUrl + "/tenant/down/" + handleFile.getFilePath();
|
|
|
String sourcePath = ClassFileUtil.downFile(downUrl, resource, handleFile.getPackageName(), handleFile.getClassName(), ClassFileUtil.CLASS_FILE);
|
|
|
|
|
|
boolean read = GridFSUtil.readFile(db, outputStream, fileName);
|
|
|
if (!read) {
|
|
|
if (sourcePath==null) {
|
|
|
logger.error("not mongo file, fileName:" + fileName);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
return read;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
private boolean generateClassFile(ServiceFlow.HandleFile handleFile) throws Exception {
|
|
@ -253,7 +258,7 @@ public class ESBCamelService {
|
|
|
SystemCamelContext.putClassMapping(handleFile.getRouteCode(), handleFile.getPackageName(), handleFile.getUsage(), handleFile.getClassName());
|
|
|
URL resource = SystemCamelContext.getResource(this);
|
|
|
// FileOutputStream outputStream = ClassFileUtil.createFile(resource, handleFile.getPackageName(), handleFile.getClassName(), ClassFileUtil.JAVA_FILE);
|
|
|
// String fileName = DES.decrypt(handleFile.getFilePath(), DES.COMMON_PASSWORD);
|
|
|
String fileName = DES.decrypt(handleFile.getFilePath(), DES.COMMON_PASSWORD);
|
|
|
// MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
|
|
|
//
|
|
|
// boolean read = GridFSUtil.readFileContent(db, outputStream, fileName);
|
|
@ -276,8 +281,11 @@ public class ESBCamelService {
|
|
|
//编译成功后将class文件上传至mongodb;文件名为类名+ routeCode
|
|
|
String packagePath = StringUtil.replaceStrAll(handleFile.getPackageName(), ".", "/");
|
|
|
String classPath = resource.getPath()+ packagePath + "/" + handleFile.getClassName() + ClassFileUtil.CLASS_FILE;
|
|
|
GridFSUtil.uploadFile(classPath, handleFile.getClassName()+handleFile.getRouteCode() + ClassFileUtil.CLASS_FILE,null);
|
|
|
//TODO 上传到本地mongodb和中心mongodb
|
|
|
// GridFSUtil.uploadFile(classPath, handleFile.getClassName() + handleFile.getRouteCode() + ClassFileUtil.CLASS_FILE, null);
|
|
|
// TODO 上传到本地mongodb和中心mongodb
|
|
|
String enFileName = DES.encrypt(handleFile.getClassName() + handleFile.getRouteCode() + ClassFileUtil.CLASS_FILE, DES.COMMON_PASSWORD);
|
|
|
String uploadUrl = centerUrl + "/tenant/upload/" + enFileName;
|
|
|
ClassFileUtil.uploadFile(uploadUrl,new File(classPath),handleFile.getClassName() + handleFile.getRouteCode() + ClassFileUtil.CLASS_FILE);
|
|
|
}
|
|
|
return succ;
|
|
|
}
|
|
@ -294,6 +302,10 @@ public class ESBCamelService {
|
|
|
|
|
|
ClassFileUtil.deleteClassfile(classPath);
|
|
|
ClassFileUtil.deleteClassfile(javaPath);
|
|
|
//TODO 从中心删除
|
|
|
String uploadUrl = centerUrl + "/tenant/delFile/" + javaPath;
|
|
|
ClassFileUtil.deleteFile(uploadUrl);
|
|
|
|
|
|
// 完成
|
|
|
logger.info("===================" + handleFile.getPackageName() + CoreConstant.DOT + handleFile.getClassName() + ".class 删除过程结束");
|
|
|
}
|