增加脚本支持,修改返回为resultBean
parent
55af273ea7
commit
aa3ece8336
@ -0,0 +1,11 @@
|
|||||||
|
package cn.estsh.i3plus.pojo.bsp.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description :
|
||||||
|
* @Reference :
|
||||||
|
* @Author : Castle
|
||||||
|
* @CreateDate : 2021/7/22 15:38
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
public class GroovyCommonUtil {
|
||||||
|
}
|
@ -1,147 +1,149 @@
|
|||||||
package cn.estsh.i3plus.pojo.bsp.common;
|
//package cn.estsh.i3plus.pojo.bsp.common;
|
||||||
|
//
|
||||||
import org.slf4j.Logger;
|
//import cn.estsh.i3plus.pojo.base.bean.BaseResultBean;
|
||||||
import org.slf4j.LoggerFactory;
|
//import org.slf4j.Logger;
|
||||||
|
//import org.slf4j.LoggerFactory;
|
||||||
import javax.net.ssl.*;
|
//
|
||||||
import java.io.BufferedReader;
|
//import javax.net.ssl.*;
|
||||||
import java.io.DataOutputStream;
|
//import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
//import java.io.DataOutputStream;
|
||||||
import java.net.HttpURLConnection;
|
//import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
//import java.net.HttpURLConnection;
|
||||||
import java.security.cert.CertificateException;
|
//import java.net.URL;
|
||||||
import java.security.cert.X509Certificate;
|
//import java.security.cert.CertificateException;
|
||||||
|
//import java.security.cert.X509Certificate;
|
||||||
/**
|
//
|
||||||
* @Description :
|
///**
|
||||||
* @Reference :
|
// * @Description :
|
||||||
* @Author : Castle
|
// * @Reference :
|
||||||
* @CreateDate : 2021/6/17 13:37
|
// * @Author : Castle
|
||||||
* @Modify:
|
// * @CreateDate : 2021/6/17 13:37
|
||||||
**/
|
// * @Modify:
|
||||||
public class HttpUtils {
|
// **/
|
||||||
private static Logger logger = LoggerFactory.getLogger(HttpUtils.class);
|
//public class HttpUtils {
|
||||||
|
// private static Logger logger = LoggerFactory.getLogger(HttpUtils.class);
|
||||||
// trust-https start
|
//
|
||||||
private static void trustAllHosts(HttpsURLConnection connection) {
|
// // trust-https start
|
||||||
try {
|
// private static void trustAllHosts(HttpsURLConnection connection) {
|
||||||
SSLContext sc = SSLContext.getInstance("TLS");
|
// try {
|
||||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
// SSLContext sc = SSLContext.getInstance("TLS");
|
||||||
SSLSocketFactory newFactory = sc.getSocketFactory();
|
// sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||||
|
// SSLSocketFactory newFactory = sc.getSocketFactory();
|
||||||
connection.setSSLSocketFactory(newFactory);
|
//
|
||||||
} catch (Exception e) {
|
// connection.setSSLSocketFactory(newFactory);
|
||||||
logger.error(e.getMessage(), e);
|
// } catch (Exception e) {
|
||||||
}
|
// logger.error(e.getMessage(), e);
|
||||||
connection.setHostnameVerifier(new HostnameVerifier() {
|
// }
|
||||||
@Override
|
// connection.setHostnameVerifier(new HostnameVerifier() {
|
||||||
public boolean verify(String hostname, SSLSession session) {
|
// @Override
|
||||||
return true;
|
// public boolean verify(String hostname, SSLSession session) {
|
||||||
}
|
// return true;
|
||||||
});
|
// }
|
||||||
}
|
// });
|
||||||
|
// }
|
||||||
private static final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
|
//
|
||||||
@Override
|
// private static final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
|
||||||
public X509Certificate[] getAcceptedIssuers() {
|
// @Override
|
||||||
return new X509Certificate[]{};
|
// public X509Certificate[] getAcceptedIssuers() {
|
||||||
}
|
// return new X509Certificate[]{};
|
||||||
|
// }
|
||||||
@Override
|
//
|
||||||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
// @Override
|
||||||
}
|
// public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||||
|
// }
|
||||||
@Override
|
//
|
||||||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
// @Override
|
||||||
}
|
// public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||||
}};
|
// }
|
||||||
// trust-https end
|
// }};
|
||||||
|
// // trust-https end
|
||||||
|
//
|
||||||
/**
|
//
|
||||||
* post
|
// /**
|
||||||
*
|
// * post
|
||||||
* @param url
|
// *
|
||||||
* @param timeout
|
// * @param url
|
||||||
* @param requestObj
|
// * @param timeout
|
||||||
* @return
|
// * @param requestObj
|
||||||
*/
|
// * @return
|
||||||
public static ReturnT postBody(String url, int timeout, Object requestObj) {
|
// */
|
||||||
HttpURLConnection connection = null;
|
// public static ResultBean postBody(String url, int timeout, Object requestObj) {
|
||||||
BufferedReader bufferedReader = null;
|
// HttpURLConnection connection = null;
|
||||||
try {
|
// BufferedReader bufferedReader = null;
|
||||||
// connection
|
// try {
|
||||||
URL realUrl = new URL(url);
|
// // connection
|
||||||
connection = (HttpURLConnection) realUrl.openConnection();
|
// URL realUrl = new URL(url);
|
||||||
|
// connection = (HttpURLConnection) realUrl.openConnection();
|
||||||
// trust-https
|
//
|
||||||
boolean useHttps = url.startsWith("https");
|
// // trust-https
|
||||||
if (useHttps) {
|
// boolean useHttps = url.startsWith("https");
|
||||||
HttpsURLConnection https = (HttpsURLConnection) connection;
|
// if (useHttps) {
|
||||||
trustAllHosts(https);
|
// HttpsURLConnection https = (HttpsURLConnection) connection;
|
||||||
}
|
// trustAllHosts(https);
|
||||||
|
// }
|
||||||
// connection setting
|
//
|
||||||
connection.setRequestMethod("POST");
|
// // connection setting
|
||||||
connection.setDoOutput(true);
|
// connection.setRequestMethod("POST");
|
||||||
connection.setDoInput(true);
|
// connection.setDoOutput(true);
|
||||||
connection.setUseCaches(false);
|
// connection.setDoInput(true);
|
||||||
connection.setReadTimeout(timeout * 1000);
|
// connection.setUseCaches(false);
|
||||||
connection.setConnectTimeout(3 * 1000);
|
// connection.setReadTimeout(timeout * 1000);
|
||||||
connection.setRequestProperty("connection", "Keep-Alive");
|
// connection.setConnectTimeout(3 * 1000);
|
||||||
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
// connection.setRequestProperty("connection", "Keep-Alive");
|
||||||
connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8");
|
// connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
||||||
|
// connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8");
|
||||||
// do connection
|
//
|
||||||
connection.connect();
|
// // do connection
|
||||||
|
// connection.connect();
|
||||||
// write requestBody
|
//
|
||||||
if (requestObj != null) {
|
// // write requestBody
|
||||||
String requestBody = GsonTool.toJson(requestObj);
|
// if (requestObj != null) {
|
||||||
|
// String requestBody = GsonTool.toJson(requestObj);
|
||||||
DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
|
//
|
||||||
dataOutputStream.write(requestBody.getBytes("UTF-8"));
|
// DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
|
||||||
dataOutputStream.flush();
|
// dataOutputStream.write(requestBody.getBytes("UTF-8"));
|
||||||
dataOutputStream.close();
|
// dataOutputStream.flush();
|
||||||
}
|
// dataOutputStream.close();
|
||||||
|
// }
|
||||||
// valid StatusCode
|
//
|
||||||
int statusCode = connection.getResponseCode();
|
// // valid StatusCode
|
||||||
if (statusCode != 200) {
|
// int statusCode = connection.getResponseCode();
|
||||||
|
// if (statusCode != 200) {
|
||||||
return new ReturnT<String>(ReturnT.FAIL_CODE, "rpc remoting fail, StatusCode(" + statusCode + ") invalid. for url : " + url);
|
// return ResultBean.fail("rpc remoting fail, StatusCode(" + statusCode + ") invalid. for url : " + url);
|
||||||
}
|
//// return new BaseResultBean().errorMsg("rpc remoting fail, StatusCode(" + statusCode + ") invalid. for url : " + url);
|
||||||
|
//// return new ReturnT<String>(ReturnT.FAIL_CODE, "rpc remoting fail, StatusCode(" + statusCode + ") invalid. for url : " + url);
|
||||||
// result
|
// }
|
||||||
bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
//
|
||||||
StringBuilder result = new StringBuilder();
|
// // result
|
||||||
String line;
|
// bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
// StringBuilder result = new StringBuilder();
|
||||||
result.append(line);
|
// String line;
|
||||||
}
|
// while ((line = bufferedReader.readLine()) != null) {
|
||||||
String resultJson = result.toString();
|
// result.append(line);
|
||||||
// parse returnT
|
// }
|
||||||
try {
|
// String resultJson = result.toString();
|
||||||
return GsonTool.fromJson(resultJson, ReturnT.class);
|
// // parse returnT
|
||||||
} catch (Exception e) {
|
// try {
|
||||||
logger.error("rpc remoting (url=" + url + ") response content invalid(" + resultJson + ").", e);
|
// return GsonTool.fromJson(resultJson, BaseResultBean.class);
|
||||||
return new ReturnT<String>(ReturnT.FAIL_CODE, "rpc remoting (url=" + url + ") response content invalid(" + resultJson + ").");
|
// } catch (Exception e) {
|
||||||
}
|
// logger.error("rpc remoting (url=" + url + ") response content invalid(" + resultJson + ").", e);
|
||||||
} catch (Exception e) {
|
// return ResultBean.fail("rpc remoting fail, StatusCode(" + statusCode + ") invalid. for url : " + url);
|
||||||
logger.error(e.getMessage(), e);
|
// }
|
||||||
return new ReturnT<String>(ReturnT.FAIL_CODE, "rpc remoting error(" + e.getMessage() + "), for url : " + url);
|
// } catch (Exception e) {
|
||||||
} finally {
|
// logger.error(e.getMessage(), e);
|
||||||
try {
|
// return ResultBean.fail("rpc remoting fail, error message(" + e.getMessage() + ") invalid. for url : " + url);
|
||||||
if (bufferedReader != null) {
|
// } finally {
|
||||||
bufferedReader.close();
|
// try {
|
||||||
}
|
// if (bufferedReader != null) {
|
||||||
if (connection != null) {
|
// bufferedReader.close();
|
||||||
connection.disconnect();
|
// }
|
||||||
}
|
// if (connection != null) {
|
||||||
} catch (Exception e2) {
|
// connection.disconnect();
|
||||||
logger.error(e2.getMessage(), e2);
|
// }
|
||||||
}
|
// } catch (Exception e2) {
|
||||||
}
|
// logger.error(e2.getMessage(), e2);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//}
|
@ -1,56 +1,56 @@
|
|||||||
package cn.estsh.i3plus.pojo.bsp.common;
|
//package cn.estsh.i3plus.pojo.bsp.common;
|
||||||
|
//
|
||||||
import java.io.Serializable;
|
//import java.io.Serializable;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author Castle
|
// * @author Castle
|
||||||
*/
|
// */
|
||||||
public class ReturnT<T> implements Serializable {
|
//public class ReturnT<T> implements Serializable {
|
||||||
public static final long serialVersionUID = 42L;
|
// public static final long serialVersionUID = 42L;
|
||||||
|
//
|
||||||
public static final int SUCCESS_CODE = 200;
|
// public static final int SUCCESS_CODE = 200;
|
||||||
public static final int FAIL_CODE = 500;
|
// public static final int FAIL_CODE = 500;
|
||||||
|
//
|
||||||
public static final ReturnT<String> SUCCESS = new ReturnT<String>(null);
|
// public static final ReturnT<String> SUCCESS = new ReturnT<String>(null);
|
||||||
public static final ReturnT<String> FAIL = new ReturnT<String>(FAIL_CODE, null);
|
// public static final ReturnT<String> FAIL = new ReturnT<String>(FAIL_CODE, null);
|
||||||
|
//
|
||||||
private int code;
|
// private int code;
|
||||||
private String msg;
|
// private String msg;
|
||||||
private T content;
|
// private T content;
|
||||||
|
//
|
||||||
public ReturnT(){}
|
// public ReturnT(){}
|
||||||
public ReturnT(int code, String msg) {
|
// public ReturnT(int code, String msg) {
|
||||||
this.code = code;
|
// this.code = code;
|
||||||
this.msg = msg;
|
// this.msg = msg;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public ReturnT(T content) {
|
// public ReturnT(T content) {
|
||||||
this.code = SUCCESS_CODE;
|
// this.code = SUCCESS_CODE;
|
||||||
this.content = content;
|
// this.content = content;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public int getCode() {
|
// public int getCode() {
|
||||||
return code;
|
// return code;
|
||||||
}
|
// }
|
||||||
public void setCode(int code) {
|
// public void setCode(int code) {
|
||||||
this.code = code;
|
// this.code = code;
|
||||||
}
|
// }
|
||||||
public String getMsg() {
|
// public String getMsg() {
|
||||||
return msg;
|
// return msg;
|
||||||
}
|
// }
|
||||||
public void setMsg(String msg) {
|
// public void setMsg(String msg) {
|
||||||
this.msg = msg;
|
// this.msg = msg;
|
||||||
}
|
// }
|
||||||
public T getContent() {
|
// public T getContent() {
|
||||||
return content;
|
// return content;
|
||||||
}
|
// }
|
||||||
public void setContent(T content) {
|
// public void setContent(T content) {
|
||||||
this.content = content;
|
// this.content = content;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public String toString() {
|
// public String toString() {
|
||||||
return "ReturnT [code=" + code + ", msg=" + msg + ", content=" + content + "]";
|
// return "ReturnT [code=" + code + ", msg=" + msg + ", content=" + content + "]";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package cn.estsh.i3plus.pojo.bsp.server.bean.model;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description :路由参数
|
||||||
|
* @Reference :
|
||||||
|
* @Author : Castle
|
||||||
|
* @CreateDate : 2021/7/5 14:02
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
@ApiModel("路由参数")
|
||||||
|
public class RouteParam {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "执行方法Id")
|
||||||
|
private Long methodId;
|
||||||
|
@ApiModelProperty(value = "路由的权重配置")
|
||||||
|
private HashMap<String,Integer> weightConfig;
|
||||||
|
@ApiModelProperty(value = "执行器地址列表")
|
||||||
|
private List<String> addressList;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package cn.estsh.i3plus.pojo.bsp.server.repository;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.pojo.base.jpa.dao.BaseRepository;
|
||||||
|
import cn.estsh.i3plus.pojo.bsp.client.bean.po.EngineScriptPersistence;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description :
|
||||||
|
* @Reference :
|
||||||
|
* @Author : Castle
|
||||||
|
* @CreateDate : 2021/7/22 13:51
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
public interface ScriptRepository extends BaseRepository<EngineScriptPersistence,Long> {
|
||||||
|
}
|
Loading…
Reference in New Issue