List of usage examples for io.netty.handler.codec.http HttpResponseStatus MULTIPLE_CHOICES
HttpResponseStatus MULTIPLE_CHOICES
To view the source code for io.netty.handler.codec.http HttpResponseStatus MULTIPLE_CHOICES.
Click Source Link
From source file:com.cyngn.vertx.bosun.BosunReporter.java
License:Apache License
/** * Send data to the bosun instance/* w w w . j a v a2 s. c om*/ * * @param api the api on bosun to send to * @param data the json data to send * @param message the event bus message the request originated from */ private void sendData(String api, String data, Message message) { HttpClient client = getNextHost(); Buffer buffer = Buffer.buffer(data.getBytes()); client.post(api).exceptionHandler(error -> { sendError(message, "Got ex contacting bosun, " + error.getLocalizedMessage()); }).handler(response -> { int statusCode = response.statusCode(); // is it 2XX if (statusCode >= HttpResponseStatus.OK.code() && statusCode < HttpResponseStatus.MULTIPLE_CHOICES.code()) { message.reply(new JsonObject().put(RESULT_FIELD, BosunResponse.OK_MSG)); } else { response.bodyHandler(responseData -> { sendError(message, "got non 200 response from bosun, error: " + responseData, statusCode); }); } }).setTimeout(timeout).putHeader(HttpHeaders.CONTENT_LENGTH, buffer.length() + "") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()).write(buffer).end(); }