Return Map so we can get more information

This commit is contained in:
Keith Armstrong 2025-01-09 19:29:06 -05:00
parent 3f2b24fe19
commit db528c70cd

View File

@ -10,9 +10,14 @@ 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.util.Base64; import java.util.Base64;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static java.lang.System.out;
public class soapProcessor { public class soapProcessor {
public static String getCredentials(String username, String password) throws Exception public static String getCredentials(String username, String password) throws Exception
@ -60,14 +65,16 @@ public class soapProcessor {
} }
catch (Exception ex) catch (Exception ex)
{ {
System.out.println(ex.toString()); out.println(ex.toString());
return null; 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); StringBuilder response = new StringBuilder(500);
Map thisMap = new HashMap();
int thisCode = -1;
try { try {
ByteArrayOutputStream outstr = new ByteArrayOutputStream(); ByteArrayOutputStream outstr = new ByteArrayOutputStream();
@ -77,13 +84,14 @@ public class soapProcessor {
thisConn.setDoOutput(true); thisConn.setDoOutput(true);
thisConn.setDoInput(true); thisConn.setDoInput(true);
OutputStream out = thisConn.getOutputStream(); OutputStream thisOut = thisConn.getOutputStream();
out.write(document); thisOut.write(document);
out.close(); thisOut.close();
InputStreamReader ireader = new InputStreamReader(thisConn.getInputStream()); InputStreamReader ireader = new InputStreamReader(thisConn.getInputStream());
BufferedReader in = new BufferedReader(ireader); BufferedReader in = new BufferedReader(ireader);
thisCode = thisConn.getResponseCode();
String inputLine; String inputLine;
while ((inputLine = in.readLine()) != null) while ((inputLine = in.readLine()) != null)
{ {
@ -94,11 +102,18 @@ public class soapProcessor {
} }
catch (Exception ex) catch (Exception ex)
{ {
System.out.println(ex.toString()); thisMap.put("success", false);
return ex.toString(); 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 static