@Override
 public void afterCompletion(int status) {
   RestPostProcessorDelegate.LOG.info("Transaction completed");
   try {
     if (status == STATUS_COMMITTED) {
       RestPostProcessorDelegate.LOG.info("Transaction was committed, sending events.");
       List<String> eventLog =
           (List<String>) TransactionSynchronizationManager.getResource(EVENT_LOG_KEY);
       eventLogSender.send(eventLog);
     } else {
       RestPostProcessorDelegate.LOG.info(
           "Transaction was not committed, status was " + status + ", not sending events.");
     }
   } catch (IOException e) {
     throw new RuntimeException("Failed to send the event log.", e);
   } finally {
     TransactionSynchronizationManager.unbindResource(EVENT_LOG_KEY);
   }
 }
    void send(List<String> eventLog) throws IOException {
      CloseableHttpClient httpClient = HttpClients.createDefault();
      try {

        JsonFactory factory = new JsonFactory();
        StringWriter writer = new StringWriter();
        JsonGenerator generator = factory.createJsonGenerator(writer);
        generator.writeStartObject();
        generator.writeArrayFieldStart("events");
        for (String eventJson : eventLog) {
          generator.writeRawValue(eventJson);
        }
        generator.writeEndArray();
        generator.writeEndObject();
        generator.close();

        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
            AuthScope.ANY, new UsernamePasswordCredentials(username, password));
        HttpClientContext context = HttpClientContext.create();
        context.setCredentialsProvider(credsProvider);

        RestPostProcessorDelegate.LOG.info(
            "Posting " + eventLog.size() + " events to " + targetUrl);
        HttpPost httpPost = new HttpPost(targetUrl);
        httpPost.setEntity(new StringEntity(writer.toString(), ContentType.APPLICATION_JSON));
        CloseableHttpResponse response = httpClient.execute(httpPost, context);
        int statusCode = response.getStatusLine().getStatusCode();
        LOG.info("Status code was " + statusCode + " when invoking " + targetUrl);
        if (statusCode >= 400) {
          throw new RiceRuntimeException(
              "Failed to invoke " + targetUrl + ", response code was " + statusCode);
        }

      } finally {
        httpClient.close();
      }
    }