Search in sources :

Example 1 with PresigningRequest

use of com.amazonaws.services.polly.internal.PresigningRequest in project aws-sdk-android by aws-amplify.

the class AmazonPollyPresigningClient method getPresignedSynthesizeSpeechUrl.

/**
 * <p>
 * Returns a pre-signed URL for accessing an Amazon Polly resource.
 * </p>
 * <p>
 * Pre-signed URLs allow clients to form a URL for an Amazon Polly
 * resource, and then sign it with the current AWS security credentials.
 * The pre-signed URL can be shared to other users, allowing access to
 * the resource without providing an account's AWS security credentials.
 * </p>
 * <p>
 * Pre-signed URLs are useful in many situations where AWS security
 * credentials aren't available from the client that needs to make the
 * actual request to Amazon Polly.
 * </p>
 * <p>
 * For example, a pre-signed URL to GET the synthesized speech audio stream
 * using the owner's AWS account can be generated and passed to a system
 * media player.
 * </p>
 *
 * @param synthesizeSpeechPresignRequest Object providing pre-signed synthesize speech
 *              request parameters.
 * @return Pre-signed URL of audio stream containing synthesized speech
 *              matching parameters provided in synthesizeSpeechPresignRequest
 *              that is possible to obtain using HTTP GET method.
 */
public URL getPresignedSynthesizeSpeechUrl(SynthesizeSpeechPresignRequest synthesizeSpeechPresignRequest) {
    Request<PresigningRequest> request = new SynthesizeSpeechPresignRequestMarshaller().marshall(synthesizeSpeechPresignRequest);
    request.setEndpoint(endpoint);
    request.setTimeOffset(timeOffset);
    if (synthesizeSpeechPresignRequest.getExpiration() == null) {
        synthesizeSpeechPresignRequest.setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * DEFAULT_GET_REQUEST_EXPIRATION_MINUTES));
    }
    Signer signer = getSignerByURI(endpoint);
    if (!(signer instanceof Presigner)) {
        throw new AmazonClientException("Unsupported signer");
    }
    Presigner presigner = (Presigner) signer;
    Date expirationDate = synthesizeSpeechPresignRequest.getExpiration();
    AWSCredentials credentials = synthesizeSpeechPresignRequest.getRequestCredentials();
    if (credentials == null) {
        credentials = awsCredentialsProvider.getCredentials();
    }
    presigner.presignRequest(request, credentials, expirationDate);
    // Remove the leading slash (if any) in the resource-path
    return ServiceUtils.convertRequestToUrl(request, true);
}
Also used : Signer(com.amazonaws.auth.Signer) AmazonClientException(com.amazonaws.AmazonClientException) SynthesizeSpeechPresignRequestMarshaller(com.amazonaws.services.polly.model.transform.SynthesizeSpeechPresignRequestMarshaller) PresigningRequest(com.amazonaws.services.polly.internal.PresigningRequest) AWSCredentials(com.amazonaws.auth.AWSCredentials) Date(java.util.Date) Presigner(com.amazonaws.auth.Presigner) AmazonPollyCustomPresigner(com.amazonaws.services.polly.internal.AmazonPollyCustomPresigner)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 Presigner (com.amazonaws.auth.Presigner)1 Signer (com.amazonaws.auth.Signer)1 AmazonPollyCustomPresigner (com.amazonaws.services.polly.internal.AmazonPollyCustomPresigner)1 PresigningRequest (com.amazonaws.services.polly.internal.PresigningRequest)1 SynthesizeSpeechPresignRequestMarshaller (com.amazonaws.services.polly.model.transform.SynthesizeSpeechPresignRequestMarshaller)1 Date (java.util.Date)1