protected Response getVipResponse(
      String version,
      String entityName,
      String acceptHeader,
      ResponseCache.Key.EntityType entityType) {
    if (!PeerAwareInstanceRegistry.getInstance().shouldAllowAccess(false)) {
      return Response.status(Response.Status.FORBIDDEN).build();
    }
    CurrentRequestVersion.set(Version.toEnum(version));
    ResponseCache.KeyType keyType = ResponseCache.KeyType.JSON;
    if (acceptHeader == null || !acceptHeader.contains("json")) {
      keyType = ResponseCache.KeyType.XML;
    }

    ResponseCache.Key cacheKey =
        new ResponseCache.Key(entityType, entityName, keyType, CurrentRequestVersion.get());

    String payLoad = ResponseCache.getInstance().get(cacheKey);

    if (payLoad != null) {
      logger.debug("Found: {}", entityName);
      return Response.ok(payLoad).build();
    } else {
      logger.debug("Not Found: {}", entityName);
      return Response.status(Response.Status.NOT_FOUND).build();
    }
  }
Beispiel #2
0
 public Key(
     EntityType entityType,
     String entityName,
     KeyType type,
     Version v,
     EurekaAccept eurekaAccept,
     @Nullable String[] regions) {
   this.regions = regions;
   this.entityType = entityType;
   this.entityName = entityName;
   this.requestType = type;
   this.requestVersion = v;
   this.eurekaAccept = eurekaAccept;
   hashKey =
       this.entityType
           + this.entityName
           + (null != this.regions ? Arrays.toString(this.regions) : "")
           + requestType.name()
           + requestVersion.name()
           + this.eurekaAccept.name();
 }