mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 09:07:27 -05:00
Fix OpenMHz Reconnection Issue.
This commit is contained in:
@@ -54,6 +54,7 @@
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.net.ConnectException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
@@ -69,6 +70,7 @@
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Audio broadcaster to push completed audio recordings to the OpenMHz call upload API.
|
* Audio broadcaster to push completed audio recordings to the OpenMHz call upload API.
|
||||||
*
|
*
|
||||||
@@ -115,14 +117,15 @@
|
|||||||
String response = testConnection(getBroadcastConfiguration());
|
String response = testConnection(getBroadcastConfiguration());
|
||||||
mLastConnectionAttempt = System.currentTimeMillis();
|
mLastConnectionAttempt = System.currentTimeMillis();
|
||||||
|
|
||||||
/**
|
if(response == "OK")
|
||||||
* OpenMHz API does not currently expose a test method.
|
|
||||||
* TODO: FIX THIS
|
|
||||||
*/
|
|
||||||
if(response == "OK")// && response.toLowerCase().startsWith("<head><title>502 bad gateway</title></head>"))
|
|
||||||
{
|
{
|
||||||
setBroadcastState(BroadcastState.CONNECTED);
|
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
|
else
|
||||||
{
|
{
|
||||||
mLog.error("Error connecting to OpenMHz server on startup [" + response + "]");
|
mLog.error("Error connecting to OpenMHz server on startup [" + response + "]");
|
||||||
@@ -170,8 +173,6 @@
|
|||||||
* Indicates if this broadcaster continues to have successful connections to and transactions with the remote
|
* 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
|
* 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.
|
* 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()
|
private boolean connected()
|
||||||
{
|
{
|
||||||
@@ -183,14 +184,21 @@
|
|||||||
String response = testConnection(getBroadcastConfiguration());
|
String response = testConnection(getBroadcastConfiguration());
|
||||||
mLastConnectionAttempt = System.currentTimeMillis();
|
mLastConnectionAttempt = System.currentTimeMillis();
|
||||||
|
|
||||||
if(response != null && response == "200")
|
if(response == "OK")
|
||||||
{
|
{
|
||||||
setBroadcastState(BroadcastState.CONNECTED);
|
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
|
else
|
||||||
{
|
{
|
||||||
setBroadcastState(BroadcastState.ERROR);
|
setBroadcastState(BroadcastState.ERROR);
|
||||||
|
mLog.error("Error reconnecting to OpenMHz server [" + response + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return getBroadcastState() == BroadcastState.CONNECTED;
|
return getBroadcastState() == BroadcastState.CONNECTED;
|
||||||
@@ -565,8 +573,8 @@
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpResponse<String> response = httpClient.send(request, responseHandler);
|
HttpResponse<String> response = httpClient.send(request, responseHandler);
|
||||||
String responseBody = response.body();
|
|
||||||
if (response.statusCode() == 200)
|
if (response.statusCode() == 200)
|
||||||
{
|
{
|
||||||
return "OK";
|
return "OK";
|
||||||
@@ -584,7 +592,15 @@
|
|||||||
}
|
}
|
||||||
catch(Exception e)
|
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user