private void sendPost(String url, CallbackData data, CallbackContext context) { HttpPost post = new HttpPost(url); Set<Node> nodes; try { nodes = context.getClusterStoreView().getClusterNodes(data.getCluster().getId()); } catch (Exception e) { LOG.error("Unable to fetch nodes for cluster {}, not sending post request.", data.getCluster().getId()); return; } try { JsonObject body = new JsonObject(); body.add("cluster", gson.toJsonTree(data.getCluster())); body.add("job", gson.toJsonTree(data.getJob())); body.add("nodes", gson.toJsonTree(nodes)); post.setEntity(new StringEntity(gson.toJson(body))); httpClient.execute(post); } catch (UnsupportedEncodingException e) { LOG.warn("Exception setting http post body", e); } catch (ClientProtocolException e) { LOG.warn("Exception executing http post callback to " + url, e); } catch (IOException e) { LOG.warn("Exception executing http post callback to " + url, e); } catch (Exception e) { LOG.warn("Exception executing http post callback to " + url, e); } finally { post.releaseConnection(); } } }