public static void accountAndContainerNamePreconditionCheck(RestRequest restRequest) throws RestServiceException {
    String accountNameFromHeader = getHeader(restRequest.getArgs(), Headers.TARGET_ACCOUNT_NAME, false);
    String containerNameFromHeader = getHeader(restRequest.getArgs(), Headers.TARGET_CONTAINER_NAME, false);
    if (accountNameFromHeader != null) {
      Account targetAccount = getAccountFromArgs(restRequest.getArgs());
      String accountNameFromBlobId = targetAccount.getName();
      if (!accountNameFromHeader.equals(accountNameFromBlobId)) {
        throw new RestServiceException(
            "Account name: " + accountNameFromHeader + " from request doesn't match the account name from Blob id : "
                + accountNameFromBlobId, RestServiceErrorCode.PreconditionFailed);
      }
      if (containerNameFromHeader != null) {
        Container targetContainer = getContainerFromArgs(restRequest.getArgs());
        String containerNameFromBlobId = targetContainer.getName();
        if (!containerNameFromHeader.equals(containerNameFromBlobId)) {
          throw new RestServiceException("Container name: " + containerNameFromHeader
              + "from request doesn't match the container name from Blob id : " + containerNameFromBlobId,
              RestServiceErrorCode.PreconditionFailed);
        }
      }
    } else if (containerNameFromHeader != null) {
      throw new RestServiceException(
          "Only container name is set in request with no corresponding account name is not allowed.",
          RestServiceErrorCode.BadRequest);
    }
  }
Check preconditions for request if the {@code restRequest} contains the target account and container.
@param restRequest the {@link RestRequest} that contains the {@link Account} and {@link Container} details.
@throws RestServiceException if preconditions check failed.
ambry-api/src/main/java/com/github/ambry/rest/RestUtils.java