java对AppScan工具的集成

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;
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

司小白

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值