當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpHeaders.setETag方法代碼示例

本文整理匯總了Java中org.springframework.http.HttpHeaders.setETag方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHeaders.setETag方法的具體用法?Java HttpHeaders.setETag怎麽用?Java HttpHeaders.setETag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.http.HttpHeaders的用法示例。


在下文中一共展示了HttpHeaders.setETag方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: putObject

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Adds an object to a bucket.
 *
 * http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
 *
 * @param bucketName the Bucket in which to store the file in.
 * @param request http servlet request
 * @return ResponseEntity with Status Code and ETag
 */
@RequestMapping(value = "/{bucketName:.+}/**", method = RequestMethod.PUT)
public ResponseEntity<String> putObject(@PathVariable final String bucketName,
    final HttpServletRequest request) {
  final String filename = filenameFrom(bucketName, request);
  try (ServletInputStream inputStream = request.getInputStream()) {
    final S3Object s3Object = fileStore.putS3Object(bucketName,
        filename,
        request.getContentType(),
        inputStream,
        isV4SigningEnabled(request));

    final HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setETag("\"" + s3Object.getMd5() + "\"");
    responseHeaders.setLastModified(s3Object.getLastModified());
    return new ResponseEntity<>(responseHeaders, HttpStatus.CREATED);
  } catch (final IOException e) {
    LOG.error("Object could not be saved!", e);
    return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  }
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:30,代碼來源:FileStoreController.java

示例2: headObject

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Retrieves metadata from an object without returning the object itself.
 *
 * @param bucketName name of the bucket to look in
 * @return ResponseEntity containing metadata and status
 */
@RequestMapping(
    value = "/{bucketName:.+}/**",
    method = RequestMethod.HEAD)
public ResponseEntity<String> headObject(@PathVariable final String bucketName,
    final HttpServletRequest request) {
  final String filename = filenameFrom(bucketName, request);

  final S3Object s3Object = fileStore.getS3Object(bucketName, filename);
  if (s3Object != null) {
    final HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentLength(Long.valueOf(s3Object.getSize()));
    if (!"".equals(s3Object.getContentType())) {
      responseHeaders.setContentType(MediaType.parseMediaType(s3Object.getContentType()));
    }
    responseHeaders.setETag("\"" + s3Object.getMd5() + "\"");
    responseHeaders.setLastModified(s3Object.getLastModified());

    if (s3Object.isEncrypted()) {
      responseHeaders.add(SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID,
          s3Object.getKmsKeyId());
    }

    return new ResponseEntity<>(responseHeaders, HttpStatus.OK);
  } else {
    return new ResponseEntity<>(HttpStatus.NOT_FOUND);
  }
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:34,代碼來源:FileStoreController.java

示例3: putObjectEncrypted

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Adds an encrypted object to a bucket.
 *
 * http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
 *
 * @param bucketName the Bucket in which to store the file in.
 * @param encryption The encryption type.
 * @param kmsKeyId The KMS encryption key id.
 * @param request http servlet request.
 *
 * @return {@link ResponseEntity} with Status Code and empty ETag.
 *
 * @throws IOException in case of an error on storing the object.
 */
@RequestMapping(
    value = "/{bucketName:.+}/**",
    headers = {
        SERVER_SIDE_ENCRYPTION,
        SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID
    },
    method = RequestMethod.PUT)
public ResponseEntity<String> putObjectEncrypted(@PathVariable final String bucketName,
    @RequestHeader(value = SERVER_SIDE_ENCRYPTION) final String encryption,
    @RequestHeader(value = SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID) final String kmsKeyId,
    final HttpServletRequest request) throws IOException {
  final String filename = filenameFrom(bucketName, request);
  final S3Object s3Object;
  try (ServletInputStream inputStream = request.getInputStream()) {
    s3Object =
        fileStore.putS3ObjectWithKMSEncryption(bucketName,
            filename,
            request.getContentType(),
            inputStream,
            isV4SigningEnabled(request),
            encryption,
            kmsKeyId);

    final HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setETag("\"" + s3Object.getMd5() + "\"");
    responseHeaders.setLastModified(s3Object.getLastModified());
    responseHeaders.add(SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID, kmsKeyId);

    return new ResponseEntity<>(responseHeaders, HttpStatus.CREATED);
  }
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:46,代碼來源:FileStoreController.java

示例4: putObjectPart

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Adds an object to a bucket accepting encryption headers.
 *
 * http://docs.aws.amazon.com/AmazonS3/latest/API/mpUploadUploadPart.html
 *
 * @param bucketName the Bucket in which to store the file in.
 * @param uploadId id of the upload. Has to match all other part's uploads.
 * @param partNumber number of the part to upload.
 * @param encryption Defines the encryption mode.
 * @param kmsKeyId Defines the KMS key id.
 * @param request {@link HttpServletRequest} of this request.
 *
 * @return the etag of the uploaded part.
 *
 * @throws IOException in case of an error.
 */
@RequestMapping(
    value = "/{bucketName:.+}/**",
    params = {"uploadId", "partNumber"},
    headers = {
        NOT_COPY_SOURCE,
        NOT_COPY_SOURCE_RANGE,
        SERVER_SIDE_ENCRYPTION
    },
    method = RequestMethod.PUT)
public ResponseEntity<CopyPartResult> putObjectPart(@PathVariable final String bucketName,
    @RequestParam final String uploadId,
    @RequestParam final String partNumber,
    @RequestHeader(value = SERVER_SIDE_ENCRYPTION) final String encryption,
    @RequestHeader(
        value = SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID,
        required = false) final String kmsKeyId,
    final HttpServletRequest request) throws IOException {

  final String filename = filenameFrom(bucketName, request);

  final String etag = fileStore.putPart(bucketName,
      filename,
      uploadId,
      partNumber,
      request.getInputStream(),
      isV4SigningEnabled(request));

  final HttpHeaders responseHeaders = new HttpHeaders();
  final String quotedEtag = "\"" + etag + "\"";
  responseHeaders.setETag(quotedEtag);

  return new ResponseEntity<>(responseHeaders, HttpStatus.CREATED);
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:50,代碼來源:FileStoreController.java


注:本文中的org.springframework.http.HttpHeaders.setETag方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。