优化与服务端通信使用HTTP协议

优化启动服务使用springboot
优化部分配置项
This commit is contained in:
seagull 2018-07-31 15:03:29 +08:00
parent 420d212bd5
commit 606b14c501
15 changed files with 481 additions and 421 deletions

29
pom.xml
View File

@ -15,7 +15,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
@ -64,7 +63,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-sh</id>
@ -85,6 +83,7 @@
<include>**/*.exe</include>
<include>**/*.conf</include>
<include>**/*.sh</include>
<include>**/*.txt</include>
<include>**/*.properties</include>
</includes>
</resource>
@ -93,9 +92,21 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>GBK</project.build.sourceEncoding>
</properties>
@ -104,7 +115,6 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
@ -135,7 +145,6 @@
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
@ -170,7 +179,6 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
@ -205,7 +213,6 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
<dependency>
<groupId>br.eti.kinoshita</groupId>
@ -225,17 +232,14 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
@ -245,7 +249,6 @@
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.26-incubating</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
@ -255,7 +258,6 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
@ -265,7 +267,10 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,2 @@
spring.application.name = LuckyFrameClient
server.port = 6633

View File

@ -0,0 +1,12 @@
__ _ ___
/ / _ _ ___| | ___ _ / __\ __ __ _ _ __ ___ ___
/ / | | | |/ __| |/ / | | |/ _\| '__/ _` | '_ ` _ \ / _ \
/ /__| |_| | (__| <| |_| / / | | | (_| | | | | | | __/
\____/\__,_|\___|_|\_\\__, \/ |_| \__,_|_| |_| |_|\___|
|___/
+-+-+-+-+ +-+-+-+-+ +-+-+-+-+-+-+-+
|V|2|.|7| |B|e|t|a| |R|e|l|e|a|s|e|
+-+-+-+-+ +-+-+-+-+ +-+-+-+-+-+-+-+

View File

@ -1,5 +1,3 @@
title 【LuckyFrame客户端监听程序,请保持开启状态】
set classpath=%CLASSPATH%;.\luckyclient;
@echo 指定任务执行
@echo 项目名称 任务ID
java -Djava.ext.dirs=./lib rmi.remotingservice.Program
@echo LuckyFrameClient Is Starting....Wait A Second
java -Djava.ext.dirs=./lib springboot.RunService

View File

@ -34,7 +34,4 @@ mail.freemarker.template=/email_template/
#第三方平台推送开关 true打开 false关闭
task.push.switch=false
#第三方平台推送URL
task.push.url=localhost
#==================================RMI接口指定本地IP============================================
#当客户端存在多个网卡(如:虚拟机的网卡)那么客户端就存在多个IP此时必须指定一个实际IP地址注册RMI服务如果只有一个网卡可默认localhost
client.localhost.ip=localhost
task.push.url=localhost

View File

@ -30,7 +30,6 @@ import javax.net.ssl.TrustManagerFactory;
import javax.xml.bind.DatatypeConverter;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;

View File

@ -1,42 +0,0 @@
package rmi.remotingservice;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.util.Properties;
import rmi.service.RunService;
import rmi.serviceimpl.RunServiceImpl;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class Program{
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Properties properties= luckyclient.publicclass.SysConfig.getConfiguration();
String localhostip=properties.getProperty("client.localhost.ip");
if(!"localhost".toLowerCase().equals(localhostip)){
System.setProperty("java.rmi.server.hostname", localhostip);
}
RunService runService=new RunServiceImpl();
//注册通讯端口
LocateRegistry.createRegistry(6633);
//注册通讯路径
Naming.rebind("rmi://"+localhostip+":6633/RunService", runService);
System.out.println("启动客户端监听...IP:"+localhostip+" 端口:6633");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -1,84 +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
* @date 2017年12月1日 上午9:29:40
*
*/
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;
}

View File

@ -1,271 +0,0 @@
package rmi.serviceimpl;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import rmi.model.RunBatchCaseEntity;
import rmi.model.RunCaseEntity;
import rmi.model.RunTaskEntity;
import rmi.service.RunService;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* 此为远程对象的实现类须继承UnicastRemoteObject
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class RunServiceImpl extends UnicastRemoteObject implements RunService{
/**
*
*/
private static final long serialVersionUID = 1L;
public RunServiceImpl() throws RemoteException {
super();
// TODO Auto-generated constructor stub
}
@Override
public String runtask(RunTaskEntity task,String loadpath) throws RemoteException {
// TODO Auto-generated method stub
System.out.println("启动任务模式测试程序...测试项目:"+task.getProjectname()+" 任务ID"+task.getTaskid());
try{
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
System.out.println("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
StringBuffer sb=new StringBuffer();
sb.append(task.getTaskid()).append(" ");
sb.append(loadpath);
run.exec("cmd.exe /k start " + "task.cmd" +" "+ sb.toString(), null,new File(System.getProperty("user.dir")+"\\"));
} catch (Exception e) {
e.printStackTrace();
return "启动任务模式测试程序异常!!!";
}
return "启动任务模式测试程序正常";
}
@Override
public String runcase(RunCaseEntity onecase,String loadpath) throws RemoteException {
// TODO Auto-generated method stub
System.out.println("启动单用例模式测试程序...测试项目:"+onecase.getProjectname()+" 任务ID"+onecase.getTaskid());
System.out.println("测试用例编号:"+onecase.getTestCaseExternalId()+" 用例版本:"+onecase.getVersion());
try{
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
System.out.println("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
StringBuffer sb=new StringBuffer();
sb.append(onecase.getTaskid()).append(" ");
sb.append(onecase.getTestCaseExternalId()).append(" ");
sb.append(onecase.getVersion()).append(" ");
sb.append(loadpath);
run.exec("cmd.exe /k start " + "task_onecase.cmd" + " " +sb.toString(), null,new File(System.getProperty("user.dir")+"\\"));
} catch (Exception e) {
e.printStackTrace();
return "启动单用例模式测试程序异常!!!";
}
return "启动单用例模式测试程序正常";
}
@Override
public String runbatchcase(RunBatchCaseEntity batchcase,String loadpath) throws RemoteException {
// TODO Auto-generated method stub
System.out.println("启动批量用例模式测试程序...测试项目:"+batchcase.getProjectname()+" 任务ID"+batchcase.getTaskid());
System.out.println("批量测试用例:"+batchcase.getBatchcase());
try{
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
System.out.println("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
StringBuffer sb=new StringBuffer();
sb.append(batchcase.getTaskid()).append(" ");
sb.append(batchcase.getBatchcase()).append(" ");
sb.append(loadpath);
System.out.println(sb.toString());
run.exec("cmd.exe /k start " + "task_batch.cmd" + " " +sb.toString(), null,new File(System.getProperty("user.dir")+"\\"));
} catch (Exception e) {
e.printStackTrace();
return "启动批量用例模式测试程序异常!!!";
}
return "启动批量用例模式测试程序正常";
}
@Override
public String webdebugcase(String sign,String executor,String loadpath) throws RemoteException {
// TODO Auto-generated method stub
System.out.println("Web端调试用例"+sign+" 发起人:"+executor);
try{
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
System.out.println("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
StringBuffer sb=new StringBuffer();
sb.append(sign).append(" ");
sb.append(executor).append(" ");
sb.append(loadpath);
run.exec("cmd.exe /k start " + "web_debugcase.cmd" + " " +sb.toString(), null,new File(System.getProperty("user.dir")+"\\"));
} catch (Exception e) {
e.printStackTrace();
return "启动Web调试模式测试程序异常";
}
return "启动Web调试模式测试程序正常";
}
/**
* 获取客户端日志
*
* @param request
* @param response
* @param storeName
* @param contentType
* @param realName
* @throws Exception
*/
@Override
public String getlogdetail(String storeName) throws RemoteException{
BufferedReader bos = null;
String ctxPath = System.getProperty("user.dir")+"\\log\\";
String downLoadPath = ctxPath + storeName;
String str = "";
InputStreamReader isr=null;
try {
isr = new InputStreamReader(new FileInputStream(downLoadPath), "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "读取日志路径错误,请检查客户端日志路径是否存在!downLoadPath: "+downLoadPath;
}
bos = new BufferedReader(isr);
StringBuffer sb = new StringBuffer();
try {
while ((str = bos.readLine()) != null)
{
sb.append(str).append("\n");
}
bos.close();
System.out.println("服务端读取本地日志成功!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "客户端转BufferedReader失败请检查原因";
}
return sb.toString();
}
/**
* 获取客户端截图
*
* @param request
* @param response
* @param storeName
* @param contentType
* @param realName
* @throws Exception
*/
@Override
public byte[] getlogimg(String imgName) throws RemoteException{
String ctxPath = System.getProperty("user.dir")+"\\log\\ScreenShot\\";
String downLoadPath = ctxPath+imgName;
byte[] b = null;
try {
File file = new File(downLoadPath);
b = new byte[(int) file.length()];
BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
is.read(b);
is.close();
System.out.println("服务端获取本地图片:"+downLoadPath);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return b;
}
/**
* 上传JAR包
*
* @param request
* @param response
* @param storeName
* @param contentType
* @param realName
* @throws Exception
*/
@Override
public String uploadjar(byte[] fileContent,String name,String loadpath) throws RemoteException{
String path = System.getProperty("user.dir")+loadpath;
if (!new File(path) .isDirectory())
{
System.out.println("客户端测试驱动桩路径不存在,请检查【"+path+"");
return "客户端测试驱动桩路径不存在,请检查【"+path+"";
}
String pathName = path +"\\"+ name;
File file = new File(pathName);
try {
if (file.exists()){
file.deleteOnExit();
}
file.createNewFile();
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
os.write(fileContent);
os.flush();
os.close();
System.out.println("服务端上传JAR包("+name+")到本地客户端lib目录成功!");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "客户端未找到正确路径或文件,上传失败!";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "客户端IOException";
}
return "上传"+name+"至客户端成功!";
}
@Override
public String getClientStatus() throws RemoteException{
return "success";
}
public static void main(String[] args) throws RemoteException {
}
}

View File

@ -0,0 +1,354 @@
package springboot;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.rmi.RemoteException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSONObject;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @author seagull
* @date 2018年7月27日 上午10:28:32
*/
@RestController
public class HttpImpl {
/**
* 运行自动化任务
* @param req
* @param res
* @return
* @throws RemoteException
*/
@PostMapping("/runtask")
public String runtask(HttpServletRequest req) throws RemoteException {
StringBuilder sb = new StringBuilder();
try (BufferedReader reader = req.getReader();) {
char[] buff = new char[1024];
int len;
while ((len = reader.read(buff)) != -1) {
sb.append(buff, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
}
JSONObject jsonObject = JSONObject.parseObject(sb.toString());
String projectname = jsonObject.getString("projectname");
String taskid = jsonObject.getString("taskid");
String loadpath = jsonObject.getString("loadpath");
System.out.println("启动任务模式测试程序...测试项目:"+projectname+" 任务ID"+taskid);
try{
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
System.out.println("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
StringBuffer sbf=new StringBuffer();
sbf.append(taskid).append(" ");
sbf.append(loadpath);
run.exec("cmd.exe /k start " + "task.cmd" +" "+ sbf.toString(), null,new File(System.getProperty("user.dir")+"\\"));
} catch (Exception e) {
e.printStackTrace();
return "启动任务模式测试程序异常!!!";
}
return "启动任务模式测试程序正常";
}
/**
* 运行单个用例
* @param req
* @param res
* @return
* @throws RemoteException
*/
@PostMapping("/runcase")
public String runcase(HttpServletRequest req) throws RemoteException {
StringBuilder sbd = new StringBuilder();
try (BufferedReader reader = req.getReader();) {
char[] buff = new char[1024];
int len;
while ((len = reader.read(buff)) != -1) {
sbd.append(buff, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
}
JSONObject jsonObject = JSONObject.parseObject(sbd.toString());
String projectname = jsonObject.getString("projectname");
String taskid = jsonObject.getString("taskid");
String loadpath = jsonObject.getString("loadpath");
String testCaseExternalId = jsonObject.getString("testCaseExternalId");
String version = jsonObject.getString("version");
System.out.println("启动单用例模式测试程序...测试项目:"+projectname+" 任务ID"+taskid);
System.out.println("测试用例编号:"+testCaseExternalId+" 用例版本:"+version);
try{
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
System.out.println("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
StringBuffer sb=new StringBuffer();
sb.append(taskid).append(" ");
sb.append(testCaseExternalId).append(" ");
sb.append(version).append(" ");
sb.append(loadpath);
run.exec("cmd.exe /k start " + "task_onecase.cmd" + " " +sb.toString(), null,new File(System.getProperty("user.dir")+"\\"));
} catch (Exception e) {
e.printStackTrace();
return "启动单用例模式测试程序异常!!!";
}
return "启动单用例模式测试程序正常";
}
/**
* 批量运行用例
* @param req
* @return
* @throws RemoteException
*/
@PostMapping("/runbatchcase")
public String runbatchcase(HttpServletRequest req) throws RemoteException {
StringBuilder sbd = new StringBuilder();
try (BufferedReader reader = req.getReader();) {
char[] buff = new char[1024];
int len;
while ((len = reader.read(buff)) != -1) {
sbd.append(buff, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
}
JSONObject jsonObject = JSONObject.parseObject(sbd.toString());
String projectname = jsonObject.getString("projectname");
String taskid = jsonObject.getString("taskid");
String loadpath = jsonObject.getString("loadpath");
String batchcase = jsonObject.getString("batchcase");
System.out.println("启动批量用例模式测试程序...测试项目:"+projectname+" 任务ID"+taskid);
System.out.println("批量测试用例:"+batchcase);
try{
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
System.out.println("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
StringBuffer sb=new StringBuffer();
sb.append(taskid).append(" ");
sb.append(batchcase).append(" ");
sb.append(loadpath);
System.out.println(sb.toString());
run.exec("cmd.exe /k start " + "task_batch.cmd" + " " +sb.toString(), null,new File(System.getProperty("user.dir")+"\\"));
} catch (Exception e) {
e.printStackTrace();
return "启动批量用例模式测试程序异常!!!";
}
return "启动批量用例模式测试程序正常";
}
/**
* web界面调度接口
* @param req
* @return
* @throws RemoteException
*/
@PostMapping("/webdebugcase")
public String webdebugcase(HttpServletRequest req) throws RemoteException {
StringBuilder sbd = new StringBuilder();
try (BufferedReader reader = req.getReader();) {
char[] buff = new char[1024];
int len;
while ((len = reader.read(buff)) != -1) {
sbd.append(buff, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
}
JSONObject jsonObject = JSONObject.parseObject(sbd.toString());
String sign = jsonObject.getString("sign");
String executor = jsonObject.getString("executor");
String loadpath = jsonObject.getString("loadpath");
System.out.println("Web端调试用例"+sign+" 发起人:"+executor);
try{
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
System.out.println("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
StringBuffer sb=new StringBuffer();
sb.append(sign).append(" ");
sb.append(executor).append(" ");
sb.append(loadpath);
run.exec("cmd.exe /k start " + "web_debugcase.cmd" + " " +sb.toString(), null,new File(System.getProperty("user.dir")+"\\"));
} catch (Exception e) {
e.printStackTrace();
return "启动Web调试模式测试程序异常";
}
return "启动Web调试模式测试程序正常";
}
/**
* 获取客户端本地日志
* @param req
* @return
* @throws RemoteException
*/
@GetMapping("/getlogdetail")
public String getlogdetail(HttpServletRequest req) throws RemoteException{
String fileName=req.getParameter("filename");
String ctxPath = System.getProperty("user.dir")+"\\log\\";
String downLoadPath = ctxPath + fileName;
String str = "";
InputStreamReader isr=null;
try {
isr = new InputStreamReader(new FileInputStream(downLoadPath), "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "读取日志路径错误,请检查客户端日志路径是否存在!downLoadPath: "+downLoadPath;
}
BufferedReader bos = new BufferedReader(isr);
StringBuffer sb = new StringBuffer();
try {
while ((str = bos.readLine()) != null)
{
sb.append(str).append("##n##");
}
bos.close();
System.out.println("服务端读取本地日志成功!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "客户端转BufferedReader失败请检查原因";
}
return sb.toString();
}
/**
* 获取错误截图
* @param req
* @return
* @throws RemoteException
*/
@GetMapping("/getlogimg")
public byte[] getlogimg(HttpServletRequest req,HttpServletResponse res) throws RemoteException{
String imgName=req.getParameter("imgName");
String ctxPath = System.getProperty("user.dir")+"\\log\\ScreenShot\\";
String downLoadPath = ctxPath+imgName;
byte[] b = null;
try {
File file = new File(downLoadPath);
b = new byte[(int) file.length()];
BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
is.read(b);
is.close();
System.out.println("服务端获取本地图片:"+downLoadPath);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return b;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return b;
}
return b;
}
@PostMapping("/uploadjar")
public String uploadjar(HttpServletRequest req,HttpServletResponse res, HttpSession session,@RequestParam("jarfile") MultipartFile jarfile) throws IOException, ServletException{
if (!jarfile.isEmpty()){
if (!FilenameUtils.getExtension(jarfile.getOriginalFilename())
.equalsIgnoreCase("jar")) {
return "文件格式后续不是.jar上传失败";
}
}else{
return "上传文件为空,请检查!";
}
String name = jarfile.getOriginalFilename();
String loadpath = req.getParameter("loadpath");
String path = System.getProperty("user.dir")+loadpath;
if (!new File(path) .isDirectory())
{
System.out.println("客户端测试驱动桩路径不存在,请检查【"+path+"");
return "客户端测试驱动桩路径不存在,请检查【"+path+"";
}
String pathName = path +"\\"+ name;
File file = new File(pathName);
try {
if (file.exists()){
file.deleteOnExit();
}
file.createNewFile();
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
byte[] jarfileByte = jarfile.getBytes();
os.write(jarfileByte);
os.flush();
os.close();
System.out.println("上传JAR包【"+name+"】到客户端驱动目录【"+path+"】成功!");
return "上传JAR包【"+name+"】到客户端驱动目录【"+path+"】成功!";
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "客户端未找到正确路径或文件,上传失败!";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "客户端IOException";
}
}
/**
* 检查客户端心跳
* @param req
* @return
* @throws RemoteException
*/
@GetMapping("/getclientstatus")
public String getClientStatus(HttpServletRequest req) throws RemoteException{
return "success";
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,25 @@
package springboot;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @author seagull
* @date 2018年7月27日 上午10:16:40
*/
@SpringBootApplication
public class RunService {
public static void main(String[] args) {
// TODO Auto-generated method stub
PropertyConfigurator.configure(System.getProperty("user.dir") + "\\log4j.conf");
SpringApplication.run(RunService.class, args);
}
}

View File

@ -1,4 +1,4 @@
package rmi.model;
package springboot.model;
import java.io.Serializable;
@ -22,7 +22,14 @@ public class RunBatchCaseEntity implements Serializable {
private String projectname;
private String taskid;
private String batchcase;
private String loadpath;
public String getLoadpath() {
return loadpath;
}
public void setLoadpath(String loadpath) {
this.loadpath = loadpath;
}
public String getProjectname() {
return projectname;
}

View File

@ -1,4 +1,4 @@
package rmi.model;
package springboot.model;
import java.io.Serializable;
@ -22,7 +22,14 @@ public class RunCaseEntity implements Serializable {
private String taskid;
private String testCaseExternalId;
private String version;
private String loadpath;
public String getLoadpath() {
return loadpath;
}
public void setLoadpath(String loadpath) {
this.loadpath = loadpath;
}
public String getProjectname() {
return projectname;
}

View File

@ -1,4 +1,4 @@
package rmi.model;
package springboot.model;
import java.io.Serializable;
@ -21,7 +21,14 @@ public class RunTaskEntity implements Serializable {
private static final long serialVersionUID = 1L;
private String projectname;
private String taskid;
private String loadpath;
public String getLoadpath() {
return loadpath;
}
public void setLoadpath(String loadpath) {
this.loadpath = loadpath;
}
public String getProjectname() {
return projectname;
}

View File

@ -0,0 +1,44 @@
package springboot.model;
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;
}
}