Ejemplo n.º 1
0
  @Override
  public void postCall(HttpRequest request, HttpResponseStatus status, HandlerInfo handlerInfo) {
    if (metricsCollectionService != null) {
      try {
        MetricsCollector collector = collectorCache.get(createContext(handlerInfo));
        String name;
        int code = status.getCode();
        if (code < 100) {
          name = "unknown";
        } else if (code < 200) {
          name = "information";
        } else if (code < 300) {
          name = "successful";
        } else if (code < 400) {
          name = "redirect";
        } else if (code < 500) {
          name = "client-error";
        } else if (code < 600) {
          name = "server-error";
        } else {
          name = "unknown";
        }

        // todo: report metrics broken down by status
        collector.increment("response." + name, 1 /*, "status:" + code*/);
      } catch (Throwable e) {
        LOG.error("Got exception while getting collector", e);
      }
    }
  }
  private void sendHttpResponse(ActorRef sender, HttpResponseStatus status, String response) {

    // headers
    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    headers.put(HttpHeaders.Names.CONTENT_TYPE, Arrays.asList("text/plain"));

    // response
    if (StringUtils.isEmpty(response)) {
      response = status.getReasonPhrase();
    }

    sender.tell(
        new HttpResponse(status.getCode(), headers, response.getBytes(Charset.forName("UTF-8"))),
        getSelf());
  }
Ejemplo n.º 3
0
 private String getResponseCounterName(HttpResponseStatus responseStatus) {
   return responseStatus.getCode() + "-" + responseStatus.getReasonPhrase() + "-count";
 }