if (intermediaryResult.getErrorMessage() != null) {
result.setErrorMessage(intermediaryResult.getErrorMessage());
} else {
String output = intermediaryConfig.getSimpleValue(OPERATION_RESULT_OUTPUT, "");
if (output.length() > 0) {
PropertyList list = new PropertyList("networkConnections");
config.put(list);
String[] lines = output.split("\n");
for (String line : lines) {
Matcher matcher = pattern.matcher(line);
if (matcher.matches()) {
PropertyMap map = new PropertyMap("networkConnection");
list.add(map);
map.put(new PropertySimple("localHost", matcher.group(1)));
map.put(new PropertySimple("localPort", matcher.group(2)));
map.put(new PropertySimple("remoteHost", matcher.group(3)));
map.put(new PropertySimple("remotePort", matcher.group(4)));
}
}
}
}
} else {
log.info("Getting network connections using the internal mechanism");
result = new OperationResult();
Configuration config = result.getComplexResults();
config.put(new PropertySimple("detectionMechanism", mechanism.toString()));
try {
List<NetConnection> conns;
conns = getResourcContext().getSystemInformation().getNetworkConnections(null, 0);
config.put(new PropertySimple(OPERATION_RESULT_EXITCODE, "0"));
if (conns.size() > 0) {
PropertyList list = new PropertyList("networkConnections");
config.put(list);
for (NetConnection conn : conns) {
PropertyMap map = new PropertyMap("networkConnection");
list.add(map);
map.put(new PropertySimple("localHost", conn.getLocalAddress()));
map.put(new PropertySimple("localPort", conn.getLocalPort()));
map.put(new PropertySimple("remoteHost", conn.getRemoteAddress()));
map.put(new PropertySimple("remotePort", conn.getRemotePort()));
}