浏览代码

okHttpClient 超时设置

demon 8 年之前
父节点
当前提交
788dbf10e6

+ 40 - 6
hos-broker/src/main/java/com/yihu/hos/common/compiler/CamelCompiler.java

@ -3,7 +3,6 @@
package com.yihu.hos.common.compiler;
import com.yihu.hos.core.file.FileUtil;
import org.apache.commons.io.FileUtils;
import javax.tools.*;
import java.io.File;
@ -77,16 +76,22 @@ public class CamelCompiler {
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null,  Charset.forName("UTF-8"));
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
        File file = new File(filePath);
        File toFIle = new File(newPath);
        if (file.exists()){
//        File file = new File(filePath);
//        File toFIle = new File(newPath);
        String text = FileUtil.readFileText(new File(filePath));
        File fPath = new File(packagePathTemplate+packageName);
        if (!fPath.exists()) fPath.mkdirs();
        File toFIle = genProcessor(filePath,packageName,oldClassName);
        if (toFIle.exists()){
            if (!toFIle.getParentFile().exists()) toFIle.getParentFile().mkdirs();
            //复制
            FileUtils.copyFile(file, toFIle);
//            FileUtils.copyFile(file, toFIle);
            if (toFIle!=null){
                Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(toFIle.getAbsolutePath());
                // options命令行选项
                Iterable<String> options = Arrays.asList("-d",classPath);// 指定的路径一定要存在,javac不会自己创建文件夹
                Iterable<String> options = Arrays.asList("-d",classPath,"-sourcepath", classPath);// 指定的路径一定要存在,javac不会自己创建文件夹
                JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
                // 编译源程序
@ -153,6 +158,35 @@ public class CamelCompiler {
    }
    public static File genProcessor(String filePath,String packageName,String newClassName) {
        try {
//            String oldPath = String.format(classPathTemplate, packageName, oldClassName);
            String newPath = String.format(classPathTemplate, packageName, newClassName);
            String text = FileUtil.readFileText(new File(filePath));
            File fPath = new File(packagePathTemplate+packageName);
            if (!fPath.exists()) fPath.mkdirs();
            File f = new File(newPath);
            FileWriter fw = new FileWriter(f);
            fw.write(text);
            fw.flush();
            fw.close();//这里只是产生一个JAVA文件,简单的IO操作
            return f;
        }
        catch (Exception e) {
            System.out.println("复制文件操作出错");
            e.printStackTrace();
        }
        return null;
    }
    public static void compiler2(String packageName,String className) throws IOException {
        String classPath = CamelCompiler.class.getProtectionDomain().getCodeSource().getLocation().getPath() ;
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

+ 2 - 1
hos-core/src/main/java/com/yihu/hos/core/http/DefaultClientImpl.java

@ -9,6 +9,7 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
 * @created Airhead 2016/8/24.
@ -39,7 +40,7 @@ class DefaultClientImpl implements HTTPClient {
            Request request = builder
                    .url(formatURL(url, params))
                    .build();
            httpClient.newBuilder().connectTimeout(60, TimeUnit.SECONDS);
            Response response = httpClient.newCall(request).execute();
            if (response.isSuccessful()) {
                return new HTTPResponse(response.code(), response.body().string());

+ 49 - 38
src/main/java/com/yihu/hos/system/service/FlowManager.java

@ -345,7 +345,9 @@ public class FlowManager implements IFlowManage {
            //新增processor记录
            int sum = 0;
            for (SystemServiceFlowTemp process:flowClassProces){
//                String newProcessName = process.getClassName()+timestamp;
                String newProcessPath = null;
                StringBuilder proPath =  new StringBuilder( );;
@ -369,54 +371,63 @@ public class FlowManager implements IFlowManage {
                    boolean succ = (boolean) body.get("successFlg");
                    if (succ){
                        newProcessPath = body.get("message").toString();
                        System.out.println(response.getBody());
                        SystemServiceFlowClass processClass = new SystemServiceFlowClass();
                        processClass.setPackageName(process.getPackageName());
                        processClass.setClassName(process.getClassName());
                        processClass.setClassPath(newProcessPath);
                        processClass.setFlowId(newFlow.getId());
                        processClass.setType(Constants.FLOW_TYPE_PROCESSOR);
                        flowClassDao.saveEntity(processClass);
                        processClass.setIsUpdate("1");
                        sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
                        sum++;
//                copyProcessor(process.getClassPath(),proPath.toString(),process.getClassName());
                    }else {
                        return null;
                    }
                }else {
                    return null;
                }
                System.out.println(response.getBody());
                SystemServiceFlowClass processClass = new SystemServiceFlowClass();
                processClass.setPackageName(process.getPackageName());
                processClass.setClassName(process.getClassName());
                processClass.setClassPath(newProcessPath);
                processClass.setFlowId(newFlow.getId());
                processClass.setType(Constants.FLOW_TYPE_PROCESSOR);
                flowClassDao.saveEntity(processClass);
                processClass.setIsUpdate("1");
                sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
//                copyProcessor(process.getClassPath(),proPath.toString(),process.getClassName());
            }
            String newClassName = flowTemp.getClassName()+timestamp;
            String newRoutePath =null;
            params = new HashMap<>();
            params.put("type",Constants.FLOW_TYPE_ROUTE);
            params.put("filePath", flowTemp.getClassPath());
            params.put("packageName", basePath.toString());
            params.put("oldClassName", flowTemp.getClassName());
            params.put("newClassName",newClassName);//原文件名加当前时间戳
            params.put("newCron",newCron);
            HTTPResponse response  = HttpClientKit.post(genCamelUrl, params);
            if (response.getStatusCode()==200 ){
                Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
                boolean succ = (boolean) body.get("successFlg");
                if (succ){
                    newRoutePath = body.get("message").toString();
            if (sum == flowClassProces.size()){
                String newClassName = flowTemp.getClassName()+timestamp;
                String newRoutePath =null;
                params = new HashMap<>();
                params.put("type",Constants.FLOW_TYPE_ROUTE);
                params.put("filePath", flowTemp.getClassPath());
                params.put("packageName", basePath.toString());
                params.put("oldClassName", flowTemp.getClassName());
                params.put("newClassName",newClassName);//原文件名加当前时间戳
                params.put("newCron",newCron);
                HTTPResponse response  = HttpClientKit.post(genCamelUrl, params);
                if (response.getStatusCode()==200 ){
                    Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
                    boolean succ = (boolean) body.get("successFlg");
                    if (succ){
                        newRoutePath = body.get("message").toString();
                    }else {
                        return null;
                    }
                    System.out.println(response.getBody());
                    SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
                    newFlowClass.setPackageName(flowTemp.getPackageName());
                    newFlowClass.setClassName(newClassName);
                    newFlowClass.setClassPath(newRoutePath);
                    newFlowClass.setFlowId(newFlow.getId());
                    newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
                    flowClassDao.saveEntity(newFlowClass);
                    newFlowClass.setIsUpdate("1");
                    sendUpdateMessage(newFlow.getCode(), newFlowClass, Constants.FLOW_OP_ADD);
                }else {
                    return null;
                }
            }else {
                System.out.println("生成processoer过程失败");
                return null;
            }
            System.out.println(response.getBody());
            SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
            newFlowClass.setPackageName(flowTemp.getPackageName());
            newFlowClass.setClassName(newClassName);
            newFlowClass.setClassPath(newRoutePath);
            newFlowClass.setFlowId(newFlow.getId());
            newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
            flowClassDao.saveEntity(newFlowClass);
            newFlowClass.setIsUpdate("1");
            sendUpdateMessage(newFlow.getCode(), newFlowClass, Constants.FLOW_OP_ADD);
//            genNewRoutefile(flowTemp.getClassPath(),basePath.toString(),flowTemp.getClassName(),newClassName,newCron);
            return newFlow.getId();