Add SOAP return details to hashmap
hashMap is used to log more debug information
This commit is contained in:
parent
6f8600057d
commit
79cb46092e
@ -10,7 +10,6 @@ import java.io.OutputStream;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -102,10 +101,18 @@ public class soapProcessor {
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
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("success", false);
|
||||||
thisMap.put("sent", new String(document, StandardCharsets.UTF_8));
|
thisMap.put("sent", new String(document, StandardCharsets.UTF_8));
|
||||||
thisMap.put("response", ex.toString());
|
thisMap.put("response", ex.toString());
|
||||||
thisMap.put("code", thisCode);
|
thisMap.put("code", exCode);
|
||||||
return thisMap;
|
return thisMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,8 +121,8 @@ public class userVerify
|
|||||||
Iterable<CSVRecord> records = csvFormat.parse(in);
|
Iterable<CSVRecord> records = csvFormat.parse(in);
|
||||||
|
|
||||||
int thisHeaderLength = varHeader.split(",").length;
|
int thisHeaderLength = varHeader.split(",").length;
|
||||||
debugProcessor.writer(fromUser, "CSV header length : " + thisHeaderLength);
|
debugProcessor.writer(fromUser, "CSV header length : " + thisHeaderLength);
|
||||||
debugProcessor.writer(fromUser, "CSV header tokens : " + varHeader);
|
debugProcessor.writer(fromUser, "CSV header tokens : " + varHeader);
|
||||||
debugProcessor.writer(fromUser, "");
|
debugProcessor.writer(fromUser, "");
|
||||||
|
|
||||||
for (CSVRecord record : records)
|
for (CSVRecord record : records)
|
||||||
|
@ -33,7 +33,6 @@ public class webService {
|
|||||||
|
|
||||||
jCommanderArgs args = new jCommanderArgs();
|
jCommanderArgs args = new jCommanderArgs();
|
||||||
JCommander jct = new JCommander(args);
|
JCommander jct = new JCommander(args);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jct.parse(argv);
|
jct.parse(argv);
|
||||||
} catch (ParameterException ex) {
|
} catch (ParameterException ex) {
|
||||||
@ -47,6 +46,11 @@ public class webService {
|
|||||||
|
|
||||||
if (varToEncrypt != null && !varToEncrypt.isEmpty())
|
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 varToStore = encyptProcessor.encrypt(varToEncrypt, varKey, varSalt);
|
||||||
String varChecked = encyptProcessor.decrypt(varToStore, varKey, varSalt);
|
String varChecked = encyptProcessor.decrypt(varToStore, varKey, varSalt);
|
||||||
|
|
||||||
@ -77,13 +81,25 @@ public class webService {
|
|||||||
if (varProps != null)
|
if (varProps != null)
|
||||||
{
|
{
|
||||||
Map thisFinal = doSoap(new File(varProps));
|
Map thisFinal = doSoap(new File(varProps));
|
||||||
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
debugProcessor.writer(true, "!! Total records : " + thisFinal.get("total"));
|
Map map = (Map) thisFinal.get("results");
|
||||||
debugProcessor.writer(true, "!! Total passed : " + thisFinal.get("passed"));
|
Iterator<Map.Entry<Integer, Map>> iterator = map.entrySet().iterator();
|
||||||
debugProcessor.writer(true, "!! Total failed : " + thisFinal.get("failed"));
|
|
||||||
|
while (iterator.hasNext())
|
||||||
|
{
|
||||||
|
Map.Entry<Integer, Map> 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");
|
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)
|
if (!thisResult)
|
||||||
{
|
{
|
||||||
debugProcessor.writer(true, "!! PLEASE CHECK THE DEBUG LOG");
|
debugProcessor.writer(true, "!! PLEASE CHECK THE DEBUG LOG");
|
||||||
@ -100,7 +116,7 @@ public class webService {
|
|||||||
int varFailed = 0;
|
int varFailed = 0;
|
||||||
Map varResult = new HashMap();
|
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 varURL = propertyProcessor.getProperty(thisProps, "SHIM_URL", null);
|
||||||
String varKeystore_LOC = propertyProcessor.getProperty(thisProps, "JAVA_KS_LOCATION", 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);
|
String varUsername = propertyProcessor.getProperty(thisProps, "USERNAME", null);
|
||||||
if (varAuthRequired && varUsername == 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);
|
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 : ");
|
// This is just a temporary key so that the rest of the code does not error out!
|
||||||
varPasswordTemp = encyptProcessor.encrypt(String.copyValueOf(varUserPW), varKey, varSalt);
|
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
|
try
|
||||||
{
|
{
|
||||||
@ -198,14 +225,16 @@ public class webService {
|
|||||||
|
|
||||||
boolean validfile = (!thisCSV.isEmpty());
|
boolean validfile = (!thisCSV.isEmpty());
|
||||||
debugProcessor.writer(varDebug, "");
|
debugProcessor.writer(varDebug, "");
|
||||||
debugProcessor.writer(true, varRoleFile + " => CSV file is valid : " + validfile);
|
debugProcessor.writer(true, "CSV file is valid : " + validfile);
|
||||||
debugProcessor.writer(true, varRoleFile + " => records to process : " + thisCSV.size());
|
debugProcessor.writer(true, "CSV records to process : " + thisCSV.size());
|
||||||
|
|
||||||
if (!validfile)
|
if (!validfile)
|
||||||
{
|
{
|
||||||
debugProcessor.writer(true, varRoleFile + " => verification failed : 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;
|
int varCount = 0;
|
||||||
|
Map resultMap = new HashMap();
|
||||||
Iterator<Map> mapper1 = thisCSV.iterator();
|
Iterator<Map> mapper1 = thisCSV.iterator();
|
||||||
while (mapper1.hasNext()) {
|
while (mapper1.hasNext()) {
|
||||||
varCount++;
|
varCount++;
|
||||||
@ -213,8 +242,6 @@ public class webService {
|
|||||||
debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : processing started");
|
debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : processing started");
|
||||||
|
|
||||||
Map hashMap = mapper1.next();
|
Map hashMap = mapper1.next();
|
||||||
debugProcessor.writer(varDebug, "record " + varCount + " : " + hashMap.values().toString());
|
|
||||||
|
|
||||||
Iterator<Map.Entry<Integer, Integer>> it = hashMap.entrySet().iterator();
|
Iterator<Map.Entry<Integer, Integer>> it = hashMap.entrySet().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
@ -232,7 +259,7 @@ public class webService {
|
|||||||
for(Object key: hashMap.keySet())
|
for(Object key: hashMap.keySet())
|
||||||
{
|
{
|
||||||
Boolean varHasText = fileProcessor.stringHasText(varXML, key.toString());
|
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<Boolean, String> errorMap = new HashMap();
|
HashMap<Boolean, String> errorMap = new HashMap();
|
||||||
@ -243,24 +270,36 @@ public class webService {
|
|||||||
{
|
{
|
||||||
String varCredentials = soapProcessor.getCredentials(varUsername, varPassword);
|
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);
|
HttpURLConnection varConn = soapProcessor.getConnection(varCredentials, varURL, varUseSSL, varKeystore_LOC, varKeystore_PW);
|
||||||
|
|
||||||
debugProcessor.writer(true, "[" + varCount + " of " + thisCSV.size() + "] : sending XML document");
|
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);
|
debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : SOAP call sending data : " + varXML);
|
||||||
|
|
||||||
Map response = soapProcessor.send(varConn, varXML.getBytes());
|
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 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());
|
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)
|
if (!varSuccess)
|
||||||
{
|
{
|
||||||
debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : " + hashMap.toString());
|
debugProcessor.writer(varDebug, "[" + varCount + " of " + thisCSV.size() + "] : " + hashMap.toString());
|
||||||
varFailed++;
|
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)
|
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("total", thisCSV.size());
|
||||||
varResult.put("passed", thisCSV.size() - varFailed);
|
varResult.put("passed", thisCSV.size() - varFailed);
|
||||||
varResult.put("failed", varFailed);
|
varResult.put("failed", varFailed);
|
||||||
|
varResult.put("results", resultMap);
|
||||||
return varResult;
|
return varResult;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user