From 00f1357af10729a0f412a230431fcb66a280aa1d Mon Sep 17 00:00:00 2001 From: Keith Armstrong Date: Tue, 31 Dec 2024 20:25:19 -0500 Subject: [PATCH] Debug writer update, credentials not required for SOAP, CSV header verification fix --- src/com/belkast/soap/debugProcessor.java | 6 +++++- src/com/belkast/soap/propertyProcessor.java | 4 ---- src/com/belkast/soap/salter.java | 4 ++++ src/com/belkast/soap/soapProcessor.java | 15 ++++++++++++++- src/com/belkast/soap/userVerify.java | 21 ++++++++++++++------- src/com/belkast/soap/webService.java | 6 +++--- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/com/belkast/soap/debugProcessor.java b/src/com/belkast/soap/debugProcessor.java index be7e363..8832fcd 100644 --- a/src/com/belkast/soap/debugProcessor.java +++ b/src/com/belkast/soap/debugProcessor.java @@ -4,11 +4,15 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; public class debugProcessor { public static void writer(boolean toScreen, String varMessage) { + SimpleDateFormat varFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); + Date dateStart = new Date(); if (toScreen) { System.out.println(varMessage); @@ -24,7 +28,7 @@ public class debugProcessor { BufferedWriter bw = null; bw = new BufferedWriter(new FileWriter(file, true)); - bw.write(varMessage); + bw.write( varFormat.format(dateStart) + ": " + varMessage); bw.newLine(); bw.flush(); bw.close(); diff --git a/src/com/belkast/soap/propertyProcessor.java b/src/com/belkast/soap/propertyProcessor.java index 798fbb8..c4bcf37 100644 --- a/src/com/belkast/soap/propertyProcessor.java +++ b/src/com/belkast/soap/propertyProcessor.java @@ -15,10 +15,6 @@ public class propertyProcessor { props.load(new FileInputStream(MyFile)); propertyValue = props.getProperty(varProperty); - if (propertyValue == null) - { - propertyValue = ""; - } } catch (Exception e) { diff --git a/src/com/belkast/soap/salter.java b/src/com/belkast/soap/salter.java index f532cf9..268846c 100644 --- a/src/com/belkast/soap/salter.java +++ b/src/com/belkast/soap/salter.java @@ -48,6 +48,10 @@ public class salter { public static String decrypt(String strToDecrypt, String secretKey, String salt) { try { + if (strToDecrypt == null) + { + return null; + } byte[] encryptedData = Base64.getDecoder().decode(strToDecrypt); byte[] iv = new byte[16]; diff --git a/src/com/belkast/soap/soapProcessor.java b/src/com/belkast/soap/soapProcessor.java index 0dc62a1..8e41876 100644 --- a/src/com/belkast/soap/soapProcessor.java +++ b/src/com/belkast/soap/soapProcessor.java @@ -17,6 +17,11 @@ public class soapProcessor { public static String getCredentials(String username, String password) throws Exception { + if (username == null || password == null) + { + return null; + } + String login = username + ":" + password; String credentials = Base64.getEncoder().encodeToString(login.getBytes()); return credentials; @@ -38,7 +43,15 @@ public class soapProcessor { try { URLConnection connection = url.openConnection(); - connection.setRequestProperty("Authorization", "Basic " + thisCredentials); + if (thisCredentials != null) + { + debugProcessor.writer(false, "We are sending credentials!"); + connection.setRequestProperty("Authorization", "Basic " + thisCredentials); + } + else + { + debugProcessor.writer(false, "No Credentials will be sent!"); + } HttpURLConnection httpConn = (HttpURLConnection)connection; return httpConn; } diff --git a/src/com/belkast/soap/userVerify.java b/src/com/belkast/soap/userVerify.java index 1b0ce26..9aef60c 100644 --- a/src/com/belkast/soap/userVerify.java +++ b/src/com/belkast/soap/userVerify.java @@ -14,9 +14,9 @@ public class userVerify System.out.println(); Scanner myObj = new Scanner(System.in); // Create a Scanner object - String varFileName = new String(); + String varFileName; while (true) { - System.out.print("Enter the name of the file to verify : "); + System.out.print("Please enter the name of the CSV file to verify : "); varFileName = myObj.nextLine(); // Read user input File thisFile = new File(varFileName); if (thisFile.exists()) @@ -62,6 +62,7 @@ public class userVerify System.exit(0); } + String exceptionReason = null; Boolean failedOnException = false; Boolean parsedCorrectly = false; long lineNum = 0; @@ -72,7 +73,7 @@ public class userVerify String varHeader = new String(); varHeader = fileProcessor.readFirstLine(thisFile); if (varHeader.length() == 0) { - System.out.println(thisFile + " : appears to be missing a valid header!"); + System.out.println(thisFile + " : the CSV file appears to be missing a valid header!"); return finalArray; } @@ -105,13 +106,14 @@ public class userVerify { invalidNum++; String thisLine = Files.readAllLines(Paths.get(thisFile)).get(Math.toIntExact(lineNum - 1)); - debugProcessor.writer(fromUser, "!! " + lineNum + " [FAILED] : " + thisLine); - debugProcessor.writer(fromUser, "!! " + lineNum + " [FAILED] : " + record.toMap().toString()); + debugProcessor.writer(fromUser, "!! " + lineNum + " [failed] : " + thisLine); + debugProcessor.writer(fromUser, "!! " + lineNum + " [failed] : " + record.toMap().toString()); } } } catch (IOException | IllegalArgumentException e) { + exceptionReason = e.toString(); failedOnException = true; break; } @@ -119,8 +121,13 @@ public class userVerify } debugProcessor.writer(fromUser,""); - debugProcessor.writer(fromUser, "CSV lines passed : " + String.valueOf(readNum - invalidNum)); - debugProcessor.writer(fromUser, "CSV lines failed : " + invalidNum); + debugProcessor.writer(fromUser, "CSV lines read : " + String.valueOf(readNum)); + debugProcessor.writer(fromUser, "CSV lines passed : " + String.valueOf(readNum - invalidNum)); + debugProcessor.writer(fromUser, "CSV lines failed : " + invalidNum); + if (exceptionReason != null) + { + debugProcessor.writer(fromUser, "CSV failure error : " + exceptionReason); + } if (invalidNum > 0) { diff --git a/src/com/belkast/soap/webService.java b/src/com/belkast/soap/webService.java index 59e95fc..95b0008 100644 --- a/src/com/belkast/soap/webService.java +++ b/src/com/belkast/soap/webService.java @@ -132,12 +132,12 @@ public class webService { ArrayList thisCSV = userVerify.readCSV(varRoleFile, false); boolean validfile = (thisCSV.size() > 0); - debugProcessor.writer(true, varRoleFile + " : CSV file is valid => " + validfile); - debugProcessor.writer(true, varRoleFile + " : records to process => " + thisCSV.size()); + debugProcessor.writer(true, varRoleFile + " : CSV file is valid : " + validfile); + debugProcessor.writer(true, varRoleFile + " : records to process : " + thisCSV.size()); if (!validfile) { - debugProcessor.writer(true, varRoleFile + " : please verify the file with com.belkast.soap.userVerify"); + debugProcessor.writer(true, varRoleFile + " : verification failed. please verify the file with com.belkast.soap.userVerify!"); } int varCount = 0; Iterator mapper1 = thisCSV.iterator();