parent
30350e2f2d
commit
88fd7764be
11
pom.xml
11
pom.xml
|
@ -113,9 +113,14 @@
|
||||||
<version>1.3.2</version>
|
<version>1.3.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-httpclient</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>commons-httpclient</artifactId>
|
<artifactId>httpclient</artifactId>
|
||||||
<version>3.1</version>
|
<version>4.5.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpmime</artifactId>
|
||||||
|
<version>4.5.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
|
|
|
@ -275,4 +275,9 @@ public class PublicConst {
|
||||||
* 用户角色管理权限码 修改用户角色
|
* 用户角色管理权限码 修改用户角色
|
||||||
*/
|
*/
|
||||||
public static final String AUTHUSERROLEMOD="role_3";
|
public static final String AUTHUSERROLEMOD="role_3";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*默认客户端端口号
|
||||||
|
*/
|
||||||
|
public static final String CLIENTPORT="6633";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package luckyweb.seagull.quartz;
|
package luckyweb.seagull.quartz;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.rmi.Naming;
|
|
||||||
import java.rmi.RemoteException;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import org.apache.http.conn.HttpHostConnectException;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hibernate.Query;
|
import org.hibernate.Query;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
|
@ -15,6 +16,8 @@ import org.quartz.Job;
|
||||||
import org.quartz.JobExecutionContext;
|
import org.quartz.JobExecutionContext;
|
||||||
import org.quartz.JobExecutionException;
|
import org.quartz.JobExecutionException;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
import luckyweb.seagull.comm.PublicConst;
|
import luckyweb.seagull.comm.PublicConst;
|
||||||
import luckyweb.seagull.comm.QueueListener;
|
import luckyweb.seagull.comm.QueueListener;
|
||||||
import luckyweb.seagull.spring.entity.TestClient;
|
import luckyweb.seagull.spring.entity.TestClient;
|
||||||
|
@ -25,10 +28,10 @@ import luckyweb.seagull.spring.service.TestTastExcuteService;
|
||||||
import luckyweb.seagull.util.DateUtil;
|
import luckyweb.seagull.util.DateUtil;
|
||||||
import luckyweb.seagull.util.HibernateSessionFactoryUtil;
|
import luckyweb.seagull.util.HibernateSessionFactoryUtil;
|
||||||
import luckyweb.seagull.util.StrLib;
|
import luckyweb.seagull.util.StrLib;
|
||||||
import rmi.model.RunBatchCaseEntity;
|
import luckyweb.seagull.util.client.HttpRequest;
|
||||||
import rmi.model.RunCaseEntity;
|
import luckyweb.seagull.util.client.RunBatchCaseEntity;
|
||||||
import rmi.model.RunTaskEntity;
|
import luckyweb.seagull.util.client.RunCaseEntity;
|
||||||
import rmi.service.RunService;
|
import luckyweb.seagull.util.client.RunTaskEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
|
@ -82,9 +85,8 @@ public class QuartzJob implements Job {
|
||||||
if(null!=tc){
|
if(null!=tc){
|
||||||
String clientip=tc.getClientip();
|
String clientip=tc.getClientip();
|
||||||
try{
|
try{
|
||||||
//调用远程对象,注意RMI路径与接口必须与服务器配置一致
|
Map<String, Object> params = new HashMap<String, Object>(0);
|
||||||
RunService service=(RunService)Naming.lookup("rmi://"+clientip+":6633/RunService");
|
String result=HttpRequest.httpClientGet("http://"+clientip+":"+PublicConst.CLIENTPORT+"/getclientstatus", params);
|
||||||
String result=service.getClientStatus();
|
|
||||||
if("success".equals(result)){
|
if("success".equals(result)){
|
||||||
if(tc.getStatus()!=0){
|
if(tc.getStatus()!=0){
|
||||||
tc.setStatus(0);
|
tc.setStatus(0);
|
||||||
|
@ -102,7 +104,7 @@ public class QuartzJob implements Job {
|
||||||
log.error("【IP:"+tc.getClientip()+"】客户端异常,修改客户端状态!");
|
log.error("【IP:"+tc.getClientip()+"】客户端异常,修改客户端状态!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (RemoteException e) {
|
}catch (HttpHostConnectException e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
log.error("【IP:"+tc.getClientip()+"】检查客户端异常(RemoteException)!");
|
log.error("【IP:"+tc.getClientip()+"】检查客户端异常(RemoteException)!");
|
||||||
if(tc.getStatus()!=1){
|
if(tc.getStatus()!=1){
|
||||||
|
@ -138,16 +140,15 @@ public class QuartzJob implements Job {
|
||||||
projname = projname.replaceAll(" ","\" \"");
|
projname = projname.replaceAll(" ","\" \"");
|
||||||
String result="启动失败!";
|
String result="启动失败!";
|
||||||
try{
|
try{
|
||||||
//调用远程对象,注意RMI路径与接口必须与服务器配置一致
|
|
||||||
RunService service=(RunService)Naming.lookup("rmi://"+clientip+":6633/RunService");
|
|
||||||
|
|
||||||
RunTaskEntity tasken = new RunTaskEntity();
|
RunTaskEntity tasken = new RunTaskEntity();
|
||||||
tasken.setProjectname(projname);
|
tasken.setProjectname(projname);
|
||||||
tasken.setTaskid(String.valueOf(task.getId()));
|
tasken.setTaskid(String.valueOf(task.getId()));
|
||||||
if(StrLib.isEmpty(loadpath)){
|
if(StrLib.isEmpty(loadpath)){
|
||||||
loadpath="/TestDriven";
|
loadpath="/TestDriven";
|
||||||
}
|
}
|
||||||
result=service.runtask(tasken,loadpath);
|
tasken.setLoadpath(loadpath);
|
||||||
|
String taskjson=JSONObject.toJSONString(tasken);
|
||||||
|
result=HttpRequest.httpClientPost("http://"+clientip+":"+PublicConst.CLIENTPORT+"/runtask", taskjson);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
return result;
|
return result;
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
@ -162,8 +163,6 @@ public class QuartzJob implements Job {
|
||||||
public String toRunCase(String projname,int tastId,String caseName,String casVersion,String clientip,String loadpath) {
|
public String toRunCase(String projname,int tastId,String caseName,String casVersion,String clientip,String loadpath) {
|
||||||
String result="启动失败!";
|
String result="启动失败!";
|
||||||
try{
|
try{
|
||||||
//调用远程对象,注意RMI路径与接口必须与服务器配置一致
|
|
||||||
RunService service=(RunService)Naming.lookup("rmi://"+clientip+":6633/RunService");
|
|
||||||
RunCaseEntity onecase = new RunCaseEntity();
|
RunCaseEntity onecase = new RunCaseEntity();
|
||||||
onecase.setProjectname(projname);
|
onecase.setProjectname(projname);
|
||||||
onecase.setTaskid(String.valueOf(tastId));
|
onecase.setTaskid(String.valueOf(tastId));
|
||||||
|
@ -172,7 +171,9 @@ public class QuartzJob implements Job {
|
||||||
if(StrLib.isEmpty(loadpath)){
|
if(StrLib.isEmpty(loadpath)){
|
||||||
loadpath="/TestDriven";
|
loadpath="/TestDriven";
|
||||||
}
|
}
|
||||||
result=service.runcase(onecase,loadpath);
|
onecase.setLoadpath(loadpath);
|
||||||
|
String casejson=JSONObject.toJSONString(onecase);
|
||||||
|
result=HttpRequest.httpClientPost("http://"+clientip+":"+PublicConst.CLIENTPORT+"/runcase", casejson);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -186,8 +187,6 @@ public class QuartzJob implements Job {
|
||||||
public String toRunCaseBatch(String projname,int taskid,String caseInfo,String clientip,String loadpath) {
|
public String toRunCaseBatch(String projname,int taskid,String caseInfo,String clientip,String loadpath) {
|
||||||
String result="启动失败!";
|
String result="启动失败!";
|
||||||
try{
|
try{
|
||||||
//调用远程对象,注意RMI路径与接口必须与服务器配置一致
|
|
||||||
RunService service=(RunService)Naming.lookup("rmi://"+clientip+":6633/RunService");
|
|
||||||
RunBatchCaseEntity batchcase = new RunBatchCaseEntity();
|
RunBatchCaseEntity batchcase = new RunBatchCaseEntity();
|
||||||
batchcase.setProjectname(projname);
|
batchcase.setProjectname(projname);
|
||||||
batchcase.setTaskid(String.valueOf(taskid));
|
batchcase.setTaskid(String.valueOf(taskid));
|
||||||
|
@ -195,7 +194,9 @@ public class QuartzJob implements Job {
|
||||||
if(StrLib.isEmpty(loadpath)){
|
if(StrLib.isEmpty(loadpath)){
|
||||||
loadpath="/TestDriven";
|
loadpath="/TestDriven";
|
||||||
}
|
}
|
||||||
result=service.runbatchcase(batchcase,loadpath);
|
batchcase.setLoadpath(loadpath);
|
||||||
|
String batchcasejson=JSONObject.toJSONString(batchcase);
|
||||||
|
result=HttpRequest.httpClientPost("http://"+clientip+":"+PublicConst.CLIENTPORT+"/runbatchcase", batchcasejson);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -10,10 +10,11 @@ import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.rmi.Naming;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -39,7 +40,7 @@ import luckyweb.seagull.spring.service.TestJobsService;
|
||||||
import luckyweb.seagull.spring.service.TestTastExcuteService;
|
import luckyweb.seagull.spring.service.TestTastExcuteService;
|
||||||
import luckyweb.seagull.util.DateLib;
|
import luckyweb.seagull.util.DateLib;
|
||||||
import luckyweb.seagull.util.StrLib;
|
import luckyweb.seagull.util.StrLib;
|
||||||
import rmi.service.RunService;
|
import luckyweb.seagull.util.client.HttpRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
|
@ -108,9 +109,9 @@ public class LogdetailController
|
||||||
|
|
||||||
String newname = new String(fname.getBytes("ISO-8859-1"), "UTF-8");
|
String newname = new String(fname.getBytes("ISO-8859-1"), "UTF-8");
|
||||||
|
|
||||||
//调用远程对象,注意RMI路径与接口必须与服务器配置一致
|
Map<String, Object> params = new HashMap<String, Object>(0);
|
||||||
RunService service=(RunService)Naming.lookup("rmi://"+tte.getTestJob().getClientip()+":6633/RunService");
|
params.put("imgName", newname);
|
||||||
byte[] bfis=service.getlogimg(newname);
|
byte[] bfis=HttpRequest.getFile("http://"+tte.getTestJob().getClientip()+":"+PublicConst.CLIENTPORT+"/getlogimg", params);
|
||||||
|
|
||||||
String path = System.getProperty("user.dir")+"\\";
|
String path = System.getProperty("user.dir")+"\\";
|
||||||
String pathName = path + newname;
|
String pathName = path + newname;
|
||||||
|
|
|
@ -3,7 +3,6 @@ package luckyweb.seagull.spring.mvc;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.rmi.Naming;
|
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -39,7 +38,8 @@ import luckyweb.seagull.spring.service.TempCasestepDebugService;
|
||||||
import luckyweb.seagull.spring.service.TestClientService;
|
import luckyweb.seagull.spring.service.TestClientService;
|
||||||
import luckyweb.seagull.spring.service.UserInfoService;
|
import luckyweb.seagull.spring.service.UserInfoService;
|
||||||
import luckyweb.seagull.util.StrLib;
|
import luckyweb.seagull.util.StrLib;
|
||||||
import rmi.service.RunService;
|
import luckyweb.seagull.util.client.HttpRequest;
|
||||||
|
import luckyweb.seagull.util.client.WebDebugCaseEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
|
@ -266,7 +266,6 @@ public class ProjectCasestepsController {
|
||||||
rsp.setContentType("text/html;charset=utf-8");
|
rsp.setContentType("text/html;charset=utf-8");
|
||||||
req.setCharacterEncoding("utf-8");
|
req.setCharacterEncoding("utf-8");
|
||||||
PrintWriter pw = rsp.getWriter();
|
PrintWriter pw = rsp.getWriter();
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
if (!UserLoginController.permissionboolean(req, PublicConst.AUTHCASESTEPS)) {
|
if (!UserLoginController.permissionboolean(req, PublicConst.AUTHCASESTEPS)) {
|
||||||
json.put("status", "fail");
|
json.put("status", "fail");
|
||||||
|
@ -332,9 +331,15 @@ public class ProjectCasestepsController {
|
||||||
|
|
||||||
tempdebugservice.delete(casesign, usercode);
|
tempdebugservice.delete(casesign, usercode);
|
||||||
|
|
||||||
// 调用远程对象,注意RMI路径与接口必须与服务器配置一致
|
WebDebugCaseEntity debugcase = new WebDebugCaseEntity();
|
||||||
RunService service = (RunService) Naming.lookup("rmi://" + clientip + ":6633/RunService");
|
debugcase.setSign(casesign);
|
||||||
String result = service.webdebugcase(casesign, usercode,clientpath);
|
debugcase.setExecutor(usercode);
|
||||||
|
if(StrLib.isEmpty(clientpath)){
|
||||||
|
clientpath="/TestDriven";
|
||||||
|
}
|
||||||
|
debugcase.setLoadpath(clientpath);
|
||||||
|
String debugcasejson=JSONObject.toJSONString(debugcase);
|
||||||
|
String result=HttpRequest.httpClientPost("http://"+clientip+":"+PublicConst.CLIENTPORT+"/webdebugcase", debugcasejson);
|
||||||
|
|
||||||
status="success";
|
status="success";
|
||||||
ms=result;
|
ms=result;
|
||||||
|
|
|
@ -102,6 +102,7 @@ public class TestClientController {
|
||||||
for(String proid:projectids){
|
for(String proid:projectids){
|
||||||
if(!StrLib.isEmpty(proid)&&!"0".equals(proid)){
|
if(!StrLib.isEmpty(proid)&&!"0".equals(proid)){
|
||||||
SectorProjects sp = sectorprojectsService.loadob(Integer.valueOf(proid));
|
SectorProjects sp = sectorprojectsService.loadob(Integer.valueOf(proid));
|
||||||
|
if(null!=sp){
|
||||||
String projectname=sp.getProjectname();
|
String projectname=sp.getProjectname();
|
||||||
if(sp.getProjecttype()==1){
|
if(sp.getProjecttype()==1){
|
||||||
sbnames.append(projectname+"(TestLink),");
|
sbnames.append(projectname+"(TestLink),");
|
||||||
|
@ -110,6 +111,7 @@ public class TestClientController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
tct.setProjectpername(sbnames.toString());
|
tct.setProjectpername(sbnames.toString());
|
||||||
}
|
}
|
||||||
// 转换成json字符串
|
// 转换成json字符串
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
package luckyweb.seagull.spring.mvc;
|
package luckyweb.seagull.spring.mvc;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.rmi.Naming;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -53,7 +52,7 @@ import luckyweb.seagull.spring.service.UserInfoService;
|
||||||
import luckyweb.seagull.util.DateLib;
|
import luckyweb.seagull.util.DateLib;
|
||||||
import luckyweb.seagull.util.DateUtil;
|
import luckyweb.seagull.util.DateUtil;
|
||||||
import luckyweb.seagull.util.StrLib;
|
import luckyweb.seagull.util.StrLib;
|
||||||
import rmi.service.RunService;
|
import luckyweb.seagull.util.client.HttpRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
|
@ -1011,9 +1010,9 @@ public class TestJobsController
|
||||||
}
|
}
|
||||||
String result="获取日志远程链接失败!";
|
String result="获取日志远程链接失败!";
|
||||||
try{
|
try{
|
||||||
//调用远程对象,注意RMI路径与接口必须与服务器配置一致
|
Map<String, Object> params = new HashMap<String, Object>(0);
|
||||||
RunService service=(RunService)Naming.lookup("rmi://"+clientip+":6633/RunService");
|
params.put("filename", storeName);
|
||||||
result=service.getlogdetail(storeName);
|
result=HttpRequest.httpClientGet("http://"+clientip+":"+PublicConst.CLIENTPORT+"/getlogdetail", params);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return result;
|
return result;
|
||||||
|
@ -1087,7 +1086,6 @@ public class TestJobsController
|
||||||
// 文件目录
|
// 文件目录
|
||||||
String path = System.getProperty("user.dir")+"\\";
|
String path = System.getProperty("user.dir")+"\\";
|
||||||
String pathName = path + file.getOriginalFilename();
|
String pathName = path + file.getOriginalFilename();
|
||||||
System.out.println(pathName);
|
|
||||||
File targetFile = new File(pathName);
|
File targetFile = new File(pathName);
|
||||||
if (targetFile.exists()){
|
if (targetFile.exists()){
|
||||||
targetFile.delete();
|
targetFile.delete();
|
||||||
|
@ -1112,17 +1110,11 @@ public class TestJobsController
|
||||||
byte[] b = null;
|
byte[] b = null;
|
||||||
String result="获取日志远程链接失败!";
|
String result="获取日志远程链接失败!";
|
||||||
try {
|
try {
|
||||||
b = new byte[(int) targetFile.length()];
|
|
||||||
BufferedInputStream is = new BufferedInputStream(new FileInputStream(targetFile));
|
|
||||||
is.read(b);
|
|
||||||
try{
|
try{
|
||||||
//调用远程对象,注意RMI路径与接口必须与服务器配置一致
|
result=HttpRequest.httpClientUploadFile("http://"+clientip+":"+PublicConst.CLIENTPORT+"/uploadjar", clientpath, targetFile);
|
||||||
RunService service=(RunService)Naming.lookup("rmi://"+clientip+":6633/RunService");
|
|
||||||
result=service.uploadjar(b, file.getOriginalFilename(),clientpath);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
is.close();
|
|
||||||
//删除服务器上的文件
|
//删除服务器上的文件
|
||||||
if (targetFile.exists()){
|
if (targetFile.exists()){
|
||||||
targetFile.delete();
|
targetFile.delete();
|
||||||
|
|
|
@ -0,0 +1,266 @@
|
||||||
|
package luckyweb.seagull.util.client;
|
||||||
|
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.xml.bind.DatatypeConverter;
|
||||||
|
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.conn.HttpHostConnectException;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.entity.mime.MultipartEntity;
|
||||||
|
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import luckyweb.seagull.spring.entity.TestTaskexcute;
|
||||||
|
import luckyweb.seagull.spring.service.TestTastExcuteService;
|
||||||
|
|
||||||
|
public class HttpRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param urlParam
|
||||||
|
* @param jsonparams
|
||||||
|
* @return
|
||||||
|
* @throws NoSuchAlgorithmException
|
||||||
|
* @throws KeyManagementException
|
||||||
|
* @Description:使用HttpClient以JSON格式发送post请求
|
||||||
|
*/
|
||||||
|
public static String httpClientPost(String urlParam,String jsonparams) throws NoSuchAlgorithmException, KeyManagementException, HttpHostConnectException{
|
||||||
|
StringBuffer resultBuffer = null;
|
||||||
|
CloseableHttpClient httpclient=HttpClients.createDefault();
|
||||||
|
HttpPost httpPost = new HttpPost(urlParam);
|
||||||
|
httpPost.setHeader("Content-Type", "application/json");
|
||||||
|
// 构建请求参数
|
||||||
|
BufferedReader br = null;
|
||||||
|
try {
|
||||||
|
if(null!=jsonparams&&jsonparams.length()>0){
|
||||||
|
StringEntity entity = new StringEntity(jsonparams,"utf-8");
|
||||||
|
httpPost.setEntity(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseableHttpResponse response = httpclient.execute(httpPost);
|
||||||
|
|
||||||
|
// 读取服务器响应数据
|
||||||
|
resultBuffer = new StringBuffer();
|
||||||
|
if(null!=response.getEntity()){
|
||||||
|
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"));
|
||||||
|
String temp;
|
||||||
|
while ((temp = br.readLine()) != null) {
|
||||||
|
resultBuffer.append(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
if (br != null) {
|
||||||
|
try {
|
||||||
|
br.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
br = null;
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultBuffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param urlParam
|
||||||
|
* @param params
|
||||||
|
* @param charset
|
||||||
|
* @param headmsg
|
||||||
|
* @param cerpath
|
||||||
|
* @return
|
||||||
|
* @throws NoSuchAlgorithmException
|
||||||
|
* @throws KeyManagementException
|
||||||
|
* @Description:使用HttpClient以JSON格式发送get请求
|
||||||
|
*/
|
||||||
|
public static String httpClientGet(String urlParam, Map<String, Object> params) throws NoSuchAlgorithmException, KeyManagementException,HttpHostConnectException {
|
||||||
|
StringBuffer resultBuffer = null;
|
||||||
|
CloseableHttpClient httpclient=HttpClients.createDefault();
|
||||||
|
BufferedReader br = null;
|
||||||
|
// 构建请求参数
|
||||||
|
StringBuffer sbParams = new StringBuffer();
|
||||||
|
if (params != null && params.size() > 0) {
|
||||||
|
for (Entry<String, Object> entry : params.entrySet()) {
|
||||||
|
sbParams.append(entry.getKey());
|
||||||
|
sbParams.append("=");
|
||||||
|
try {
|
||||||
|
sbParams.append(URLEncoder.encode(String.valueOf(entry.getValue()), "utf-8"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
sbParams.append("&");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sbParams != null && sbParams.length() > 0) {
|
||||||
|
urlParam = urlParam + "?" + sbParams.substring(0, sbParams.length() - 1);
|
||||||
|
}
|
||||||
|
HttpGet httpGet = new HttpGet(urlParam);
|
||||||
|
try {
|
||||||
|
CloseableHttpResponse response = httpclient.execute(httpGet);
|
||||||
|
|
||||||
|
// 读取服务器响应数据
|
||||||
|
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"));
|
||||||
|
String temp;
|
||||||
|
resultBuffer = new StringBuffer();
|
||||||
|
while ((temp = br.readLine()) != null) {
|
||||||
|
resultBuffer.append(temp);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
if (br != null) {
|
||||||
|
try {
|
||||||
|
br.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
br = null;
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultBuffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String httpClientUploadFile(String urlParam, String loadpath, File file) throws NoSuchAlgorithmException, KeyManagementException, HttpHostConnectException {
|
||||||
|
StringBuffer resultBuffer = null;
|
||||||
|
CloseableHttpClient httpclient=HttpClients.createDefault();
|
||||||
|
HttpPost httpPost = new HttpPost(urlParam);
|
||||||
|
// 构建请求参数
|
||||||
|
BufferedReader br = null;
|
||||||
|
try {
|
||||||
|
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
|
||||||
|
//设置请求的编码格式
|
||||||
|
entityBuilder.setCharset(Charset.forName("utf-8"));
|
||||||
|
entityBuilder.addBinaryBody("jarfile", file);
|
||||||
|
entityBuilder.addTextBody("loadpath", loadpath);
|
||||||
|
HttpEntity reqEntity =entityBuilder.build();
|
||||||
|
httpPost.setEntity(reqEntity);
|
||||||
|
|
||||||
|
CloseableHttpResponse response = httpclient.execute(httpPost);
|
||||||
|
//从状态行中获取状态码
|
||||||
|
String responsecode = String.valueOf(response.getStatusLine().getStatusCode());
|
||||||
|
// 读取服务器响应数据
|
||||||
|
resultBuffer = new StringBuffer();
|
||||||
|
|
||||||
|
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"));
|
||||||
|
String temp;
|
||||||
|
while ((temp = br.readLine()) != null) {
|
||||||
|
resultBuffer.append(temp);
|
||||||
|
}
|
||||||
|
if(resultBuffer.length()==0){
|
||||||
|
resultBuffer.append("上传文件异常,响应码:"+responsecode);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
if (br != null) {
|
||||||
|
try {
|
||||||
|
br.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
br = null;
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultBuffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 文件 流
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static byte[] getFile(String urlParam, Map<String, Object> params) throws IOException, HttpHostConnectException{
|
||||||
|
// 构建请求参数
|
||||||
|
StringBuffer sbParams = new StringBuffer();
|
||||||
|
if (params != null && params.size() > 0) {
|
||||||
|
for (Entry<String, Object> entry : params.entrySet()) {
|
||||||
|
sbParams.append(entry.getKey());
|
||||||
|
sbParams.append("=");
|
||||||
|
try {
|
||||||
|
sbParams.append(URLEncoder.encode(String.valueOf(entry.getValue()), "utf-8"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
sbParams.append("&");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sbParams != null && sbParams.length() > 0) {
|
||||||
|
urlParam = urlParam + "?" + sbParams.substring(0, sbParams.length() - 1);
|
||||||
|
}
|
||||||
|
URL urlConet = new URL(urlParam);
|
||||||
|
HttpURLConnection con = (HttpURLConnection)urlConet.openConnection();
|
||||||
|
con.setRequestMethod("GET");
|
||||||
|
con.setConnectTimeout(4 * 1000);
|
||||||
|
InputStream inStream = con .getInputStream(); //通过输入流获取图片数据
|
||||||
|
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||||
|
byte[] buffer = new byte[2048];
|
||||||
|
int len = 0;
|
||||||
|
while( (len=inStream.read(buffer)) != -1 ){
|
||||||
|
outStream.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
inStream.close();
|
||||||
|
byte[] data = outStream.toByteArray();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
RunTaskEntity tt = new RunTaskEntity();
|
||||||
|
tt.setTaskid("10965");
|
||||||
|
tt.setProjectname("果果在明人我");
|
||||||
|
tt.setLoadpath("/test");
|
||||||
|
String aa=JSONObject.toJSONString(tt);
|
||||||
|
System.out.println(aa);
|
||||||
|
System.out.println(httpClientPost("http://localhost:16363/runtask",aa));
|
||||||
|
|
||||||
|
/* String path = System.getProperty("user.dir")+"\\";
|
||||||
|
File targetFile = new File(path+"aopalliance-1.0.jar");
|
||||||
|
System.out.println(httpClientUploadFile("http://localhost:16363/uploadjar", "\\log11", targetFile));*/
|
||||||
|
|
||||||
|
/* Map<String, Object> params = new HashMap<String, Object>(0);
|
||||||
|
params.put("imgName", "0131-044346.png");
|
||||||
|
byte[] bfis = getFile("http://localhost:16363/getlogimg", params);
|
||||||
|
String path = System.getProperty("user.dir")+"\\";
|
||||||
|
String pathName = path + "test.png";
|
||||||
|
File file = new File(pathName);
|
||||||
|
file.createNewFile();
|
||||||
|
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
|
||||||
|
os.write(bfis);
|
||||||
|
os.flush();
|
||||||
|
os.close();*/
|
||||||
|
|
||||||
|
/* Map<String, Object> params = new HashMap<String, Object>(0);
|
||||||
|
System.out.println(httpClientGet("http://localhost:16363/getclientstatus", params));*/
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package rmi.model;
|
package luckyweb.seagull.util.client;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@ -19,7 +19,14 @@ public class RunBatchCaseEntity implements Serializable {
|
||||||
private String projectname;
|
private String projectname;
|
||||||
private String taskid;
|
private String taskid;
|
||||||
private String batchcase;
|
private String batchcase;
|
||||||
|
private String loadpath;
|
||||||
|
|
||||||
|
public String getLoadpath() {
|
||||||
|
return loadpath;
|
||||||
|
}
|
||||||
|
public void setLoadpath(String loadpath) {
|
||||||
|
this.loadpath = loadpath;
|
||||||
|
}
|
||||||
public String getProjectname() {
|
public String getProjectname() {
|
||||||
return projectname;
|
return projectname;
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package rmi.model;
|
package luckyweb.seagull.util.client;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@ -20,7 +20,14 @@ public class RunCaseEntity implements Serializable {
|
||||||
private String taskid;
|
private String taskid;
|
||||||
private String testCaseExternalId;
|
private String testCaseExternalId;
|
||||||
private String version;
|
private String version;
|
||||||
|
private String loadpath;
|
||||||
|
|
||||||
|
public String getLoadpath() {
|
||||||
|
return loadpath;
|
||||||
|
}
|
||||||
|
public void setLoadpath(String loadpath) {
|
||||||
|
this.loadpath = loadpath;
|
||||||
|
}
|
||||||
public String getProjectname() {
|
public String getProjectname() {
|
||||||
return projectname;
|
return projectname;
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package rmi.model;
|
package luckyweb.seagull.util.client;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@ -18,7 +18,14 @@ public class RunTaskEntity implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private String projectname;
|
private String projectname;
|
||||||
private String taskid;
|
private String taskid;
|
||||||
|
private String loadpath;
|
||||||
|
|
||||||
|
public String getLoadpath() {
|
||||||
|
return loadpath;
|
||||||
|
}
|
||||||
|
public void setLoadpath(String loadpath) {
|
||||||
|
this.loadpath = loadpath;
|
||||||
|
}
|
||||||
public String getProjectname() {
|
public String getProjectname() {
|
||||||
return projectname;
|
return projectname;
|
||||||
}
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package luckyweb.seagull.util.client;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* =================================================================
|
||||||
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
|
* =================================================================
|
||||||
|
* 注意对象必须继承Serializable
|
||||||
|
* @author: seagull
|
||||||
|
* @date 2017年12月1日 上午9:29:40
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class WebDebugCaseEntity implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String sign;
|
||||||
|
private String executor;
|
||||||
|
private String loadpath;
|
||||||
|
|
||||||
|
public String getSign() {
|
||||||
|
return sign;
|
||||||
|
}
|
||||||
|
public void setSign(String sign) {
|
||||||
|
this.sign = sign;
|
||||||
|
}
|
||||||
|
public String getExecutor() {
|
||||||
|
return executor;
|
||||||
|
}
|
||||||
|
public void setExecutor(String executor) {
|
||||||
|
this.executor = executor;
|
||||||
|
}
|
||||||
|
public String getLoadpath() {
|
||||||
|
return loadpath;
|
||||||
|
}
|
||||||
|
public void setLoadpath(String loadpath) {
|
||||||
|
this.loadpath = loadpath;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,82 +0,0 @@
|
||||||
package rmi.service;
|
|
||||||
|
|
||||||
import java.rmi.Remote;
|
|
||||||
import java.rmi.RemoteException;
|
|
||||||
|
|
||||||
import rmi.model.RunBatchCaseEntity;
|
|
||||||
import rmi.model.RunCaseEntity;
|
|
||||||
import rmi.model.RunTaskEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* =================================================================
|
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
|
||||||
* =================================================================
|
|
||||||
* 此为远程对象调用的接口,必须继承Remote类
|
|
||||||
* @author seagull
|
|
||||||
*/
|
|
||||||
public interface RunService extends Remote {
|
|
||||||
/**
|
|
||||||
* 运行任务
|
|
||||||
* @param task
|
|
||||||
* @param loadpath
|
|
||||||
* @return
|
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
|
||||||
public String runtask(RunTaskEntity task,String loadpath) throws RemoteException;
|
|
||||||
/**
|
|
||||||
* 运行单条用例
|
|
||||||
* @param onecase
|
|
||||||
* @param loadpath
|
|
||||||
* @return
|
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
|
||||||
public String runcase(RunCaseEntity onecase,String loadpath) throws RemoteException;
|
|
||||||
/**
|
|
||||||
* 运行批量用例
|
|
||||||
* @param batchcase
|
|
||||||
* @param loadpath
|
|
||||||
* @return
|
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
|
||||||
public String runbatchcase(RunBatchCaseEntity batchcase,String loadpath) throws RemoteException;
|
|
||||||
/**
|
|
||||||
* 取客户端日志
|
|
||||||
* @param storeName
|
|
||||||
* @return
|
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
|
||||||
public String getlogdetail(String storeName) throws RemoteException;
|
|
||||||
/**
|
|
||||||
* 取客户端错误图片
|
|
||||||
* @param imgName
|
|
||||||
* @return
|
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
|
||||||
public byte[] getlogimg(String imgName) throws RemoteException;
|
|
||||||
/**
|
|
||||||
* 上传JAR包到客户端
|
|
||||||
* @param fileContent
|
|
||||||
* @param name
|
|
||||||
* @param loadpath
|
|
||||||
* @return
|
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
|
||||||
public String uploadjar(byte[] fileContent,String name,String loadpath) throws RemoteException;
|
|
||||||
/**
|
|
||||||
* WEB端远程调试用例
|
|
||||||
* @param sign
|
|
||||||
* @param executor
|
|
||||||
* @param loadpath
|
|
||||||
* @return
|
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
|
||||||
public String webdebugcase(String sign,String executor,String loadpath) throws RemoteException;
|
|
||||||
/**
|
|
||||||
* 检测客户端心跳
|
|
||||||
* @return
|
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
|
||||||
public String getClientStatus() throws RemoteException;
|
|
||||||
}
|
|
Loading…
Reference in New Issue