1.本地安装好AppScan工具
2.用java代码 调用cmd 命令生成 PDF报告
3.代码如下(配置和常量信息在上篇jmeter集成里面)
appScan命令:
appscancmd e /su http://192.168.10.101:9099/ /d C:\shx\test.scan /rt pdf /report_file C:\shx\test.pdf
@Service
@Slf4j
public class AppScanServiceExt extends OpenStackService {
/**
* 环境里面appScan位置
*/
@Value(value = “
t
e
s
t
t
o
o
l
.
a
p
p
S
c
a
n
"
)
p
u
b
l
i
c
S
t
r
i
n
g
a
p
p
S
c
a
n
;
/
∗
∗
∗
文
件
保
存
位
置
∗
/
@
V
a
l
u
e
(
v
a
l
u
e
=
"
{testtool.appScan}") public String appScan; /** * 文件保存位置 */ @Value(value = "
testtool.appScan")publicStringappScan;/∗∗∗文件保存位置∗/@Value(value="{testtool.pathJmx}”)
public String pathJmx;
public String getAppScan(String path) throws IOException {
String osName = System.getProperties().getProperty(CommonConstant.OS_NAME).toLowerCase();
SimpleDateFormat sdf = new SimpleDateFormat(CommonConstant.Y_M_D);
String dateNowStr = sdf.format(new Date());
//报告保存位置
String appScanPath = null;
if (osName.contains(CommonConstant.WINDOWS)) {
appScanPath = pathJmx + dateNowStr + CommonConstant.SYMBOL +CommonConstant.APP_SCAN_PATH + dateNowStr;
}else {
appScanPath = CommonConstant.HOME + dateNowStr + CommonConstant.SYMBOL + CommonConstant.APP_SCAN_PATH + dateNowStr;
}
//判断文件是否存在
File fileJmx = null;
if (osName.contains(CommonConstant.WINDOWS)) {
fileJmx = new File(pathJmx + dateNowStr + CommonConstant.SYMBOL +CommonConstant.APP_SCAN_PATH + dateNowStr);
}else {
fileJmx = new File(CommonConstant.HOME + dateNowStr + CommonConstant.SYMBOL + CommonConstant.APP_SCAN_PATH + dateNowStr);
}
if (fileJmx.exists()){
//有文件就删除
Boolean result = FileUtil.delFiles(fileJmx);
if (!result){
log.error("文件删除失败");
return null;
}
}
File file = new File(appScanPath);
if(!file.exists()){
file.mkdirs();
}
//执行cmd 命令
Runtime.getRuntime().exec(CommonConstant.CMD_EXE_START + CommonConstant.APP_SCAN + path + CommonConstant.D_D + appScanPath + CommonConstant.SCAN + CommonConstant.REPORT_FILE + appScanPath + CommonConstant.PDF_SCAN,null,
new File(appScan));
return appScanPath;
}
}