Parcourir la source

Merge branch 'master' of http://192.168.1.220:10080/esb/esb

demon il y a 8 ans
Parent
commit
12dbb4fc4a

+ 2 - 3
hos-arbiter/src/main/java/com/yihu/hos/arbiter/services/ServiceFlowService.java

@ -81,7 +81,7 @@ public class ServiceFlowService {
                }
                case "routeDefineAdded": {
                    HttpPost httpPost = new HttpPost(brokerServer.getURL() + "/esb/processor");
                    HttpPost httpPost = new HttpPost(brokerServer.getURL() + "/esb/route");
                    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairList, Consts.UTF_8));
                    CloseableHttpResponse response = httpclient.execute(httpPost);
                    response.close();
@ -100,11 +100,10 @@ public class ServiceFlowService {
                        URI uri = new URIBuilder()
                                .setScheme("http")
                                .setHost(brokerServer.getHostAddress() + ":" + brokerServer.getPort())
                                .setPath("/route")
                                .setPath("/esb/route")
                                .setParameter("serviceFlow", serviceFlow.getServiceFlow())
                                .setParameter("packageName", serviceFlow.getPackageName())
                                .setParameter("className", serviceFlow.getClassName())
                                .setParameter("path", serviceFlow.getPath())
                                .build();
                        HttpDelete httpDelete = new HttpDelete(uri);

+ 8 - 10
hos-broker/src/main/java/com/yihu/hos/services/ESBCamelService.java

@ -64,7 +64,7 @@ public class ESBCamelService {
            SystemCamelContext.getDefaultCamelContext().removeRoute(serviceFlow);
            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));
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE));
            classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.PROCESSOR));
            if (routeBuilderClass != null) {
@ -88,10 +88,6 @@ public class ESBCamelService {
                logger.error("必要的入参数据不正确,请检查!");
                return Result.error("必要的入参数据不正确,请检查!");
            }
            File systemClassRootPath = new File(ClassLoader.getSystemResource("").getPath() + "/" + serviceFlow);
            if (!systemClassRootPath.exists()) {
                systemClassRootPath.mkdirs();
            }
            // 第1、2两步处理过程,都是在这里完成
            this.createClassfile(serviceFlow, packageName, className, path, BrokerConstant.ROUTE);
@ -194,9 +190,9 @@ public class ESBCamelService {
    private void createClassfile(String serviceFlow, String packageName, String className, String path, String type) throws MalformedURLException {
        // 1、============
        File systemClassFlowPath = new File(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath() + "/" + serviceFlow);
        File systemClassFlowPath = new File(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath());
        // 记录到工具类中,以便其它线程需要时进行取用
        SystemClassMapping.getSystemClassNameMapping().put(serviceFlow + type, serviceFlow + CoreConstant.DOT + packageName + CoreConstant.DOT + className);
        SystemClassMapping.getSystemClassNameMapping().put(serviceFlow + type, packageName + CoreConstant.DOT + className);
        // 2、============开始写入class文件
        ClassFileUtil.createClassfile(systemClassFlowPath.toURI().toURL(), packageName, className, path);
@ -211,7 +207,8 @@ public class ESBCamelService {
        if(StringUtil.isEmpty(systemClassName)) {
            return;
        }
        String classPath = ClassLoader.getSystemResource("").getPath() + "/" + serviceFlow + "/" + packageName + "/" + className + ".class";
        String packagePath = StringUtil.replaceStrAll(packageName, ".", "/");
        String classPath = this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath() + packagePath + "/" + className + ".class";
        // 2、============开始写入class文件
        ClassFileUtil.updateClassfile(classPath, path);
        // 完成
@ -225,7 +222,8 @@ public class ESBCamelService {
        if(StringUtil.isEmpty(systemClassName)) {
            return;
        }
        String classPath = ClassLoader.getSystemResource("").getPath() + "/" + serviceFlow + "/" + packageName + "/" + className + ".class";
        String packagePath = StringUtil.replaceStrAll(packageName, ".", "/");
        String classPath = ClassLoader.getSystemResource("").getPath() + "/" + packagePath + "/" + className + ".class";
        // 2、============开始写入class文件
        ClassFileUtil.deleteClassfile(classPath);
@ -239,7 +237,7 @@ public class ESBCamelService {
    /* **************************       修改任务cron生成新的camel文件 add by hzy   *********************************** */
    public Result genNewClassfile(String type,String filePath, String packageName, String oldClassName, String newClassName,String newCron) {
        try {
            String path = null;
            String path;
            if ("route".equals(type)){
                 path = CamelCompiler.compiler(filePath,packageName,oldClassName,newClassName,newCron);
            }else if ("processor".equals(type)){

+ 1 - 1
hos-camel/src/main/java/api/route/ApiRouteBulider.java

@ -10,7 +10,7 @@ import org.apache.camel.builder.RouteBuilder;
public class ApiRouteBulider extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("jetty:http://localhost:9091/api/v1").routeId("api")
        from("jetty:http://localhost:9090/api/v1").routeId("api")
                .process(new ApiProcessor());
    }
}

+ 2 - 12
hos-camel/src/main/java/api1/processor/ApiProcessor.java

@ -16,18 +16,8 @@ import java.io.InputStream;
 */
public class ApiProcessor implements Processor {
    public void process(Exchange exchange) throws Exception {
        // 因为很明确消息格式是http的,所以才使用这个类
        // 否则还是建议使用org.apache.camel.Message这个抽象接口
        HttpMessage message = (HttpMessage) exchange.getIn();
        InputStream bodyStream = (InputStream) message.getBody();
        String inputContext = this.analysisMessage(bodyStream);
        bodyStream.close();
        // 存入到exchange的out区域
        if (exchange.getPattern() == ExchangePattern.InOut) {
            Message outMessage = exchange.getOut();
            outMessage.setBody("hello," + inputContext);
        }
        Message outMessage = exchange.getOut();
        outMessage.setBody("hello,api1");
    }
    /**

+ 2 - 2
hos-camel/src/main/java/api1/route/ApiRouteBulider.java

@ -10,7 +10,7 @@ import org.apache.camel.builder.RouteBuilder;
public class ApiRouteBulider extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("jetty:http://localhost:9090/api/v1").routeId("api1")
                .process(new ApiProcessor());
        from("jetty:http://localhost:9091/api/v1").routeId("api1")
                .process(new ApiProcessor()).to("stream:out");
    }
}

+ 44 - 0
hos-camel/src/main/java/api2/processor/ApiProcessor.java

@ -0,0 +1,44 @@
package api2.processor;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.http.common.HttpMessage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
 * @author Airhead
 * @since 2016-11-13
 */
public class ApiProcessor implements Processor {
    public void process(Exchange exchange) throws Exception {
        Message outMessage = exchange.getOut();
        outMessage.setBody("hello,api2");
    }
    /**
     * 从stream中分析字符串内容
     *
     * @param bodyStream
     * @return
     */
    private String analysisMessage(InputStream bodyStream) throws IOException {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] contextBytes = new byte[4096];
        int realLen;
        while ((realLen = bodyStream.read(contextBytes, 0, 4096)) != -1) {
            outStream.write(contextBytes, 0, realLen);
        }
        // 返回从Stream中读取的字串
        try {
            return new String(outStream.toByteArray(), "UTF-8");
        } finally {
            outStream.close();
        }
    }
}

+ 16 - 0
hos-camel/src/main/java/api2/route/ApiRouteBulider.java

@ -0,0 +1,16 @@
package api2.route;
import api2.processor.ApiProcessor;
import org.apache.camel.builder.RouteBuilder;
/**
 * @author Airhead
 * @since 2016-11-13
 */
public class ApiRouteBulider extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("jetty:http://localhost:9092/api/v1").routeId("api2")
                .process(new ApiProcessor());
    }
}

+ 42 - 0
hos-camel/src/main/java/api3/processor/ApiProcessor.java

@ -0,0 +1,42 @@
package api3.processor;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
 * @author Airhead
 * @since 2016-11-13
 */
public class ApiProcessor implements Processor {
    public void process(Exchange exchange) throws Exception {
        Message outMessage = exchange.getOut();
        outMessage.setBody("hello,api3");
    }
    /**
     * 从stream中分析字符串内容
     *
     * @param bodyStream
     * @return
     */
    private String analysisMessage(InputStream bodyStream) throws IOException {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] contextBytes = new byte[4096];
        int realLen;
        while ((realLen = bodyStream.read(contextBytes, 0, 4096)) != -1) {
            outStream.write(contextBytes, 0, realLen);
        }
        // 返回从Stream中读取的字串
        try {
            return new String(outStream.toByteArray(), "UTF-8");
        } finally {
            outStream.close();
        }
    }
}

+ 16 - 0
hos-camel/src/main/java/api3/route/ApiRouteBulider.java

@ -0,0 +1,16 @@
package api3.route;
import api3.processor.ApiProcessor;
import org.apache.camel.builder.RouteBuilder;
/**
 * @author Airhead
 * @since 2016-11-13
 */
public class ApiRouteBulider extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("jetty:http://localhost:9093/api/v1").routeId("api3")
                .process(new ApiProcessor());
    }
}

+ 5 - 2
src/main/java/com/yihu/hos/system/controller/AppController.java

@ -20,9 +20,11 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.rmi.server.UID;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
 * 应用管理
@ -334,12 +336,13 @@ public class AppController extends BaseController {
    @ResponseBody
    public Object upload(@RequestParam MultipartFile file,HttpSession session,HttpServletRequest request
    ) {
        String basePath = filePathConfig.getFilePath();
        UUID uuid = UUID.randomUUID();
        String basePath = filePathConfig.getFilePath() + uuid + "/";
        String path = appManager.uploadFile(file, basePath);
        if (StringUtils.isEmpty(path)){
            return Result.error("上传失败");
        }else {
            return Result.success(filePathConfig.getServerPath() + "/" + path);
            return Result.success(filePathConfig.getServerPath() + uuid + "/" + path);
        }
    }

+ 9 - 17
src/main/java/com/yihu/hos/system/controller/FlowController.java

@ -3,6 +3,8 @@ package com.yihu.hos.system.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.hos.common.constants.Constants;
import com.yihu.hos.config.FilePathConfig;
import com.yihu.hos.core.datatype.DateUtil;
import com.yihu.hos.core.datatype.StringUtil;
import com.yihu.hos.system.model.SystemServiceFlow;
import com.yihu.hos.system.model.SystemServiceFlowClass;
import com.yihu.hos.system.model.SystemServiceFlowTemp;
@ -24,10 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 *  流程管理
@ -200,22 +199,14 @@ public class FlowController extends BaseController {
    public Object upload(@RequestParam MultipartFile file,HttpServletRequest request
    ) {
        //TODO 文件地址设置
        String packageName = request.getParameter("packageName");
        String className =  request.getParameter("className");
        StringBuilder basePath = new StringBuilder(camelFile + File.separator );;
        if (packageName!=null){
            String packagePath[] = packageName.split("\\.");
            for (int i=0;i<packagePath.length;i++){
                basePath.append(packagePath[i]).append(File.separator);
            }
        }
        UUID uuid = UUID.randomUUID();
        StringBuilder basePath = new StringBuilder(camelFile + uuid + "/");
        String path = flowManage.uploadFile(file, basePath.toString());
        if (StringUtils.isEmpty(path)){
            return Result.error("上传失败");
        }else {
            return Result.success(basePath.toString()+ "/" +path);
            return Result.success(basePath.toString() + path);
        }
    }
@ -224,13 +215,14 @@ public class FlowController extends BaseController {
    public Object uploadImg(@RequestParam MultipartFile file,HttpServletRequest request
    ) {
        //TODO 文件地址设置
        String basePath = filePathConfig.getFilePath();
        UUID uuid = UUID.randomUUID();
        String basePath = filePathConfig.getFilePath() + uuid + "/";
        String path = flowManage.uploadFile(file, basePath);
        if (StringUtils.isEmpty(path)){
            return Result.error("上传失败");
        }else {
            return Result.success(filePathConfig.getServerPath() + "/" + path);
            return Result.success(filePathConfig.getServerPath() + uuid + "/" + path);
        }
    }

+ 3 - 2
src/main/java/com/yihu/hos/system/service/FlowManager.java

@ -142,6 +142,7 @@ public class FlowManager implements IFlowManage {
                        sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_DELETE);
                    } else {
                        flowClassRoute = flowClass;
                        flowClassRoute.setIsUpdate("1");
                        oper = Constants.FLOW_OP_DELETE;
                    }
                }
@ -171,6 +172,7 @@ public class FlowManager implements IFlowManage {
                sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_DELETE);
            } else {
                flowClassRoute = flowClass;
                flowClassRoute.setIsUpdate("1");
                oper = Constants.FLOW_OP_DELETE;
            }
        }
@ -265,7 +267,7 @@ public class FlowManager implements IFlowManage {
                case "update" : serviceFlowEventService.routeDefineChanged(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
                default : break;
            }
        } else if ( "1".equals(flowClass.getIsUpdate()) && Constants.FLOW_TYPE_PROCESSOR.equals(flowClass.getType())) {
        } else if ("1".equals(flowClass.getIsUpdate()) && Constants.FLOW_TYPE_PROCESSOR.equals(flowClass.getType())) {
            //processor
            switch (operate){
                case "add" : serviceFlowEventService.processorAdded(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
@ -276,7 +278,6 @@ public class FlowManager implements IFlowManage {
        }
    }
    /**
     * 获取流程列表
     * @param type 流程的文件类型

+ 8 - 8
src/main/resources/application.yml

@ -38,9 +38,9 @@ esb:
  camelFile: D:\
upload:
  file:
    path: D:\code\newHealth\new-esb\esb\src\main\webapp
    path: D:\code\newHealth\new-esb\esb\src\main\webapp\
  server:
    path: http://localhost:8080/esb
    path: http://localhost:8080/esb/
---
spring:
@ -63,9 +63,9 @@ esb:
  camelFile: usr/local/esb/
upload:
  file:
    path: /usr/local/esb/file/webapps/ROOT
    path: /usr/local/esb/file/webapps/ROOT/
  server:
    path: http://172.19.103.89:8081
    path: http://172.19.103.89:8081/
#  data:
#    mongodb:
#      host: 172.19.103.86
@ -94,9 +94,9 @@ spring:
    pooled: false
upload:
  file:
    path: /usr/local/esb/file/webapps/ROOT
    path: /usr/local/esb/file/webapps/ROOT/
  server:
    path: http://172.19.103.89:8081
    path: http://172.19.103.89:8081/
---
spring:
  profiles: hzy
@ -115,6 +115,6 @@ spring:
    pooled: false
upload:
  file:
    path: /usr/local/esb/file/webapps/ROOT
    path: /usr/local/esb/file/webapps/ROOT/
  server:
    path: http://172.19.103.89:8081
    path: http://172.19.103.89:8081/