From 6d11a0a70c7cdcc8659e208eb7eaa7c90c98074f Mon Sep 17 00:00:00 2001 From: snoop Date: Wed, 12 Apr 2017 15:08:55 +0900 Subject: [PATCH] added error process --- .../overflow/crawler/wmi/WMICrawlerLinux.java | 23 ++++++++++++++++++- .../overflow/crawler/wmi/WMICrawlerTest.java | 10 ++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerLinux.java b/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerLinux.java index 5fcc2e6..70b0893 100644 --- a/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerLinux.java +++ b/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerLinux.java @@ -2,6 +2,8 @@ package com.loafle.overflow.crawler.wmi; import java.util.*; + + /** * Created by root on 17. 4. 12. */ @@ -67,10 +69,29 @@ public class WMICrawlerLinux extends WMICrawlerOS { } result = result.trim(); + + List> resultMapList = new ArrayList>(); + + int errIdx = result.indexOf("ERROR:"); + if(errIdx >= 0) { + + int enterIdx = result.indexOf("\\n", errIdx); + if(enterIdx < 0) enterIdx = result.length(); + String errStr = result.substring(errIdx + "ERROR:".length(), enterIdx); + + + Map map = new HashMap<>(); + + map.put("ERROR", errStr); + resultMapList.add(map); + return resultMapList; + } + + String[] lines = result.split("\\n"); String line = ""; - List> resultMapList = new ArrayList>(); + List columns = null; for (int indexI = 0 ; indexI < lines.length; ++indexI) { diff --git a/src/test/java/com/loafle/overflow/crawler/wmi/WMICrawlerTest.java b/src/test/java/com/loafle/overflow/crawler/wmi/WMICrawlerTest.java index 5337842..b094f74 100644 --- a/src/test/java/com/loafle/overflow/crawler/wmi/WMICrawlerTest.java +++ b/src/test/java/com/loafle/overflow/crawler/wmi/WMICrawlerTest.java @@ -52,11 +52,11 @@ public class WMICrawlerTest { Map map = new HashMap(); - String id = "administrator"; - String pw = "!@#$qwer1234"; - String nameSpace = "root/cimv2"; - String query = "select * from Win32_OperatingSystem"; - String ip = "192.168.1.1"; +// String id = "administrator"; +// String pw = "!@#$qwer1234"; +// String nameSpace = "root/cimv2"; +// String query = "select * from Win32_OperatingSystem"; +// String ip = "192.168.1.1"; map.put("id", "administrator"); map.put("pw", "!@#$qwer1234");