public Document getDocument() {
    Document doc = new Document();
    String sessionId;
    String keyIdParam;
    String callBackKey = "&callbackUrl=";
    String callBackValue = generalConfig.sURL_DocumentKvitanciiCallback();
    String keyID = this.accessCode;
    Collection<Long> correctDocTypes = Lists.newArrayList(0L, 1L);
    String uriDoc;

    if (this.documentTypeId == null || !correctDocTypes.contains(this.documentTypeId)) {
      LOG.error("DocumentTypeId = " + this.documentTypeId);
      throw new DocumentTypeNotSupportedException(
          "Incorrect DocumentTypeId. DocumentTypeId = " + this.documentTypeId);
    } else {
      uriDoc =
          Long.valueOf(0L).equals(this.documentTypeId)
              ? generalConfig.sURL_DocumentKvitanciiForIgov()
              : generalConfig.sURL_DocumentKvitanciiForAccounts();

      keyIdParam = Long.valueOf(0L).equals(this.documentTypeId) ? "?keyID=" : "?id=";
    }

    String finalUri = uriDoc + keyIdParam + keyID + callBackKey + callBackValue;

    // if (generalConfig.bTest()) {
    SSLCertificateValidation.disable();
    // }

    try {
      sessionId = getSessionId();
      String authHeader = "sid:" + sessionId;
      byte[] authHeaderBytes = Base64.encode(authHeader.getBytes(StandardCharsets.UTF_8));
      String authHeaderEncoded = new String(authHeaderBytes);

      HttpHeaders headers = new HttpHeaders();
      headers.setAccept(Collections.singletonList(MediaType.ALL));
      headers.set("Authorization", "Basic " + authHeaderEncoded);
      LOG.debug("try to final url: {}", finalUri);
      ResponseEntity<byte[]> documentEntity =
          new RestRequest()
              .getEntity(finalUri, null, StandardCharsets.UTF_8, byte[].class, headers);

      String contentType = documentEntity.getHeaders().getContentType().toString();
      String contentDispositionHeader =
          documentEntity.getHeaders().get("Content-Disposition").get(0);
      ContentDisposition header = new ContentDisposition(contentDispositionHeader);
      String documentName = header.getParameter("name");

      if (isBlank(documentName)) {
        documentName = header.getParameter("filename");
      }

      if (this.withContent) {
        doc.setFileBody(getFileFromRespEntity(documentEntity));
      }

      doc.setDocumentType(documentTypeDao.findByIdExpected(0L));
      doc.setSubject(subjectDao.getSubject(this.nID_Subject));
      doc.setFile(documentName);
      doc.setContentType(contentType);
      doc.setDate_Upload(DateTime.now());
      doc.setsID_subject_Upload(null);
      doc.setContentKey(null);
      doc.setoSignData(null);

    } catch (ParseException | ResourceAccessException e) {
      LOG.error("Can't get document: ", e);
      throw new DocumentNotFoundException("Can't get document: ", e);
    }

    return doc;
  }