本文整理汇总了Java中com.amazonaws.HttpMethod类的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod类的具体用法?Java HttpMethod怎么用?Java HttpMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpMethod类属于com.amazonaws包,在下文中一共展示了HttpMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generatePreSignUrl
import com.amazonaws.HttpMethod; //导入依赖的package包/类
/**
* Method to generate pre-signed object URL to s3 object
* @param bucketName AWS S3 bucket name
* @param key (example: android/apkFolder/ApkName.apk)
* @param ms espiration time in ms, i.e. 1 hour is 1000*60*60
* @return url String pre-signed URL
*/
public URL generatePreSignUrl(final String bucketName, final String key, long ms) {
java.util.Date expiration = new java.util.Date();
long msec = expiration.getTime();
msec += ms;
expiration.setTime(msec);
GeneratePresignedUrlRequest generatePresignedUrlRequest =
new GeneratePresignedUrlRequest(bucketName, key);
generatePresignedUrlRequest.setMethod(HttpMethod.GET);
generatePresignedUrlRequest.setExpiration(expiration);
URL url = s3client.generatePresignedUrl(generatePresignedUrlRequest);
return url;
}
示例2: getPreSignedUrl
import com.amazonaws.HttpMethod; //导入依赖的package包/类
@NotNull
@Override
public String getPreSignedUrl(@NotNull HttpMethod httpMethod, @NotNull String bucketName, @NotNull String objectKey, @NotNull Map<String, String> params) throws IOException {
try {
final Callable<String> resolver = () -> S3Util.withS3Client(params, client -> {
final GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, objectKey, httpMethod)
.withExpiration(new Date(System.currentTimeMillis() + getUrlLifetimeSec() * 1000));
return client.generatePresignedUrl(request).toString();
});
if (httpMethod == HttpMethod.GET) {
return TeamCityProperties.getBoolean(TEAMCITY_S3_PRESIGNURL_GET_CACHE_ENABLED)
? myGetLinksCache.get(getCacheIdentity(params, objectKey, bucketName), resolver)
: resolver.call();
} else {
return resolver.call();
}
} catch (Exception e) {
final AWSException awsException = new AWSException(e.getCause());
if (StringUtil.isNotEmpty(awsException.getDetails())) {
LOG.warn(awsException.getDetails());
}
final String err = "Failed to create " + httpMethod.name() + " pre-signed URL for [" + objectKey + "] in bucket [" + bucketName + "]";
LOG.infoAndDebugDetails(err, awsException);
throw new IOException(err + ": " + awsException.getMessage(), awsException);
}
}
开发者ID:JetBrains,项目名称:teamcity-s3-artifact-storage-plugin,代码行数:27,代码来源:S3PreSignedUrlProviderImpl.java
示例3: processDownload
import com.amazonaws.HttpMethod; //导入依赖的package包/类
@Override
public boolean processDownload(@NotNull StoredBuildArtifactInfo storedBuildArtifactInfo,
@NotNull BuildPromotion buildPromotion,
@NotNull HttpServletRequest httpServletRequest,
@NotNull HttpServletResponse httpServletResponse) throws IOException {
final ArtifactData artifactData = storedBuildArtifactInfo.getArtifactData();
if (artifactData == null) throw new IOException("Can not process artifact download request for a folder");
final Map<String, String> params = S3Util.validateParameters(storedBuildArtifactInfo.getStorageSettings());
final String pathPrefix = S3Util.getPathPrefix(storedBuildArtifactInfo.getCommonProperties());
final String bucketName = S3Util.getBucketName(params);
if (bucketName == null) {
final String message = "Failed to create pre-signed URL: bucket name is not specified, please check storage settings";
LOG.warn(message);
throw new IOException(message);
}
httpServletResponse.setHeader(HttpHeaders.CACHE_CONTROL, "max-age=" + myPreSignedUrlProvider.getUrlLifetimeSec());
httpServletResponse.sendRedirect(myPreSignedUrlProvider.getPreSignedUrl(HttpMethod.valueOf(httpServletRequest.getMethod()), bucketName, pathPrefix + artifactData.getPath(),params));
return true;
}
开发者ID:JetBrains,项目名称:teamcity-s3-artifact-storage-plugin,代码行数:23,代码来源:S3ArtifactDownloadProcessor.java
示例4: generateUrl
import com.amazonaws.HttpMethod; //导入依赖的package包/类
@NotNull
static URL generateUrl(@NotNull final String bucketName, @NotNull final String objectKey) throws IOException {
try {
LOGGER.info("Generating pre-signed URL for bucket: {}\tobject: {}", bucketName, objectKey);
final long millisNow = System.currentTimeMillis();
final long expirationMillis = millisNow + 1000 * 60 * 120; //add 2 hours;
final Date expiration = new java.util.Date(expirationMillis);
final GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey);
generatePresignedUrlRequest.setMethod(HttpMethod.GET);
generatePresignedUrlRequest.setExpiration(expiration);
return s3Client.generatePresignedUrl(generatePresignedUrlRequest);
} catch (AmazonServiceException exception) {
LOGGER.error("Error Message: {}", exception.getMessage());
LOGGER.error("HTTP Code: {}", exception.getStatusCode());
LOGGER.error("Error Code: {}", exception.getErrorCode());
LOGGER.error("Error Type: {}", exception.getErrorType());
LOGGER.error("Request ID: {}", exception.getRequestId());
} catch (AmazonClientException ace) {
LOGGER.error("The client encountered an internal error while trying to communicate with S3");
LOGGER.error("Error Message: {}", ace.getMessage());
}
throw new IOException("Failed to create sbp URL.");
}
示例5: getExpiringUrl
import com.amazonaws.HttpMethod; //导入依赖的package包/类
/**
* create url for a file which will expire in specified seconds.
*
* @param bucket the bucket name
* @param filename the filename
* @param expirySeconds the number of seconds after which this url will expire
* @return the url
* @throws CloudException on AWS Service/Client errors
*/
public URL getExpiringUrl(String bucket, String filename, long expirySeconds) throws CloudException {
checkArgument(! Strings.isNullOrEmpty(bucket), "bucket is null or empty");
checkArgument(! Strings.isNullOrEmpty(filename), "filename is null or empty");
checkArgument(expirySeconds > 0, "expirySeconds %d is not postive for bucket %s filename %s",
expirySeconds, bucket, filename);
Date expiry = Instant.now().plus(Duration.standardSeconds(expirySeconds)).toDate();
try {
return urlGenS3.generatePresignedUrl(bucket, filename, expiry, HttpMethod.GET);
} catch (AmazonClientException ex) {
throw new CloudException(
String.format("Error fetching expiring url for bucket %s filename %s in region %s",
bucket, filename, region), ex);
}
}
示例6: testAwsV2UrlSigning
import com.amazonaws.HttpMethod; //导入依赖的package包/类
@Test
public void testAwsV2UrlSigning() throws Exception {
client = AmazonS3ClientBuilder.standard()
.withClientConfiguration(V2_SIGNER_CONFIG)
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.withEndpointConfiguration(s3EndpointConfig)
.build();
String blobName = "foo";
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(BYTE_SOURCE.size());
client.putObject(containerName, blobName, BYTE_SOURCE.openStream(),
metadata);
Date expiration = new Date(System.currentTimeMillis() +
TimeUnit.HOURS.toMillis(1));
URL url = client.generatePresignedUrl(containerName, blobName,
expiration, HttpMethod.GET);
try (InputStream actual = url.openStream();
InputStream expected = BYTE_SOURCE.openStream()) {
assertThat(actual).hasContentEqualTo(expected);
}
}
示例7: testAwsV4UrlSigning
import com.amazonaws.HttpMethod; //导入依赖的package包/类
@Test
public void testAwsV4UrlSigning() throws Exception {
String blobName = "foo";
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(BYTE_SOURCE.size());
client.putObject(containerName, blobName, BYTE_SOURCE.openStream(),
metadata);
Date expiration = new Date(System.currentTimeMillis() +
TimeUnit.HOURS.toMillis(1));
URL url = client.generatePresignedUrl(containerName, blobName,
expiration, HttpMethod.GET);
try (InputStream actual = url.openStream();
InputStream expected = BYTE_SOURCE.openStream()) {
assertThat(actual).hasContentEqualTo(expected);
}
}
示例8: createHttpUriRequest
import com.amazonaws.HttpMethod; //导入依赖的package包/类
/**
* Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
* @param httpMethod the HTTP method
* @param uri the URI
* @return the Commons HttpMethodBase object
*/
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
switch (httpMethod) {
case GET:
return new HttpGet(uri);
case DELETE:
return new HttpDeleteWithBody(uri);
case HEAD:
return new HttpHead(uri);
case OPTIONS:
return new HttpOptions(uri);
case POST:
return new HttpPost(uri);
case PUT:
return new HttpPut(uri);
case TRACE:
return new HttpTrace(uri);
case PATCH:
return new HttpPatch(uri);
default:
throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
}
}
示例9: getURL
import com.amazonaws.HttpMethod; //导入依赖的package包/类
public URL getURL(String fileName)
{
log.debug("Generating pre-signed URL.");
java.util.Date expiration = new java.util.Date();
long milliSeconds = expiration.getTime();
milliSeconds += Config.UPLOAD_EXPIRATION_TIME; // Add 10 sec.
expiration.setTime(milliSeconds);
GeneratePresignedUrlRequest generatePresignedUrlRequest =
new GeneratePresignedUrlRequest(bucketName, fileName);
generatePresignedUrlRequest.setMethod(HttpMethod.PUT);
generatePresignedUrlRequest.setExpiration(expiration);
return s3client.generatePresignedUrl(generatePresignedUrlRequest);
}
示例10: getSignedUrl
import com.amazonaws.HttpMethod; //导入依赖的package包/类
public URL getSignedUrl(String p_s3_bucket, String p_s3_file, Date p_exires) {
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(p_s3_bucket, p_s3_file);
generatePresignedUrlRequest.setMethod(HttpMethod.GET); // Default.
generatePresignedUrlRequest.setExpiration(p_exires);
return s3Client.generatePresignedUrl(generatePresignedUrlRequest);
}
示例11: generatePresignedUrl
import com.amazonaws.HttpMethod; //导入依赖的package包/类
@Override
public URL generatePresignedUrl(String bucketName, String key,
Date expiration, HttpMethod method) throws SdkClientException {
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, key, method);
request.setExpiration(expiration);
return generatePresignedUrl(request);
}
示例12: generatePresignedUrl
import com.amazonaws.HttpMethod; //导入依赖的package包/类
@Override
public URL generatePresignedUrl(String bucketName, String key, Date expiration, HttpMethod method)
throws SdkClientException {
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, key, method);
request.setExpiration(expiration);
return generatePresignedUrl(request);
}
示例13: presignRequest
import com.amazonaws.HttpMethod; //导入依赖的package包/类
/**
* Pre-signs the specified request, using a signature query-string
* parameter.
*
* @param request
* The request to sign.
* @param methodName
* The HTTP method (GET, PUT, DELETE, HEAD) for the specified
* request.
* @param bucketName
* The name of the bucket involved in the request. If the request
* is not an operation on a bucket this parameter should be null.
* @param key
* The object key involved in the request. If the request is not
* an operation on an object, this parameter should be null.
* @param expiration
* The time at which the signed request is no longer valid, and
* will stop working.
* @param subResource
* The optional sub-resource being requested as part of the
* request (e.g. "location", "acl", "logging", or "torrent").
*/
protected <T> void presignRequest(Request<T> request, HttpMethod methodName,
String bucketName, String key, Date expiration, String subResource) {
// Run any additional request handlers if present
beforeRequest(request);
String resourcePath = "/" +
((bucketName != null) ? bucketName + "/" : "") +
((key != null) ? SdkHttpUtils.urlEncode(key, true) : "") +
((subResource != null) ? "?" + subResource : "");
// Make sure the resource-path for signing does not contain
// any consecutive "/"s.
// Note that we should also follow the same rule to escape
// consecutive "/"s when generating the presigned URL.
// See ServiceUtils#convertRequestToUrl(...)
resourcePath = resourcePath.replaceAll("(?<=/)/", "%2F");
new S3QueryStringSigner(methodName.toString(), resourcePath, expiration)
.sign(request, CredentialUtils.getCredentialsProvider(request.getOriginalRequest(), awsCredentialsProvider).getCredentials());
// The Amazon S3 DevPay token header is a special exception and can be safely moved
// from the request's headers into the query string to ensure that it travels along
// with the pre-signed URL when it's sent back to Amazon S3.
if (request.getHeaders().containsKey(Headers.SECURITY_TOKEN)) {
String value = request.getHeaders().get(Headers.SECURITY_TOKEN);
request.addParameter(Headers.SECURITY_TOKEN, value);
request.getHeaders().remove(Headers.SECURITY_TOKEN);
}
}
示例14: getSignedUploadUrl
import com.amazonaws.HttpMethod; //导入依赖的package包/类
public String getSignedUploadUrl(String bucket, String fileKey, String contentType, Map headers) {
GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucket, fileKey);
if (!empty(contentType)) {
req.setContentType(contentType);
}
if (headers != null) {
for (Object key: headers.keySet())
req.addRequestParameter(key.toString(), headers.get(key).toString());
}
req.setExpiration(Date.from(utcNow().plusDays(2).toInstant()));
req.setMethod(HttpMethod.PUT);
return client.generatePresignedUrl(req).toString();
}
示例15: main
import com.amazonaws.HttpMethod; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// create the AWS S3 Client
AmazonS3 s3 = AWSS3Factory.getS3Client();
// retrieve the key value from user
System.out.println( "Enter the object key:" );
String key = new BufferedReader( new InputStreamReader( System.in ) ).readLine();
// retrieve the expiration time for the object from user
System.out.print( "How many hours should this tag be valid? " );
String hours = new BufferedReader( new InputStreamReader( System.in ) ).readLine();
// convert hours to a date
Date expiration = new Date();
long curTime_msec = expiration.getTime();
long nHours = Long.valueOf(hours);
curTime_msec += 60 * 60 * 1000 * nHours;
expiration.setTime(curTime_msec);
// generate the object's pre-signed URL
GeneratePresignedUrlRequest presignedUrl = new GeneratePresignedUrlRequest(AWSS3Factory.S3_BUCKET, key);
presignedUrl.setMethod(HttpMethod.GET);
presignedUrl.setExpiration(expiration);
URL url = s3.generatePresignedUrl(presignedUrl);
// print object's pre-signed URL
System.out.println( String.format("object [%s/%s] pre-signed URL: [%s]",
AWSS3Factory.S3_BUCKET, key, url.toString()));
}