Source:
public void sendMessage(final SlackMessage message) { LOG.info("Sending Slack message {}", message); final HttpRequest.Builder requestBuilder = HttpRequest.newBuilder() .setUrl(blazarSlackConfiguration.getSlackApiBaseUrl() + "/chat.postMessage") .setMethod(Method.POST) .setContentType(HttpRequest.ContentType.FORM); requestBuilder.setFormParam("token").to(message.getToken().or(blazarSlackConfiguration.getSlackApiToken())); requestBuilder.setFormParam("channel").to("#" + message.getChannel()); requestBuilder.setFormParam("text").to(message.getText().or("")); requestBuilder.setFormParam("username").to(message.getUsername().or(blazarSlackConfiguration.getUsername())); if (message.getAttachments() != null) { try { requestBuilder.setFormParam("attachments").to(objectMapper.writeValueAsString(message.getAttachments())); } catch (Exception e) { throw Throwables.propagate(e); } } requestBuilder.setFormParam("icon_emoji").to(message.getIconEmoji().or(":fire:")); asyncHttpClient.execute(requestBuilder.build(), new Callback() { @Override public void failed(Exception e) { LOG.error(String.format("Failed to send notification to Slack channel %s", message.getChannel()), e); } @Override public void completed(HttpResponse httpResponse) { if (httpResponse.isSuccess()) { SlackApiResponse apiResponse = httpResponse.getAs(SlackApiResponse.class); if (apiResponse.getOk()) { LOG.debug("Successfully sent Slack notification to channel {}. Response: {}", message.getChannel(), apiResponse); } else { LOG.error("Slack didn't returned an ok for notification to channel {}. Slack response is: {}", message.getChannel(), apiResponse); } } else { LOG.error("Failed to send Slack notification to channel {}. Status code: {}, Response: {}", message.getChannel(), httpResponse.getStatusCode(), httpResponse.getAsString()); } } }); }

Target:
public void sendMessage(final SlackMessage message) { LOG.info("Sending Slack message {}", message); final HttpRequest.Builder requestBuilder = HttpRequest.newBuilder() .setUrl(blazarSlackConfiguration.getSlackApiBaseUrl() + "/chat.postMessage") .setMethod(Method.POST) .setContentType(HttpRequest.ContentType.FORM); requestBuilder.setFormParam("token").to(message.getToken().or(blazarSlackConfiguration.getSlackApiToken())); requestBuilder.setFormParam("channel").to("#" + message.getChannel()); requestBuilder.setFormParam("text").to(message.getText().or("")); requestBuilder.setFormParam("username").to(message.getUsername().or(blazarSlackConfiguration.getUsername())); if (message.getAttachments() != null) { try { requestBuilder.setFormParam("attachments").to(objectMapper.writeValueAsString(message.getAttachments())); } catch (Exception e) { throw Throwables.propagate(e); } } if (message.getIconEmoji().isPresent()) { requestBuilder.setFormParam("icon_emoji").to(message.getIconEmoji().get()); } asyncHttpClient.execute(requestBuilder.build(), new Callback() { @Override public void failed(Exception e) { LOG.error(String.format("Failed to send notification to Slack channel %s", message.getChannel()), e); } @Override public void completed(HttpResponse httpResponse) { if (httpResponse.isSuccess()) { SlackApiResponse apiResponse = httpResponse.getAs(SlackApiResponse.class); if (apiResponse.getOk()) { LOG.debug("Successfully sent Slack notification to channel {}. Response: {}", message.getChannel(), apiResponse); } else { LOG.error("Slack didn't returned an ok for notification to channel {}. Slack response is: {}", message.getChannel(), apiResponse); } } else { LOG.error("Failed to send Slack notification to channel {}. Status code: {}, Response: {}", message.getChannel(), httpResponse.getStatusCode(), httpResponse.getAsString()); } } }); }