List of usage examples for com.amazonaws.services.s3 AmazonS3URI AmazonS3URI
private AmazonS3URI(final URI uri, final boolean urlEncode)
From source file:com.netflix.genie.web.services.impl.S3FileTransferImpl.java
License:Apache License
@VisibleForTesting AmazonS3URI getS3Uri(final String path) throws GenieBadRequestException { if (!S3_PREFIX_PATTERN.matcher(path).matches()) { throw new GenieBadRequestException(String.format("Invalid prefix in path for s3 file %s", path)); }//ww w. jav a 2s.c o m // Delegate validation and parsing to AmazonS3URI. // However it cannot handle "s3n://", so strip the 'n' final String adjustedPath = path.replaceFirst("^s3n://", "s3://"); final AmazonS3URI uri; try { uri = new AmazonS3URI(adjustedPath, false); } catch (IllegalArgumentException e) { throw new GenieBadRequestException(String.format("Invalid path for s3 file %s", path), e); } if (StringUtils.isBlank(uri.getBucket()) || StringUtils.isBlank(uri.getKey())) { throw new GenieBadRequestException( String.format("Invalid blank components in path for s3 file %s", path)); } final boolean bucketPassesStrictValidation = S3_BUCKET_PATTERN.matcher(uri.getBucket()).matches(); final boolean keyPassesStrictValidation = S3_KEY_PATTERN.matcher(uri.getKey()).matches(); // URL fails strict validation check! if (!bucketPassesStrictValidation || !keyPassesStrictValidation) { if (this.s3FileTransferProperties.isStrictUrlCheckEnabled()) { throw new GenieBadRequestException( String.format("Invalid bucket %s in path for s3 file %s", uri.getBucket(), path)); } else { log.warn("S3 URL fails strict validation: \"{}\"", path); this.urlFailingStrictValidationCounter.increment(); } } return uri; }