• java程序运行中如果出现异常未被处理,将会被抛到java虚拟机进行处理,程序中断运行后被挂起,在页面输出错误信息(不会输出到console)


    下面的代码中,因为我是使用 

    for (Iterator<Element> i = el.elements().iterator(); i.hasNext(); )

    迭代器遍历根节点的所有子节点的flag,但是因为linux基线有 <initcmd> 节点,导致flag为空,

    在传入service中进行数据库操作时抛出异常未被处理导致程序被挂起,错误信息不输出到console,直接打印到了页面。

    解决方法就是try catch处理掉异常并返回false即可

        public boolean isFound(String xcwIndex) {
            try {
                XconfigLinuxExample example = new XconfigLinuxExample();
                XconfigLinuxExample.Criteria criteria = example.createCriteria();
                criteria.andXcwindexEqualTo(xcwIndex);
    
                long count = xconfigLinuxMapper.countByExample(example);
                return count > 0;
            }catch (Exception e){
    //            System.out.println("xcwIndex为空,当次未遍历到flag");
                return false;
            }
        }


        public void getSysTypeByUuid(String uuid) throws IOException, DocumentException {
    
    
            switch (uuid){
                case "66c221be-6ab2-ef53-1589-fe16877914e2": //windows
                    importDataXML("66c221be-6ab2-ef53-1589-fe16877914e2");break;
                case "66c221be-6ab2-ef53-1589-fe16877914f4": //linux linux系都需要去除 <initcmd> 的干扰
                    linuxBaseline("66c221be-6ab2-ef53-1589-fe16877914f4");break;
            }
        }
        public void linuxBaseline(String uuid) throws DocumentException, IOException {
    
            JSONObject jsonObject = new JSONObject();
            String result = null;
    
            CompTools compTools = new CompTools();
    
            String path = "C:\RM-ROOT\upload\assetsConfResultXml\" + uploadedFileName;
    
    //        创建 dom4j 解析器
            SAXReader reader = new SAXReader();
            Document document = reader.read(new File(path));
            Element root = document.getRootElement();
    
    
            List<Element> elements = root.elements();
            String flag;
            String xcwValue;
            Integer noneComplianceConfCount = 0;
            for (Element el :
                    elements) {
                for (Iterator<Element> i = el.elements().iterator(); i.hasNext(); ) {
                    Element element = (Element) i.next();
    
                    flag = element.attributeValue("flag");
                    if (xconfigLinuxService.isFound(flag)) {
                        XconfigLinux allByXcwIndex = xconfigLinuxService.getAllByXcwIndex(flag);
                        xcwValue = element.element("cmd").element("value").getText();
                        result = compTools.linuxComp(allByXcwIndex.getCindex().toString(), flag, xconfigLinuxService, xcwValue);
                        jsonObject.put(flag, result);
                        if ("1".equals(result)){
                            noneComplianceConfCount+=1;
                        }
    
                    } else {
    //                    System.out.println("没找到:"+flag);
                    }
    
    
                }
            }
            assetsService.saveAssetsData(OriginalFilename,jsonObject,noneComplianceConfCount,uuid);
        }
  • 相关阅读:
    Linux-OpenSUSE折腾-1(Qt安装,Chrome安装)
    Qt HUD(平显)演示程序绿色版
    你所不知道的按位运算
    Linux-Shell脚本编程-学习-8-函数
    Linux-Shell脚本编程-学习-7-总结前面开启后面的学习
    Linux-Shell脚本编程-学习-6-Shell编程-使用结构化命令-文件比较-case编程
    Linux-Shell脚本编程-学习-5-Shell编程-使用结构化命令-if-then-else-elif
    Linux-Shell脚本编程-学习-4-Shell编程-操作数字-加减乘除计算
    Linux-Shell脚本编程-学习-3-Shell编程-shell脚本基本格式
    selenium 总结篇,常见方法和页面元素的操作
  • 原文地址:https://www.cnblogs.com/kinome/p/9444523.html
Copyright © 2020-2023  润新知