]> git.ktnx.net Git - mobile-ledger.git/commitdiff
SendTransactionTask: log full request JSON in simulation mode (debug builds)
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 10 Dec 2019 19:56:22 +0000 (21:56 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 10 Dec 2019 19:56:22 +0000 (21:56 +0200)
app/src/main/java/net/ktnx/mobileledger/async/SendTransactionTask.java

index cfbf5222c30a24ff41c9c1282a664da17e61a46e..496624bf52475a6c22e6e2a2388d9d48d44aa53b 100644 (file)
@@ -71,7 +71,19 @@ public class SendTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
         simulate = false;
     }
     private boolean sendOK() throws IOException {
+        HttpURLConnection http = NetworkUtil.prepareConnection(mProfile, "add");
+        http.setRequestMethod("PUT");
+        http.setRequestProperty("Content-Type", "application/json");
+        http.setRequestProperty("Accept", "*/*");
+
+        ParsedLedgerTransaction jsonTransaction;
+        jsonTransaction = ltr.toParsedLedgerTransaction();
+        ObjectMapper mapper = new ObjectMapper();
+        ObjectWriter writer = mapper.writerFor(ParsedLedgerTransaction.class);
+        String body = writer.writeValueAsString(jsonTransaction);
+
         if (simulate) {
+            debug("network", "The request would be: " + body);
             try {
                 Thread.sleep(1500);
                 if (Math.random() > 0.3)
@@ -84,17 +96,6 @@ public class SendTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
             return true;
         }
 
-        HttpURLConnection http = NetworkUtil.prepareConnection(mProfile, "add");
-        http.setRequestMethod("PUT");
-        http.setRequestProperty("Content-Type", "application/json");
-        http.setRequestProperty("Accept", "*/*");
-
-        ParsedLedgerTransaction jsonTransaction;
-        jsonTransaction = ltr.toParsedLedgerTransaction();
-        ObjectMapper mapper = new ObjectMapper();
-        ObjectWriter writer = mapper.writerFor(ParsedLedgerTransaction.class);
-        String body = writer.writeValueAsString(jsonTransaction);
-
         byte[] bodyBytes = body.getBytes(StandardCharsets.UTF_8);
         http.setDoOutput(true);
         http.setDoInput(true);