From 6f3e7c86e591bb666fbfca85d7da211ff1600bd7 Mon Sep 17 00:00:00 2001
From: tadscottsmith <78445808+tadscottsmith@users.noreply.github.com>
Date: Wed, 10 Jan 2024 14:58:46 -0600
Subject: [PATCH 1/2] Fix OpenMHz Reconnection Issue.
---
.../broadcast/openmhz/OpenMHzBroadcaster.java | 40 +++++++++++++------
1 file changed, 28 insertions(+), 12 deletions(-)
diff --git a/src/main/java/io/github/dsheirer/audio/broadcast/openmhz/OpenMHzBroadcaster.java b/src/main/java/io/github/dsheirer/audio/broadcast/openmhz/OpenMHzBroadcaster.java
index 4d1441a96..cc7893dee 100644
--- a/src/main/java/io/github/dsheirer/audio/broadcast/openmhz/OpenMHzBroadcaster.java
+++ b/src/main/java/io/github/dsheirer/audio/broadcast/openmhz/OpenMHzBroadcaster.java
@@ -54,6 +54,7 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
+ import java.net.ConnectException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
@@ -69,6 +70,7 @@
import java.util.concurrent.TimeUnit;
+
/**
* Audio broadcaster to push completed audio recordings to the OpenMHz call upload API.
*
@@ -115,14 +117,15 @@ public void start()
String response = testConnection(getBroadcastConfiguration());
mLastConnectionAttempt = System.currentTimeMillis();
- /**
- * OpenMHz API does not currently expose a test method.
- * TODO: FIX THIS
- */
- if(response == "OK")// && response.toLowerCase().startsWith("
502 bad gateway"))
+ if(response == "OK")
{
setBroadcastState(BroadcastState.CONNECTED);
}
+ else if (response == "No Response")
+ {
+ setBroadcastState(BroadcastState.NO_SERVER);
+ mLog.error("Error connecting to OpenMHz server [Server not found or not reachable]");
+ }
else
{
mLog.error("Error connecting to OpenMHz server on startup [" + response + "]");
@@ -170,8 +173,6 @@ public void dispose()
* Indicates if this broadcaster continues to have successful connections to and transactions with the remote
* server. If there is a connectivity or other issue, the broadcast state is set to temporary error and
* the audio processor thread will persistently invoke this method to attempt a reconnect.
- *
- * OpenMHz does not have a test API endpoint, so we look for the incomplete call response.
*/
private boolean connected()
{
@@ -183,14 +184,21 @@ private boolean connected()
String response = testConnection(getBroadcastConfiguration());
mLastConnectionAttempt = System.currentTimeMillis();
- if(response != null && response == "200")
+ if(response == "OK")
{
setBroadcastState(BroadcastState.CONNECTED);
}
+ else if (response == "No Response")
+ {
+ setBroadcastState(BroadcastState.NO_SERVER);
+ mLog.error("Error connecting to OpenMHz server [Server not found or not reachable]");
+ }
else
{
setBroadcastState(BroadcastState.ERROR);
+ mLog.error("Error reconnecting to OpenMHz server [" + response + "]");
}
+
}
return getBroadcastState() == BroadcastState.CONNECTED;
@@ -565,8 +573,8 @@ public static String testConnection(OpenMHzConfiguration configuration)
try
{
- HttpResponse response = httpClient.send(request, responseHandler);
- String responseBody = response.body();
+ HttpResponse response = httpClient.send(request, responseHandler);
+
if (response.statusCode() == 200)
{
return "OK";
@@ -583,8 +591,16 @@ else if(response.statusCode() == 500)
return "No Response";
}
catch(Exception e)
- {
- return e.getLocalizedMessage();
+ {
+ Throwable throwableCause = e.getCause();
+
+ if(throwableCause instanceof ConnectException)
+ {
+ return "No Response";
+ }
+
+ mLog.error("Exception connecting to OpenMHz server [" + e.toString() + "]");
+ return "Uknown Exception";
}
}
From 7c5ef3803a649fbf24a2c420f8e67836f6c2c611 Mon Sep 17 00:00:00 2001
From: tadscottsmith <78445808+tadscottsmith@users.noreply.github.com>
Date: Wed, 10 Jan 2024 19:06:43 -0600
Subject: [PATCH 2/2] Fix typo.
---
.../dsheirer/audio/broadcast/openmhz/OpenMHzBroadcaster.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/io/github/dsheirer/audio/broadcast/openmhz/OpenMHzBroadcaster.java b/src/main/java/io/github/dsheirer/audio/broadcast/openmhz/OpenMHzBroadcaster.java
index cc7893dee..f8c49a693 100644
--- a/src/main/java/io/github/dsheirer/audio/broadcast/openmhz/OpenMHzBroadcaster.java
+++ b/src/main/java/io/github/dsheirer/audio/broadcast/openmhz/OpenMHzBroadcaster.java
@@ -191,7 +191,7 @@ private boolean connected()
else if (response == "No Response")
{
setBroadcastState(BroadcastState.NO_SERVER);
- mLog.error("Error connecting to OpenMHz server [Server not found or not reachable]");
+ mLog.error("Error reconnecting to OpenMHz server [Server not found or not reachable]");
}
else
{