Added code to handle soapProcessor returning Map

This commit is contained in:
Keith Armstrong 2025-01-09 19:30:06 -05:00
parent db528c70cd
commit 8e17fd2848

View File

@ -47,8 +47,8 @@ public class webService {
if (varToEncrypt != null && !varToEncrypt.isEmpty())
{
String varToStore = salter.encrypt(varToEncrypt, varKey, varSalt);
String varChecked = salter.decrypt(varToStore, varKey, varSalt);
String varToStore = encyptProcessor.encrypt(varToEncrypt, varKey, varSalt);
String varChecked = encyptProcessor.decrypt(varToStore, varKey, varSalt);
System.out.println("Clear Text Password : " + varToEncrypt);
System.out.println("Encryption Key : " + varKey);
@ -61,7 +61,7 @@ public class webService {
String varProps = args.props;
if (varProps == null && varToEncrypt == null)
{
debugProcessor.writer(true, "Check the program parameters. There is nothing to do!");
debugProcessor.writer(true, "Check the command line parameters. There is nothing to do!");
System.out.println();
jct.usage();
System.exit(0);
@ -76,7 +76,18 @@ public class webService {
if (varProps != null)
{
doSoap(new File(varProps));
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"));
Boolean thisResult = thisFinal.get("total") == thisFinal.get("passed");
debugProcessor.writer(true, "!! ALL PROCESSED : " + thisResult.toString().toUpperCase());
if (!thisResult)
{
debugProcessor.writer(true, "!! PLEASE CHECK THE DEBUG LOG");
}
}
System.out.println();
@ -84,8 +95,11 @@ public class webService {
}
private static void doSoap(File thisProps) throws Exception {
private static Map doSoap(File thisProps) throws Exception {
String varPassword = "";
int varFailed = 0;
Map varResult = new HashMap();
debugProcessor.writer(false, "Debug is set to : " + varDebug);
String varURL = propertyProcessor.getProperty(thisProps, "SHIM_URL", null);
@ -130,33 +144,37 @@ public class webService {
Boolean varUseSSL = Boolean.valueOf(varPropUseSSL);
Boolean varAuthRequired = Boolean.valueOf(varPropAuthRequired);
Boolean varEmptyColumns = Boolean.valueOf(varPropEmptyColumns);
String varUsername = propertyProcessor.getProperty(thisProps, "USERNAME", null);
if (varAuthRequired && varUsername == null)
{
varUsername = userCreds.getUsername("Please enter your username : ");
varUsername = credentialsProcessor.getUsername("Please enter your username : ");
}
String varPasswordTemp = propertyProcessor.getProperty(thisProps, "PASSWORD", null);
if (varAuthRequired && varPasswordTemp == null)
{
char[] varUserPW = userCreds.getPassword("Please enter your password : ");
varPasswordTemp = salter.encrypt(String.copyValueOf(varUserPW), varKey, varSalt);
char[] varUserPW = credentialsProcessor.getPassword("[" + varUsername + "] Please enter your password : ");
varPasswordTemp = encyptProcessor.encrypt(String.copyValueOf(varUserPW), varKey, varSalt);
}
else if (!varAuthRequired)
{
varPasswordTemp = null;
}
try
{
varPassword = salter.decrypt(varPasswordTemp, varKey, varSalt);
varPassword = encyptProcessor.decrypt(varPasswordTemp, varKey, varSalt);
}
catch(Exception e)
{
debugProcessor.writer(true, "The password could not be decrypted. Please check that the Encryption Key is correct!");
debugProcessor.writer(true, "The password could not be decrypted. Please check the encryption key!");
System.out.println();
System.exit(0);
}
debugProcessor.writer(varDebug, "");
debugProcessor.writer(varDebug, thisProps + " => SOAP URL : " + (varURL == null ? "" : varURL));
debugProcessor.writer(varDebug, thisProps + " => Authentication required : " + varAuthRequired);
debugProcessor.writer(varDebug, thisProps + " => Use SSL : " + varUseSSL);
@ -179,6 +197,7 @@ public class webService {
ArrayList thisCSV = userVerify.readCSV(varRoleFile, false, !varEmptyColumns);
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());
@ -191,7 +210,7 @@ public class webService {
while (mapper1.hasNext()) {
varCount++;
debugProcessor.writer(true, "");
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : processing started");
debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : processing started");
Map hashMap = mapper1.next();
debugProcessor.writer(varDebug, "record " + varCount + " : " + hashMap.values().toString());
@ -203,28 +222,58 @@ public class webService {
debugProcessor.writer(varDebug, "record " + varCount + " : " + pair.getKey() + " => " + pair.getValue());
}
String varDocument = fileProcessor.replaceInFile(varInputFile, hashMap);
for(Object key: hashMap.keySet())
{
Boolean varHasText = fileProcessor.fileHasText(varInputFile, key.toString());
debugProcessor.writer(varDebug, "[before] " + varInputFile + " : " + key + " token exists => " + varHasText);
}
if (varDocument != null && !varDocument.isEmpty())
String varXML = fileProcessor.replaceInFile(varInputFile, hashMap);
for(Object key: hashMap.keySet())
{
Boolean varHasText = fileProcessor.stringHasText(varXML, key.toString());
debugProcessor.writer(varDebug, "[after] " + varInputFile + " : " + key + " token exists => " + varHasText);
}
HashMap<Boolean, String> errorMap = new HashMap();
errorMap.put(false, "FAILED");
errorMap.put(true, "SUCCESS");
if (varXML != null && !varXML.isEmpty())
{
String varCredentials = soapProcessor.getCredentials(varUsername, varPassword);
debugProcessor.writer(varDebug, "connecting to URL : " + varURL);
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : opening connection [" + varURL + "]");
HttpURLConnection varConn = soapProcessor.getConnection(varCredentials, varURL, varUseSSL, varKeystore_LOC, varKeystore_PW);
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : opened connection");
debugProcessor.writer(varDebug, "sending XML document : " + varDocument);
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : sending XML document");
debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call sending data : " + varXML);
String response = soapProcessor.send(varConn, varInputFile, hashMap, varDocument.getBytes());
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : XML document sent");
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());
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"));
debugProcessor.writer(varDebug, "response received : " + response);
if (varConn != null)
{
soapProcessor.closeConnection(varConn);
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : closed connection");
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : connection closed");
}
}
}
varResult.put("total", thisCSV.size());
varResult.put("passed", thisCSV.size() - varFailed);
varResult.put("failed", varFailed);
return varResult;
}
}