@Nonnull
  @Override
  public Response handle(@Nonnull final Context context) throws Exception {
    String action = context.getRequest().getAction();
    if (!HttpMethods.GET.equals(action)) {
      return context.proceed();
    }
    NegativeCacheFacet negativeCache = context.getRepository().facet(NegativeCacheFacet.class);
    NegativeCacheKey key = negativeCache.getCacheKey(context);

    Response response;
    Status status = negativeCache.get(key);
    if (status == null) {
      response = context.proceed();
      if (isNotFound(response)) {
        negativeCache.put(key, response.getStatus());
      } else if (response.getStatus().isSuccessful()) {
        negativeCache.invalidate(key);
      }
    } else {
      response = new Response.Builder().status(status).build();

      log.debug("Found {} in negative cache, returning {}", key, response);
    }
    return response;
  }
예제 #2
0
  @Nonnull
  @Override
  public Response handle(final @Nonnull Context context) throws Exception {
    final String method = context.getRequest().getAction();
    switch (method) {
      case GET:
      case HEAD:
        {
          final DispatchedRepositories dispatched =
              context.getRequest().getAttributes().getOrCreate(DispatchedRepositories.class);
          return doGet(context, dispatched);
        }

      default:
        return HttpResponses.methodNotAllowed(method, GET, HEAD);
    }
  }
예제 #3
0
 /** Method that actually performs group GET. Override if needed. */
 protected Response doGet(
     final @Nonnull Context context, final @Nonnull DispatchedRepositories dispatched)
     throws Exception {
   final GroupFacet groupFacet = context.getRepository().facet(GroupFacet.class);
   return getFirst(context.getRequest(), groupFacet.members(), dispatched);
 }