From db528c70cd93d58ad8a85c09be05b9a5e0785e03 Mon Sep 17 00:00:00 2001 From: Keith Armstrong Date: Thu, 9 Jan 2025 19:29:06 -0500 Subject: [PATCH] Return Map so we can get more information --- src/com/belkast/soap/soapProcessor.java | 31 ++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/com/belkast/soap/soapProcessor.java b/src/com/belkast/soap/soapProcessor.java index d9c2eb9..d4b0f03 100644 --- a/src/com/belkast/soap/soapProcessor.java +++ b/src/com/belkast/soap/soapProcessor.java @@ -10,9 +10,14 @@ 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; import java.util.Map; +import static java.lang.System.out; + public class soapProcessor { public static String getCredentials(String username, String password) throws Exception @@ -60,14 +65,16 @@ public class soapProcessor { } catch (Exception ex) { - System.out.println(ex.toString()); + out.println(ex.toString()); return null; } } - public static String send(HttpURLConnection thisConn, String varInputFile, Map hashMap, byte[] document) throws Exception + public static Map send(HttpURLConnection thisConn, byte[] document) throws Exception { StringBuilder response = new StringBuilder(500); + Map thisMap = new HashMap(); + int thisCode = -1; try { ByteArrayOutputStream outstr = new ByteArrayOutputStream(); @@ -77,13 +84,14 @@ public class soapProcessor { thisConn.setDoOutput(true); thisConn.setDoInput(true); - OutputStream out = thisConn.getOutputStream(); - out.write(document); - out.close(); + OutputStream thisOut = thisConn.getOutputStream(); + thisOut.write(document); + thisOut.close(); InputStreamReader ireader = new InputStreamReader(thisConn.getInputStream()); BufferedReader in = new BufferedReader(ireader); + thisCode = thisConn.getResponseCode(); String inputLine; while ((inputLine = in.readLine()) != null) { @@ -94,11 +102,18 @@ public class soapProcessor { } catch (Exception ex) { - System.out.println(ex.toString()); - return ex.toString(); + thisMap.put("success", false); + thisMap.put("sent", new String(document, StandardCharsets.UTF_8)); + thisMap.put("response", ex.toString()); + thisMap.put("code", thisCode); + return thisMap; } - return response.toString(); + thisMap.put("success", true); + thisMap.put("sent", new String(document, StandardCharsets.UTF_8)); + thisMap.put("response", response.toString()); + thisMap.put("code", thisCode); + return thisMap; } static