/** * Converts the specified request object into a URL, containing all the * specified parameters, the specified request endpoint, etc. * * @param request * The request to convert into a URL. * @param removeLeadingSlashInResourcePath * Whether the leading slash in resource-path should be removed * before appending to the endpoint. * @return A new URL representing the specified request. * * @throws SdkClientException * If the request cannot be converted to a well formed URL. * @deprecated No longer used. May be removed in a future major version. */ @Deprecated public static URL convertRequestToUrl(Request<?> request, boolean removeLeadingSlashInResourcePath) { return convertRequestToUrl(request, removeLeadingSlashInResourcePath, true); }
/** * Converts the specified request object into a URL, containing all the * specified parameters, the specified request endpoint, etc. * * @param request * The request to convert into a URL. * @return A new URL representing the specified request. * * @throws SdkClientException * If the request cannot be converted to a well formed URL. * @deprecated No longer used. May be removed in a future major version. */ @Deprecated public static URL convertRequestToUrl(Request<?> request) { // To be backward compatible, this method by default does not // remove the leading slash in the request resource-path. return convertRequestToUrl(request, false); }
@Override public URL getUrl(String bucketName, String key) { Request<?> request = new DefaultRequest<Object>(Constants.S3_SERVICE_DISPLAY_NAME); resolveRequestEndpoint(request, bucketName, key, endpoint); return ServiceUtils.convertRequestToUrl(request, false, false); }
return ServiceUtils.convertRequestToUrl(request, true, false);
/** * Converts the specified request object into a URL, containing all the * specified parameters, the specified request endpoint, etc. * * @param request The request to convert into a URL. * @return A new URL representing the specified request. * @throws AmazonClientException If the request cannot be converted to a * well formed URL. */ public static URL convertRequestToUrl(Request<?> request) { // To be backward compatible, this method by default does not // remove the leading slash in the request resource-path. return convertRequestToUrl(request, false); }
/** * Returns an URL for the object stored in the specified bucket and key. * <p> * If the object identified by the given bucket and key has public read * permissions (ex: {@link CannedAccessControlList#PublicRead}), then this * URL can be directly accessed to retrieve the object's data. * * @param bucketName The name of the bucket containing the object whose URL * is being requested. * @param key The key under which the object whose URL is being requested is * stored. * @return A unique URL for the object stored in the specified bucket and * key. */ @Override public URL getUrl(String bucketName, String key) { final Request<?> request = new DefaultRequest<Object>(Constants.S3_SERVICE_DISPLAY_NAME); resolveRequestEndpoint(request, bucketName, key); return ServiceUtils.convertRequestToUrl(request); }
@Test public void testSign() throws URISyntaxException { final S3QueryStringSigner signer = new S3QueryStringSigner("GET", "/test-bucket123456/TestFile.txt", new Date(1431377237312L)); final GetObjectRequest gr = new GetObjectRequest("test-bucket123456", "TestFile.txt"); final Request<?> req = new DefaultRequest(gr, Constants.S3_SERVICE_DISPLAY_NAME); req.setHttpMethod(HttpMethodName.GET); req.setResourcePath("TestFile.txt"); req.setEndpoint(new URI("https://test-bucket123456.s3-us-west-2.amazonaws.com")); signer.sign(req, new BasicAWSCredentials( "AKIAJD11BOGUS11ACCESS11KEYXMGOZQ", "LYd/ZD4F11BOGUS11SECRET11KEYOM1SiD6")); assertEquals( "https://test-bucket123456.s3-us-west-2.amazonaws.com/TestFile.txt?AWSAccessKeyId=AKIAJD11BOGUS11ACCESS11KEYXMGOZQ&Expires=1431377237&Signature=vtILMLWYdEalygpKGFv%2FqvP5qp8%3D", ServiceUtils.convertRequestToUrl(req, true).toString()); } }
@Test(expected = AmazonClientException.class) public void testConvertRequestUrlThrow() throws URISyntaxException { final Request<String> req = new DefaultRequest<String>("s3"); req.setHttpMethod(HttpMethodName.GET); req.setEndpoint(new URI("htps://test-bucket1234.s3.amazonaws.com")); req.setResourcePath("/TestFile.txt"); req.withParameter("AWSAccessKeyId", "TESTJDND73Z2EOXMTEST"); req.withParameter("Expires", "1430878121"); req.withParameter("Signature", "SxXP9iKzsnIeCjYBKFS8iW/9Bus="); final URL craftedURL = ServiceUtils.convertRequestToUrl(req, true); }
@Test public void testConvertRequestToURL() throws URISyntaxException, MalformedURLException { /** * Request which generates this presigned URL Request: GET * https://test-bucket1234.s3.amazonaws.com /TestFile.txt Parameters: * (AWSAccessKeyId: TESTJDND73Z2EOXMTEST, Expires: 1430878121, * Signature: SxXP9iKzsnIeCjYBKFS8iW/9Bus=, ) 05-05 18:08:41.265: * I/System.out(28304): URL: * https://test-bucket1234.s3.amazonaws.com/TestFile * .txt?AWSAccessKeyId=TESTJDND73Z2EOXMTEST * &Expires=1430878121&Signature=SxXP9iKzsnIeCjYBKFS8iW%2F9Bus%3D */ final Request<String> req = new DefaultRequest<String>("s3"); req.setHttpMethod(HttpMethodName.GET); req.setEndpoint(new URI("https://test-bucket1234.s3.amazonaws.com")); req.setResourcePath("/TestFile.txt"); req.withParameter("AWSAccessKeyId", "TESTJDND73Z2EOXMTEST"); req.withParameter("Expires", "1430878121"); req.withParameter("Signature", "SxXP9iKzsnIeCjYBKFS8iW/9Bus="); final URL craftedURL = ServiceUtils.convertRequestToUrl(req, true); assertEquals( new URL( "https://test-bucket1234.s3.amazonaws.com/TestFile.txt?AWSAccessKeyId=TESTJDND73Z2EOXMTEST&Expires=1430878121&Signature=SxXP9iKzsnIeCjYBKFS8iW%2F9Bus%3D"), craftedURL); final URL url = ServiceUtils.convertRequestToUrl(req); assertEquals( new URL( "https://test-bucket1234.s3.amazonaws.com/%2FTestFile.txt?AWSAccessKeyId=TESTJDND73Z2EOXMTEST&Expires=1430878121&Signature=SxXP9iKzsnIeCjYBKFS8iW%2F9Bus%3D"), url); }
/** * Converts the specified request object into a URL, containing all the * specified parameters, the specified request endpoint, etc. * * @param request The request to convert into a URL. * @return A new URL representing the specified request. * @throws AmazonClientException If the request cannot be converted to a * well formed URL. */ public static URL convertRequestToUrl(Request<?> request) { // To be backward compatible, this method by default does not // remove the leading slash in the request resource-path. return convertRequestToUrl(request, false); }
/** * Converts the specified request object into a URL, containing all the * specified parameters, the specified request endpoint, etc. * * @param request * The request to convert into a URL. * @param removeLeadingSlashInResourcePath * Whether the leading slash in resource-path should be removed * before appending to the endpoint. * @return A new URL representing the specified request. * * @throws SdkClientException * If the request cannot be converted to a well formed URL. * @deprecated No longer used. May be removed in a future major version. */ @Deprecated public static URL convertRequestToUrl(Request<?> request, boolean removeLeadingSlashInResourcePath) { return convertRequestToUrl(request, removeLeadingSlashInResourcePath, true); }
/** * Converts the specified request object into a URL, containing all the * specified parameters, the specified request endpoint, etc. * * @param request * The request to convert into a URL. * @return A new URL representing the specified request. * * @throws SdkClientException * If the request cannot be converted to a well formed URL. * @deprecated No longer used. May be removed in a future major version. */ @Deprecated public static URL convertRequestToUrl(Request<?> request) { // To be backward compatible, this method by default does not // remove the leading slash in the request resource-path. return convertRequestToUrl(request, false); }
return ServiceUtils.convertRequestToUrl(request, true);
@Override public URL getUrl(String bucketName, String key) { Request<?> request = new DefaultRequest<Object>(Constants.S3_SERVICE_DISPLAY_NAME); resolveRequestEndpoint(request, bucketName, key, endpoint); return ServiceUtils.convertRequestToUrl(request, false, false); }
/** * Returns an URL for the object stored in the specified bucket and key. * <p> * If the object identified by the given bucket and key has public read * permissions (ex: {@link CannedAccessControlList#PublicRead}), then this * URL can be directly accessed to retrieve the object's data. * * @param bucketName The name of the bucket containing the object whose URL * is being requested. * @param key The key under which the object whose URL is being requested is * stored. * @return A unique URL for the object stored in the specified bucket and * key. */ @Override public URL getUrl(String bucketName, String key) { final Request<?> request = new DefaultRequest<Object>(Constants.S3_SERVICE_DISPLAY_NAME); resolveRequestEndpoint(request, bucketName, key); return ServiceUtils.convertRequestToUrl(request); }
@Override public URL getCreateSpeechUrl(CreateSpeechRequest createSpeechRequest) throws UnsupportedEncodingException { createSpeechRequest.setMethodType(MethodType.GET); Request<CreateSpeechRequest> request = CreateSpeechRequestMarshallerFactory.getMarshaller( createSpeechRequest.getMethodType()).marshall(createSpeechRequest); return ServiceUtils.convertRequestToUrl(prepareRequestForGetUrl(request)); }
@Override public URL getListVoicesUrl(ListVoicesRequest listVoicesRequest) throws UnsupportedEncodingException { listVoicesRequest.setMethodType(MethodType.GET); Request<ListVoicesRequest> request = ListVoicesRequestMarshallerFactory.getMarshaller( listVoicesRequest.getMethodType()).marshall(listVoicesRequest); return ServiceUtils.convertRequestToUrl(prepareRequestForGetUrl(request)); }
return ServiceUtils.convertRequestToUrl(request, true, false);
return ServiceUtils.convertRequestToUrl(request, true);