From 79cb46092ea79e6cbbf2abf319fa093b0dd857fb Mon Sep 17 00:00:00 2001 From: Keith Armstrong Date: Sun, 12 Jan 2025 21:26:20 -0500 Subject: [PATCH] Add SOAP return details to hashmap hashMap is used to log more debug information --- src/com/belkast/soap/soapProcessor.java | 11 +++- src/com/belkast/soap/userVerify.java | 4 +- src/com/belkast/soap/webService.java | 81 +++++++++++++++++++------ 3 files changed, 72 insertions(+), 24 deletions(-) diff --git a/src/com/belkast/soap/soapProcessor.java b/src/com/belkast/soap/soapProcessor.java index d4b0f03..5831ff1 100644 --- a/src/com/belkast/soap/soapProcessor.java +++ b/src/com/belkast/soap/soapProcessor.java @@ -10,7 +10,6 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; -import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.HashMap; @@ -102,10 +101,18 @@ public class soapProcessor { } catch (Exception ex) { + String regexPattern = "(^.+response code: )(\\d\\d\\d)(.+$)"; + String exCode = ex.toString().replaceAll(regexPattern, "$2"); + + if (exCode.equals(ex.toString())) + { + exCode = "N/A"; + } + thisMap.put("success", false); thisMap.put("sent", new String(document, StandardCharsets.UTF_8)); thisMap.put("response", ex.toString()); - thisMap.put("code", thisCode); + thisMap.put("code", exCode); return thisMap; } diff --git a/src/com/belkast/soap/userVerify.java b/src/com/belkast/soap/userVerify.java index d046da2..e863f26 100644 --- a/src/com/belkast/soap/userVerify.java +++ b/src/com/belkast/soap/userVerify.java @@ -121,8 +121,8 @@ public class userVerify Iterable records = csvFormat.parse(in); int thisHeaderLength = varHeader.split(",").length; - debugProcessor.writer(fromUser, "CSV header length : " + thisHeaderLength); - debugProcessor.writer(fromUser, "CSV header tokens : " + varHeader); + debugProcessor.writer(fromUser, "CSV header length : " + thisHeaderLength); + debugProcessor.writer(fromUser, "CSV header tokens : " + varHeader); debugProcessor.writer(fromUser, ""); for (CSVRecord record : records) diff --git a/src/com/belkast/soap/webService.java b/src/com/belkast/soap/webService.java index 5e5e3e4..34ebf7d 100644 --- a/src/com/belkast/soap/webService.java +++ b/src/com/belkast/soap/webService.java @@ -33,7 +33,6 @@ public class webService { jCommanderArgs args = new jCommanderArgs(); JCommander jct = new JCommander(args); - try { jct.parse(argv); } catch (ParameterException ex) { @@ -47,6 +46,11 @@ public class webService { if (varToEncrypt != null && !varToEncrypt.isEmpty()) { + if (varKey == null) + { + String varKey = credentialsProcessor.getCredential("Please enter the encryption key (must be 16 characters) : ", 16, true); + } + String varToStore = encyptProcessor.encrypt(varToEncrypt, varKey, varSalt); String varChecked = encyptProcessor.decrypt(varToStore, varKey, varSalt); @@ -77,13 +81,25 @@ public class webService { if (varProps != null) { Map thisFinal = doSoap(new File(varProps)); + System.out.println(); - debugProcessor.writer(true, "!! Total records : " + thisFinal.get("total")); - debugProcessor.writer(true, "!! Total passed : " + thisFinal.get("passed")); - debugProcessor.writer(true, "!! Total failed : " + thisFinal.get("failed")); + Map map = (Map) thisFinal.get("results"); + Iterator> iterator = map.entrySet().iterator(); + + while (iterator.hasNext()) + { + Map.Entry pair = iterator.next(); + debugProcessor.writer(varDebug, "!! processed " + pair.getKey() + " [" + pair.getValue().get("soap_response") + "] " + pair.getValue()); + } + + System.out.println(); + debugProcessor.writer(true, "!! Connect User : " + thisFinal.get("user")); + debugProcessor.writer(true, "!! Total records : " + thisFinal.get("total")); + debugProcessor.writer(true, "!! Total passed : " + thisFinal.get("passed")); + debugProcessor.writer(true, "!! Total failed : " + thisFinal.get("failed")); Boolean thisResult = thisFinal.get("total") == thisFinal.get("passed"); - debugProcessor.writer(true, "!! ALL PROCESSED : " + thisResult.toString().toUpperCase()); + debugProcessor.writer(true, "!! WAS SUCCESSFUL : " + thisResult.toString().toUpperCase()); if (!thisResult) { debugProcessor.writer(true, "!! PLEASE CHECK THE DEBUG LOG"); @@ -100,7 +116,7 @@ public class webService { int varFailed = 0; Map varResult = new HashMap(); - debugProcessor.writer(false, "Debug is set to : " + varDebug); + debugProcessor.writer(false, "Debug setting : " + varDebug); String varURL = propertyProcessor.getProperty(thisProps, "SHIM_URL", null); String varKeystore_LOC = propertyProcessor.getProperty(thisProps, "JAVA_KS_LOCATION", null); @@ -150,19 +166,30 @@ public class webService { String varUsername = propertyProcessor.getProperty(thisProps, "USERNAME", null); if (varAuthRequired && varUsername == null) { - varUsername = credentialsProcessor.getUsername("Please enter your username : "); + varUsername = credentialsProcessor.getCredential("Please enter your username : ", 1, false); } String varPasswordTemp = propertyProcessor.getProperty(thisProps, "PASSWORD", null); - if (varAuthRequired && varPasswordTemp == null) + + if (varAuthRequired) + { + if (varPasswordTemp == null) { - char[] varUserPW = credentialsProcessor.getPassword("[" + varUsername + "] Please enter your password : "); - varPasswordTemp = encyptProcessor.encrypt(String.copyValueOf(varUserPW), varKey, varSalt); + // This is just a temporary key so that the rest of the code does not error out! + varKey = "ZyXwQbRH9VGrAEzN"; + String varUserPW = credentialsProcessor.getCredential("[" + varUsername + "] Please enter your password : ", 1, true); + varPasswordTemp = encyptProcessor.encrypt(varUserPW, varKey, varSalt); } - else if (!varAuthRequired) + + if (varKey == null) { - varPasswordTemp = null; + String userKey = credentialsProcessor.getCredential("Please enter the encryption key (must be 16 characters) : ", 16, true); } + } + else + { + varPasswordTemp = null; + } try { @@ -198,14 +225,16 @@ public class webService { boolean validfile = (!thisCSV.isEmpty()); debugProcessor.writer(varDebug, ""); - debugProcessor.writer(true, varRoleFile + " => CSV file is valid : " + validfile); - debugProcessor.writer(true, varRoleFile + " => records to process : " + thisCSV.size()); + debugProcessor.writer(true, "CSV file is valid : " + validfile); + debugProcessor.writer(true, "CSV records to process : " + thisCSV.size()); if (!validfile) { debugProcessor.writer(true, varRoleFile + " => verification failed : please verify the file with com.belkast.soap.userVerify!"); } + int varCount = 0; + Map resultMap = new HashMap(); Iterator mapper1 = thisCSV.iterator(); while (mapper1.hasNext()) { varCount++; @@ -213,8 +242,6 @@ public class webService { debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : processing started"); Map hashMap = mapper1.next(); - debugProcessor.writer(varDebug, "record " + varCount + " : " + hashMap.values().toString()); - Iterator> it = hashMap.entrySet().iterator(); while (it.hasNext()) { @@ -232,7 +259,7 @@ public class webService { for(Object key: hashMap.keySet()) { Boolean varHasText = fileProcessor.stringHasText(varXML, key.toString()); - debugProcessor.writer(varDebug, "[after] " + varInputFile + " : " + key + " token exists => " + varHasText); +// debugProcessor.writer(varDebug, "[after] " + varInputFile + " : " + key + " token exists => " + varHasText); } HashMap errorMap = new HashMap(); @@ -243,24 +270,36 @@ public class webService { { String varCredentials = soapProcessor.getCredentials(varUsername, varPassword); - debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : opening connection [" + varURL + "]"); + debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : opening connection to " + varURL); HttpURLConnection varConn = soapProcessor.getConnection(varCredentials, varURL, varUseSSL, varKeystore_LOC, varKeystore_PW); debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : sending XML document"); + debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call logging in : " + varAuthRequired); debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call sending data : " + varXML); Map response = soapProcessor.send(varConn, varXML.getBytes()); debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call response code : " + response.get("code")); - debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call was successful : " + Boolean.valueOf(response.get("success").toString())); boolean varSuccess = Boolean.valueOf(response.get("success").toString()); + debugProcessor.writer(!varSuccess, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call response data : " + response.get("response")); + debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call was successful : " + Boolean.valueOf(response.get("success").toString())); + if (!varSuccess) { debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : " + hashMap.toString()); varFailed++; } - debugProcessor.writer(!varSuccess, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call response data : " + response.get("response")); + hashMap.put("csv_file", varInputFile); + hashMap.put("csv_records", thisCSV.size()); + hashMap.put("date", new Date()); + hashMap.put("soap_auth", varAuthRequired); + hashMap.put("soap_response", response.get("code")); + hashMap.put("soap_sent_size", varXML.length()); + hashMap.put("soap_success", response.get("success")); + hashMap.put("soap_user", (varUsername == null) ? "N/A" : varUsername); + hashMap.put("this_record", varCount); + resultMap.put(varCount,hashMap); if (varConn != null) { @@ -270,9 +309,11 @@ public class webService { } } + varResult.put("user", (varUsername == null) ? "N/A" : varUsername); varResult.put("total", thisCSV.size()); varResult.put("passed", thisCSV.size() - varFailed); varResult.put("failed", varFailed); + varResult.put("results", resultMap); return varResult; }