Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
34dd7513fd
1 changed files with 11 additions and 6 deletions
|
@ -3,6 +3,8 @@ package net.osmand.plus.monitoring;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -137,21 +139,24 @@ public class LiveMonitoringHelper {
|
||||||
HttpParams params = new BasicHttpParams();
|
HttpParams params = new BasicHttpParams();
|
||||||
HttpConnectionParams.setConnectionTimeout(params, 15000);
|
HttpConnectionParams.setConnectionTimeout(params, 15000);
|
||||||
DefaultHttpClient httpclient = new DefaultHttpClient(params);
|
DefaultHttpClient httpclient = new DefaultHttpClient(params);
|
||||||
HttpRequestBase method = new HttpGet(url);
|
// Parse the URL and let the URI constructor handle proper encoding of special characters such as spaces
|
||||||
log.info("Monitor " + url);
|
URL u = new URL(url);
|
||||||
|
URI uri = new URI(u.getProtocol(), u.getAuthority(), u.getHost(), u.getPort(), u.getPath(), u.getQuery(), u.getRef());
|
||||||
|
HttpRequestBase method = new HttpGet(uri);
|
||||||
|
log.info("Monitor " + uri);
|
||||||
HttpResponse response = httpclient.execute(method);
|
HttpResponse response = httpclient.execute(method);
|
||||||
|
|
||||||
if(response.getStatusLine() == null ||
|
if(response.getStatusLine() == null ||
|
||||||
response.getStatusLine().getStatusCode() != 200){
|
response.getStatusLine().getStatusCode() != 200){
|
||||||
|
|
||||||
String msg;
|
String msg;
|
||||||
if(response.getStatusLine() != null){
|
if(response.getStatusLine() == null){
|
||||||
msg = ctx.getString(R.string.failed_op); //$NON-NLS-1$
|
msg = ctx.getString(R.string.failed_op); //$NON-NLS-1$
|
||||||
} else {
|
} else {
|
||||||
msg = response.getStatusLine().getStatusCode() + " : " + //$NON-NLS-1$//$NON-NLS-2$
|
msg = response.getStatusLine().getStatusCode() + " : " + //$NON-NLS-1$//$NON-NLS-2$
|
||||||
response.getStatusLine().getReasonPhrase();
|
response.getStatusLine().getReasonPhrase();
|
||||||
}
|
}
|
||||||
log.error("Error sending monitor request request : " + msg);
|
log.error("Error sending monitor request: " + msg);
|
||||||
} else {
|
} else {
|
||||||
InputStream is = response.getEntity().getContent();
|
InputStream is = response.getEntity().getContent();
|
||||||
StringBuilder responseBody = new StringBuilder();
|
StringBuilder responseBody = new StringBuilder();
|
||||||
|
@ -165,12 +170,12 @@ public class LiveMonitoringHelper {
|
||||||
is.close();
|
is.close();
|
||||||
}
|
}
|
||||||
httpclient.getConnectionManager().shutdown();
|
httpclient.getConnectionManager().shutdown();
|
||||||
log.info("Montior response : " + responseBody);
|
log.info("Monitor response (" + response.getFirstHeader("Content-Type") + "): " + responseBody.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed connect to " + url, e);
|
log.error("Failed connect to " + url + ": " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue