use of org.apache.http.conn.HttpHostConnectException in project OpenTripPlanner by opentripplanner.
the class AnalystWorker method getSomeWork.
public List<AnalystClusterRequest> getSomeWork(WorkType type) {
// Run a POST request (long-polling for work) indicating which graph this worker prefers to work on
String url;
if (type == WorkType.HIGH_PRIORITY) {
// this is a side-channel request for single point work
url = BROKER_BASE_URL + "/single/" + graphId;
} else {
url = BROKER_BASE_URL + "/dequeue/" + graphId;
}
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader(new BasicHeader(WORKER_ID_HEADER, machineId));
HttpResponse response = null;
try {
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
if (entity == null) {
return null;
}
if (response.getStatusLine().getStatusCode() != 200) {
EntityUtils.consumeQuietly(entity);
return null;
}
return objectMapper.readValue(entity.getContent(), new TypeReference<List<AnalystClusterRequest>>() {
});
} catch (JsonProcessingException e) {
LOG.error("JSON processing exception while getting work", e);
} catch (SocketTimeoutException stex) {
LOG.error("Socket timeout while waiting to receive work.");
} catch (HttpHostConnectException ce) {
LOG.error("Broker refused connection. Sleeping before retry.");
try {
Thread.currentThread().sleep(5000);
} catch (InterruptedException e) {
}
} catch (IOException e) {
LOG.error("IO exception while getting work", e);
}
return null;
}
use of org.apache.http.conn.HttpHostConnectException in project bboss-elastic by bbossgroups.
the class ElasticSearchRestClient method execute.
public String execute(final String entity, String options) throws ElasticSearchException {
String endpoint = BULK_ENDPOINT;
if (options != null) {
endpoint = new StringBuilder().append(endpoint).append("?").append(options).toString();
}
final ESStringResponseHandler responseHandler = new ESStringResponseHandler();
return _executeHttp(endpoint, responseHandler, new ExecuteRequest() {
@Override
public Object execute(ESAddress host, String url, int triesCount) throws Exception {
Object response = null;
if (showTemplate) {
if (logger.isInfoEnabled()) {
logger.info("ElasticSearch http request endpoint:{},retry:{},request body:\n{}", url, triesCount, entity);
}
}
response = restSeachExecutor.execute(url, entity, responseHandler);
return response;
}
});
/**
* int triesCount = 0;
* String response = null;
* Throwable e = null;
* ESAddress host = null;
* String url = null;
*
* while (true) {
*
* try {
* host = serversList.get(failAllContinue || !this.healthCheckEnabled());
* url = new StringBuilder().append(host.getAddress()).append( "/" ).append( endpoint).toString();
*
*// response = HttpRequestUtil.sendJsonBody(httpPool,entity, url, this.headers);
* if(this.showTemplate ){
* if(logger.isInfoEnabled()) {
* logger.info("ElasticSearch http request endpoint:{},retry:{},request body:\n{}",url,triesCount,entity);
* }
*
* }
* ESStringResponseHandler responseHandler = new ESStringResponseHandler();
* response = restSeachExecutor.execute(url,entity,responseHandler);
* e = getException( responseHandler );
* break;
* }
* catch (HttpHostConnectException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* } catch (UnknownHostException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
* catch (NoRouteToHostException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
* catch (NoHttpResponseException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
* catch (ConnectionPoolTimeoutException ex){//连接池获取connection超时,直接抛出
*
* e = handleConnectionPoolTimeOutException( ex);
* break;
* }
* catch (ConnectTimeoutException connectTimeoutException){
* host.setStatus(1);
* e = handleConnectionTimeOutException(connectTimeoutException);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
* }
*// catch (IOException ex) {
*// host.setStatus(1);
*// if (triesCount < serversList.size()) {//失败尝试下一个地址
*// triesCount++;
*// e = ex;
*// continue;
*// } else {
*// e = ex;
*// break;
*// }
*//
*// }
* catch (SocketTimeoutException ex) {
* e = handleSocketTimeoutException( ex);
* break;
* }
* catch (NoServerElasticSearchException ex){
* e = ex;
*
* break;
* }
* catch (ClientProtocolException ex){
* host.setStatus(1);
* e = ex;
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
* //throw new ElasticSearchException(new StringBuilder().append("Request[").append(url).append("] handle failed: must use http/https protocol port such as 9200,do not use transport such as 9300.").toString(),ex);
* }
* catch (ElasticSearchException ex) {
* e = ex;
* break;
* }
* catch (Exception ex) {
* e = ex;
* break;
* }
* catch (Throwable ex) {
* e = ex;
* break;
* }
*
* }
* if (e != null){
* if(e instanceof ElasticSearchException)
* throw (ElasticSearchException)e;
* throw new ElasticSearchException(e);
* }
* return response;
*/
}
use of org.apache.http.conn.HttpHostConnectException in project bboss-elastic by bbossgroups.
the class ElasticSearchRestClient method executeRequest.
public String executeRequest(String path, final String entity) throws ElasticSearchException {
final ESStringResponseHandler responseHandler = new ESStringResponseHandler();
return _executeHttp(path, responseHandler, new ExecuteRequest() {
@Override
public Object execute(ESAddress host, String url, int triesCount) throws Exception {
Object response = null;
if (showTemplate) {
if (logger.isInfoEnabled()) {
if (entity != null)
logger.info("ElasticSearch http request endpoint:{},retry:{},request body:\n{}", url, triesCount, entity);
else
logger.info("ElasticSearch http request endpoint:{},retry:{}", url, triesCount);
}
}
response = restSeachExecutor.executeSimpleRequest(url, entity, responseHandler);
return response;
}
});
/**
* int triesCount = 0;
* String response = null;
* Throwable e = null;
*
* ESAddress host = null;
* String url = null;
* while (true) {
*
* try {
* host = serversList.get(!healthCheckEnabled());
* url = getPath(host.getAddress(),path);
*// if (entity == null)
*// response = HttpRequestUtil.httpPostforString(url, null, this.headers);
*// else
*// response = HttpRequestUtil.sendJsonBody(entity, url, this.headers);
* if(this.showTemplate ){
* if(logger.isInfoEnabled()) {
* if(entity != null)
* logger.info("ElasticSearch http request endpoint:{},retry:{},request body:\n{}",url,triesCount,entity);
* else
* logger.info("ElasticSearch http request endpoint:{},retry:{}",url,triesCount);
* }
* }
* ESStringResponseHandler responseHandler = new ESStringResponseHandler();
* response = this.restSeachExecutor.executeSimpleRequest(url,entity,responseHandler);
* e = getException( responseHandler );
* break;
* }
*
* catch (HttpHostConnectException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* } catch (UnknownHostException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
* catch (NoRouteToHostException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
*
* catch (NoHttpResponseException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
* catch (ConnectionPoolTimeoutException ex){//连接池获取connection超时,直接抛出
*
* e = handleConnectionPoolTimeOutException( ex);
* break;
* }
* catch (ConnectTimeoutException connectTimeoutException){
* host.setStatus(1);
* e = handleConnectionTimeOutException(connectTimeoutException);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
* }
*// catch (IOException ex) {
*// host.setStatus(1);
*// if (triesCount < serversList.size()) {//失败尝试下一个地址
*// triesCount++;
*// e = ex;
*// continue;
*// } else {
*// e = ex;
*// break;
*// }
*//
*// }
* catch (SocketTimeoutException ex) {
* e = handleSocketTimeoutException( ex);
* break;
* }
* catch (NoServerElasticSearchException ex){
* e = ex;
* break;
* }
* catch (ClientProtocolException ex){
* host.setStatus(1);
* e = ex;
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*// throw new ElasticSearchException(new StringBuilder().append("Request[").append(url).append("] handle failed: must use http/https protocol port such as 9200,do not use transport such as 9300.").toString(),ex);
* }
* catch (ElasticSearchException ex) {
* throw ex;
* }
*
* catch (Exception ex) {
* e = ex;
* break;
* }
* catch (Throwable ex) {
* e = ex;
* break;
* }
* }
* if (e != null){
* throw new ElasticSearchException(e);
* }
* return response;
*/
}
use of org.apache.http.conn.HttpHostConnectException in project XPrivacy by M66B.
the class Util method bug.
public static void bug(XHook hook, Throwable ex) {
if (ex instanceof InvocationTargetException) {
InvocationTargetException exex = (InvocationTargetException) ex;
if (exex.getTargetException() != null)
ex = exex.getTargetException();
}
int priority;
if (ex instanceof ActivityShare.AbortException)
priority = Log.WARN;
else if (ex instanceof ActivityShare.ServerException)
priority = Log.WARN;
else if (ex instanceof ConnectTimeoutException)
priority = Log.WARN;
else if (ex instanceof FileNotFoundException)
priority = Log.WARN;
else if (ex instanceof HttpHostConnectException)
priority = Log.WARN;
else if (ex instanceof NameNotFoundException)
priority = Log.WARN;
else if (ex instanceof NoClassDefFoundError)
priority = Log.WARN;
else if (ex instanceof OutOfMemoryError)
priority = Log.WARN;
else if (ex instanceof RuntimeException)
priority = Log.WARN;
else if (ex instanceof SecurityException)
priority = Log.WARN;
else if (ex instanceof SocketTimeoutException)
priority = Log.WARN;
else if (ex instanceof SSLPeerUnverifiedException)
priority = Log.WARN;
else if (ex instanceof StackOverflowError)
priority = Log.WARN;
else if (ex instanceof TransactionTooLargeException)
priority = Log.WARN;
else if (ex instanceof UnknownHostException)
priority = Log.WARN;
else if (ex instanceof UnsatisfiedLinkError)
priority = Log.WARN;
else
priority = Log.ERROR;
boolean xprivacy = false;
for (StackTraceElement frame : ex.getStackTrace()) if (frame.getClassName() != null && frame.getClassName().startsWith("biz.bokhorst.xprivacy")) {
xprivacy = true;
break;
}
if (!xprivacy)
priority = Log.WARN;
log(hook, priority, ex.toString() + " uid=" + Process.myUid() + "\n" + Log.getStackTraceString(ex));
}
use of org.apache.http.conn.HttpHostConnectException in project Talon-for-Twitter by klinker24.
the class TweetMarkerHelper method getLastStatus.
public boolean getLastStatus(String collection, final Context context) {
long currentId = sharedPrefs.getLong("current_position_" + currentAccount, 0l);
boolean updated = false;
try {
long startTime = Calendar.getInstance().getTimeInMillis();
HttpGet get = new HttpGet(postURL + "&" + collection);
get.addHeader("X-Auth-Service-Provider", SERVICE_PROVIDER);
get.addHeader("X-Verify-Credentials-Authorization", getAuthrityHeader(twitter));
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(get);
Log.v("talon_tweetmarker", "getting id response code: " + response.getStatusLine().getStatusCode() + " for " + screenname);
long endTime = Calendar.getInstance().getTimeInMillis();
StatusLine statusLine = response.getStatusLine();
final long responseTime = endTime - startTime;
if (endTime - startTime > 15000 && statusLine.getStatusCode() == 200) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if (sharedPrefs.getBoolean("show_tweetmarker_length", true)) {
new AlertDialog.Builder(context).setTitle("Slow TweetMarker Fetch").setMessage("TweetMarker successfully fetched it's position, but seemed to take quite a bit of time. " + "They may be experiencing issues at the moment, you may want to try again in a little while! \n\n" + "Server Response Time: " + (responseTime / 1000) + " seconds").setPositiveButton("Turn Off TM", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sharedPrefs.edit().putString("tweetmarker_options", "0").commit();
AppSettings.invalidate();
}
}).setNeutralButton(R.string.dont_show_again, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sharedPrefs.edit().putBoolean("show_tweetmarker_length", false).commit();
dialog.dismiss();
}
}).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();
}
} catch (Exception e) {
}
}
});
}
if (statusLine.getStatusCode() == 500 || statusLine.getStatusCode() == 503) {
// common tweetmarker failure codes
final StatusLine s = statusLine;
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
try {
new AlertDialog.Builder(context).setTitle("TweetMarker Failure").setMessage("Error: " + s.getStatusCode() + "(" + s.getReasonPhrase() + ")" + "\n\n" + "TweetMarker has been experiencing some issues on their end lately with some apps. They seem intermittent, random, and are causing incredibly slow load times." + "I have been in contact with them, but I would recommend turning off this feature until these issues are resolved.").setPositiveButton("Turn Off TM", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sharedPrefs.edit().putString("tweetmarker_options", "0").commit();
AppSettings.invalidate();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();
} catch (Exception e) {
}
}
});
updated = false;
} else if (statusLine.getStatusCode() == 200) {
// request ok
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line;
StringBuilder builder = new StringBuilder();
while ((line = rd.readLine()) != null) {
builder.append(line);
}
JSONObject jsonObject = new JSONObject(builder.toString());
JSONObject timeline = jsonObject.getJSONObject(collection);
if (timeline != null) {
currentId = Long.parseLong(timeline.getString("id"));
int version = Integer.parseInt(timeline.getString("version"));
Log.v("talon_tweetmarker", "getting tweetmarker," + " version: " + version + " id: " + currentId + " screename: " + screenname);
int lastVer = sharedPrefs.getInt("last_version_account_" + currentAccount, 0);
if (lastVer != version) {
updated = true;
}
sharedPrefs.edit().putInt("last_version_account_" + currentAccount, version).commit();
}
} else {
// wait first
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
}
response = client.execute(get);
statusLine = response.getStatusLine();
if (statusLine.getStatusCode() == 200) {
// request ok
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line;
StringBuilder builder = new StringBuilder();
while ((line = rd.readLine()) != null) {
builder.append(line);
}
JSONObject jsonObject = new JSONObject(builder.toString());
JSONObject timeline = jsonObject.getJSONObject(collection);
if (timeline != null) {
currentId = Long.parseLong(timeline.getString("id"));
int version = Integer.parseInt(timeline.getString("version"));
Log.v("talon_tweetmarker", "getting tweetmarker," + " version: " + version + " id: " + currentId + " screename: " + screenname);
int lastVer = sharedPrefs.getInt("last_version_account_" + currentAccount, 0);
if (lastVer != version) {
updated = true;
}
sharedPrefs.edit().putInt("last_version_account_" + currentAccount, version).commit();
}
}
}
} catch (HttpHostConnectException e) {
// timeout when connecting to host.
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
try {
new AlertDialog.Builder(context).setTitle("TweetMarker Failure").setMessage("Timeout connecting to TweetMarker." + "\n\n" + "TweetMarker has been experiencing some issues on their end lately with some apps. They seem intermittent, random, and are causing incredibly slow load times." + "I have been in contact with them, but I would recommend turning off this feature until these issues are resolved.").setPositiveButton("Turn Off TM", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sharedPrefs.edit().putString("tweetmarker_options", "0").commit();
AppSettings.invalidate();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();
} catch (Exception e) {
}
}
});
} catch (Exception e) {
e.printStackTrace();
} catch (OutOfMemoryError e) {
}
Log.v("talon_launcher_stuff", "writing " + currentId + " to shared prefs");
sharedPrefs.edit().putLong("current_position_" + currentAccount, currentId).commit();
if (contentProvider) {
HomeContentProvider.updateCurrent(currentAccount, context, currentId);
} else {
try {
HomeDataSource.getInstance(context).markPosition(currentAccount, currentId);
} catch (Exception e) {
}
}
return updated;
}
Aggregations