@Override
  protected void onComplete(Request request, Response response) {
    activeRequestsCounter.dec();
    Long duration =
        computeDurationMillis(START_TIMES_BY_CORRELATION_ID.remove(request.getCorrelationId()));

    if (duration != null && duration.longValue() > 0) {
      allTimesTimer.update(duration, TimeUnit.MILLISECONDS);

      String name = getRouteName(request);
      if (name == null || name.isEmpty()) return;

      ROUTE_TIMERS.get(name).update(duration, TimeUnit.MILLISECONDS);
    }

    Counter responseCounter = COUNTERS_BY_RESPONSE.get(response.getResponseStatus().getCode());

    if (responseCounter == null) {
      responseCounter = metrics.counter(getResponseCounterName(response.getResponseStatus()));
      COUNTERS_BY_RESPONSE.putIfAbsent(response.getResponseStatus().getCode(), responseCounter);
    }

    responseCounter.inc();
    publish(request, response, duration);
  }
 @Test
 public void shouldAddXContentTypeOptionsHeader() {
   HttpRequest httpRequest =
       new DefaultHttpRequest(
           HttpVersion.HTTP_1_1, HttpMethod.GET, "/foo?param1=bar&param2=baz&quux");
   httpRequest.addHeader("Host", "testing-host");
   Response response = new Response();
   postprocessor.process(new Request(httpRequest, null), response);
   assertTrue(response.hasHeaders());
   String result = response.getHeader(XCONTENTTYPEOPTIONS);
   assertNotNull(result);
   assertEquals(NOSNIFF, result);
 }
 public void update(Request request, Response response) {
   String id = request.getHeader(Constants.Url.SAMPLE_ID, "No resource ID supplied");
   SampleOidEntity entity =
       request.getBodyAs(SampleOidEntity.class, "Resource details not provided");
   entity.setId(Identifiers.MONGOID.parse(id));
   service.update(entity);
   response.setResponseNoContent();
 }
  /** Set the 'X-Response-Time' header to the response time in milliseconds. */
  @Override
  public void process(Request request, Response response) {
    Long duration =
        computeDurationMillis(START_TIMES_BY_CORRELATION_ID.get(request.getCorrelationId()));

    if (duration != null && duration.longValue() > 0) {
      response.addHeader("X-Response-Time", String.valueOf(duration));
    }
  }
  public SampleOidEntity create(Request request, Response response) {
    SampleOidEntity entity =
        request.getBodyAs(SampleOidEntity.class, "Resource details not provided");
    SampleOidEntity saved = service.create(entity);

    // Construct the response for create...
    response.setResponseCreated();

    // Bind the resource with link URL tokens, etc. here...
    TokenResolver resolver =
        HyperExpress.bind(Constants.Url.SAMPLE_ID, Identifiers.MONGOID.format(saved.getId()));

    // Include the Location header...
    String locationPattern =
        request.getNamedUrl(HttpMethod.GET, Constants.Routes.SINGLE_OID_SAMPLE);
    response.addLocationHeader(LOCATION_BUILDER.build(locationPattern, resolver));

    // Return the newly-created resource...
    return saved;
  }
  public List<SampleOidEntity> readAll(Request request, Response response) {
    QueryFilter filter = QueryFilters.parseFrom(request);
    QueryOrder order = QueryOrders.parseFrom(request);
    QueryRange range = QueryRanges.parseFrom(request, 20);
    List<SampleOidEntity> entities = service.readAll(filter, range, order);
    long count = service.count(filter);
    response.setCollectionResponse(range, entities.size(), count);

    // Bind the resources in the collection with link URL tokens, etc. here...
    HyperExpress.tokenBinder(
        new TokenBinder<SampleOidEntity>() {
          @Override
          public void bind(SampleOidEntity entity, TokenResolver resolver) {
            resolver.bind(Constants.Url.SAMPLE_ID, Identifiers.MONGOID.format(entity.getId()));
          }
        });

    return entities;
  }
 public void delete(Request request, Response response) {
   String id = request.getHeader(Constants.Url.SAMPLE_ID, "No resource ID supplied");
   service.delete(Identifiers.MONGOID.parse(id));
   response.setResponseNoContent();
 }