Made the code tighter
Updated 4 files
This commit is contained in:
parent
1c86d5a944
commit
d5ed7a9f9e
@ -6,15 +6,19 @@ import java.util.Properties;
|
|||||||
|
|
||||||
public class propertyProcessor
|
public class propertyProcessor
|
||||||
{
|
{
|
||||||
public static String getProperty(File MyFile, String varProperty) throws Exception
|
public static String getProperty(File MyFile, String varProperty, String thisDefault) throws Exception
|
||||||
{
|
{
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
String propertyValue = "";
|
|
||||||
|
|
||||||
|
String propertyValue = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
props.load(new FileInputStream(MyFile));
|
props.load(new FileInputStream(MyFile));
|
||||||
propertyValue = props.getProperty(varProperty);
|
propertyValue = props.getProperty(varProperty);
|
||||||
|
if (propertyValue == null)
|
||||||
|
{
|
||||||
|
propertyValue = thisDefault;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -4,19 +4,17 @@ import java.io.Console;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class userCreds {
|
public class userCreds {
|
||||||
public static String getUsername() {
|
public static String getUsername(String thisPrompt) {
|
||||||
Scanner myObj = new Scanner(System.in);
|
Scanner myObj = new Scanner(System.in);
|
||||||
String varPrompt = "Please enter your username : ";
|
System.out.print(thisPrompt);
|
||||||
System.out.print(varPrompt);
|
|
||||||
String varEntry;
|
String varEntry;
|
||||||
varEntry = myObj.nextLine();
|
varEntry = myObj.nextLine();
|
||||||
return varEntry;
|
return varEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static char[] getPassword() {
|
public static char[] getPassword(String thisPrompt) {
|
||||||
String varPrompt = "Please enter your password : ";
|
|
||||||
Console console = System.console();
|
Console console = System.console();
|
||||||
char[] password = console.readPassword(varPrompt);
|
char[] password = console.readPassword(thisPrompt);
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,15 +11,13 @@ import java.util.*;
|
|||||||
|
|
||||||
public class userVerify
|
public class userVerify
|
||||||
{
|
{
|
||||||
public static void main (String[] args) {
|
public static void main (String[] args) throws IOException
|
||||||
|
{
|
||||||
System.out.println();
|
System.out.println();
|
||||||
Scanner myObj = new Scanner(System.in); // Create a Scanner object
|
|
||||||
|
|
||||||
debugProcessor.writer(false, "");
|
|
||||||
debugProcessor.writer(true, "SOAP Client (06.01.2025 build) - Belkast Consulting (c) 2025");
|
|
||||||
debugProcessor.writer(true, "");
|
|
||||||
String varPrompt = "Please enter the name of the CSV file to validate : ";
|
String varPrompt = "Please enter the name of the CSV file to validate : ";
|
||||||
String varFileName;
|
String varFileName;
|
||||||
|
|
||||||
|
Scanner myObj = new Scanner(System.in); // Create a Scanner object
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
System.out.print(varPrompt);
|
System.out.print(varPrompt);
|
||||||
|
@ -3,7 +3,6 @@ package com.belkast.soap;
|
|||||||
import com.beust.jcommander.ParameterException;
|
import com.beust.jcommander.ParameterException;
|
||||||
import com.beust.jcommander.*;
|
import com.beust.jcommander.*;
|
||||||
|
|
||||||
import javax.crypto.BadPaddingException;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@ -19,10 +18,7 @@ public class webService {
|
|||||||
|
|
||||||
public static void main(String... argv) throws Exception
|
public static void main(String... argv) throws Exception
|
||||||
{
|
{
|
||||||
debugProcessor.writer(true, "");
|
System.out.println();
|
||||||
debugProcessor.writer(true, "SOAP Client (06.01.2025 build) - Belkast Consulting (c) 2025");
|
|
||||||
debugProcessor.writer(true, "");
|
|
||||||
|
|
||||||
// @Parameter(names = "--props",
|
// @Parameter(names = "--props",
|
||||||
// description = "Location of the Properties file")
|
// description = "Location of the Properties file")
|
||||||
|
|
||||||
@ -41,12 +37,11 @@ public class webService {
|
|||||||
try {
|
try {
|
||||||
jct.parse(argv);
|
jct.parse(argv);
|
||||||
} catch (ParameterException ex) {
|
} catch (ParameterException ex) {
|
||||||
System.out.println();
|
|
||||||
jct.usage();
|
jct.usage();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
varDebug = Boolean.valueOf(args.debug);
|
varDebug = args.debug;
|
||||||
varKey = args.key;
|
varKey = args.key;
|
||||||
String varToEncrypt = args.encrypt;
|
String varToEncrypt = args.encrypt;
|
||||||
|
|
||||||
@ -93,17 +88,17 @@ public class webService {
|
|||||||
String varPassword = "";
|
String varPassword = "";
|
||||||
debugProcessor.writer(false, "Debug is set to : " + varDebug);
|
debugProcessor.writer(false, "Debug is set to : " + varDebug);
|
||||||
|
|
||||||
String varURL = propertyProcessor.getProperty(thisProps, "SHIM_URL");
|
String varURL = propertyProcessor.getProperty(thisProps, "SHIM_URL", null);
|
||||||
|
String varKeystore_LOC = propertyProcessor.getProperty(thisProps, "JAVA_KS_LOCATION", null);
|
||||||
|
String varInputFile = propertyProcessor.getProperty(thisProps, "XML_FILE", null);
|
||||||
|
String varRoleFile = propertyProcessor.getProperty(thisProps, "CSV_FILE",null);
|
||||||
|
String varKeystore_PW = propertyProcessor.getProperty(thisProps, "JAVA_KS_PASSWORD", null);
|
||||||
|
|
||||||
String varUseSSL = propertyProcessor.getProperty(thisProps, "SSL");
|
String varPropAuthRequired = propertyProcessor.getProperty(thisProps, "AUTH_REQUIRED", "true");
|
||||||
String varKeystore_LOC = propertyProcessor.getProperty(thisProps, "JAVA_KS_LOCATION");
|
|
||||||
String varKeystore_PW = propertyProcessor.getProperty(thisProps, "JAVA_KS_PASSWORD");
|
|
||||||
|
|
||||||
String varInputFile = propertyProcessor.getProperty(thisProps, "XML_FILE");
|
String varPropUseSSL = propertyProcessor.getProperty(thisProps, "SSL", "true");
|
||||||
|
|
||||||
String varRoleFile = propertyProcessor.getProperty(thisProps, "CSV_FILE");
|
String varPropEmptyColumns = propertyProcessor.getProperty(thisProps, "CSV_ALLOW_EMPTY_COLUMN_VALUES", "false");
|
||||||
String varPropEmptyColumns = propertyProcessor.getProperty(thisProps, "CSV_ALLOW_EMPTY_COLUMN_VALUES");
|
|
||||||
Boolean varEmptyColumns = Boolean.valueOf(varPropEmptyColumns);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File checkInput = new File(varInputFile);
|
File checkInput = new File(varInputFile);
|
||||||
@ -113,6 +108,11 @@ public class webService {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (varURL.isEmpty())
|
||||||
|
{
|
||||||
|
throw new RuntimeException("SHIM_URL cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
File checkRole = new File(varRoleFile);
|
File checkRole = new File(varRoleFile);
|
||||||
if (!checkRole.exists()) {
|
if (!checkRole.exists()) {
|
||||||
debugProcessor.writer(true, thisProps + " => The file specified in CSV_FILE does not exist [ " + varRoleFile + " ]");
|
debugProcessor.writer(true, thisProps + " => The file specified in CSV_FILE does not exist [ " + varRoleFile + " ]");
|
||||||
@ -122,23 +122,26 @@ public class webService {
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
debugProcessor.writer(true, "Please check that the properties file " + thisProps + " is correctly formatted!");
|
debugProcessor.writer(true, thisProps + " => The properties file is missing a required value!");
|
||||||
|
debugProcessor.writer(true, thisProps + " => Required values : SHIM_URL, XML_FILE, CSV_FILE");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
String varAuthProp = propertyProcessor.getProperty(thisProps, "AUTH_REQUIRED");
|
Boolean varUseSSL = Boolean.valueOf(varPropUseSSL);
|
||||||
Boolean varAuthRequired = Boolean.valueOf(varAuthProp);
|
Boolean varAuthRequired = Boolean.valueOf(varPropAuthRequired);
|
||||||
String varUsername = propertyProcessor.getProperty(thisProps, "USERNAME");
|
Boolean varEmptyColumns = Boolean.valueOf(varPropEmptyColumns);
|
||||||
|
|
||||||
|
String varUsername = propertyProcessor.getProperty(thisProps, "USERNAME", null);
|
||||||
if (varAuthRequired && varUsername == null)
|
if (varAuthRequired && varUsername == null)
|
||||||
{
|
{
|
||||||
varUsername = userCreds.getUsername();
|
varUsername = userCreds.getUsername("Please enter your username : ");
|
||||||
}
|
}
|
||||||
|
|
||||||
String varPasswordTemp = propertyProcessor.getProperty(thisProps, "PASSWORD");
|
String varPasswordTemp = propertyProcessor.getProperty(thisProps, "PASSWORD", null);
|
||||||
if (varAuthRequired && varPasswordTemp == null)
|
if (varAuthRequired && varPasswordTemp == null)
|
||||||
{
|
{
|
||||||
char[] varUserPW = userCreds.getPassword();
|
char[] varUserPW = userCreds.getPassword("Please enter your password : ");
|
||||||
varPasswordTemp = salter.encrypt(String.copyValueOf(varUserPW), varKey, varSalt);
|
varPasswordTemp = salter.encrypt(String.copyValueOf(varUserPW), varKey, varSalt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,13 +157,13 @@ public class webService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debugProcessor.writer(varDebug, "");
|
debugProcessor.writer(varDebug, "");
|
||||||
debugProcessor.writer(varDebug, thisProps + " => SOAP URL : " + varURL);
|
debugProcessor.writer(varDebug, thisProps + " => SOAP URL : " + (varURL == null ? "" : varURL));
|
||||||
debugProcessor.writer(varDebug, thisProps + " => Authentication required : " + varAuthRequired);
|
debugProcessor.writer(varDebug, thisProps + " => Authentication required : " + varAuthRequired);
|
||||||
debugProcessor.writer(varDebug, thisProps + " => Use SSL : " + varUseSSL);
|
debugProcessor.writer(varDebug, thisProps + " => Use SSL : " + varUseSSL);
|
||||||
debugProcessor.writer(varDebug, thisProps + " => JAVA keystore : " + varKeystore_LOC);
|
debugProcessor.writer(varDebug, thisProps + " => JAVA keystore location : " + (varKeystore_LOC == null ? "" : varKeystore_LOC));
|
||||||
debugProcessor.writer(varDebug, thisProps + " => JAVA keystore password : " + varKeystore_PW);
|
debugProcessor.writer(varDebug, thisProps + " => JAVA keystore password : " + (varKeystore_PW == null ? "" : varKeystore_PW));
|
||||||
debugProcessor.writer(varDebug, thisProps + " => XML file : " + varInputFile);
|
debugProcessor.writer(varDebug, thisProps + " => XML file : " + (varInputFile == null ? "" : varInputFile));
|
||||||
debugProcessor.writer(varDebug, thisProps + " => CSV file : " + varRoleFile);
|
debugProcessor.writer(varDebug, thisProps + " => CSV file : " + (varRoleFile == null ? "" : varRoleFile));
|
||||||
debugProcessor.writer(varDebug, thisProps + " => CSV allow empty : " + varEmptyColumns);
|
debugProcessor.writer(varDebug, thisProps + " => CSV allow empty : " + varEmptyColumns);
|
||||||
|
|
||||||
if (!varAuthRequired)
|
if (!varAuthRequired)
|
||||||
@ -188,7 +191,7 @@ public class webService {
|
|||||||
while (mapper1.hasNext()) {
|
while (mapper1.hasNext()) {
|
||||||
varCount++;
|
varCount++;
|
||||||
debugProcessor.writer(true, "");
|
debugProcessor.writer(true, "");
|
||||||
debugProcessor.writer(true, "processing record " + varCount);
|
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : processing started");
|
||||||
|
|
||||||
Map hashMap = mapper1.next();
|
Map hashMap = mapper1.next();
|
||||||
debugProcessor.writer(varDebug, "record " + varCount + " : " + hashMap.values().toString());
|
debugProcessor.writer(varDebug, "record " + varCount + " : " + hashMap.values().toString());
|
||||||
@ -205,18 +208,21 @@ public class webService {
|
|||||||
if (varDocument != null && !varDocument.isEmpty())
|
if (varDocument != null && !varDocument.isEmpty())
|
||||||
{
|
{
|
||||||
String varCredentials = soapProcessor.getCredentials(varUsername, varPassword);
|
String varCredentials = soapProcessor.getCredentials(varUsername, varPassword);
|
||||||
Boolean isSSL = Boolean.parseBoolean(varUseSSL);
|
|
||||||
|
|
||||||
debugProcessor.writer(varDebug, "connecting to URL : " + varURL);
|
debugProcessor.writer(varDebug, "connecting to URL : " + varURL);
|
||||||
HttpURLConnection varConn = soapProcessor.getConnection(varCredentials, varURL, isSSL, varKeystore_LOC, varKeystore_PW);
|
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(varDebug, "sending document : " + varDocument);
|
|
||||||
String response = soapProcessor.send(varConn, varInputFile, hashMap, varDocument.getBytes());
|
String response = soapProcessor.send(varConn, varInputFile, hashMap, varDocument.getBytes());
|
||||||
|
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : XML document sent");
|
||||||
|
|
||||||
debugProcessor.writer(varDebug, "response received : " + response);
|
debugProcessor.writer(varDebug, "response received : " + response);
|
||||||
if (varConn != null)
|
if (varConn != null)
|
||||||
{
|
{
|
||||||
soapProcessor.closeConnection(varConn);
|
soapProcessor.closeConnection(varConn);
|
||||||
|
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : closed connection");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user