All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.transcribe.DefaultTranscribeAsyncClient Maven / Gradle / Ivy

/*
 * Copyright 2014-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.transcribe;

import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.ApiName;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.handler.AsyncClientHandler;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.http.HttpResponseHandler;
import software.amazon.awssdk.core.util.VersionInfo;
import software.amazon.awssdk.protocols.core.ExceptionMetadata;
import software.amazon.awssdk.protocols.json.AwsJsonProtocol;
import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.JsonOperationMetadata;
import software.amazon.awssdk.services.transcribe.model.BadRequestException;
import software.amazon.awssdk.services.transcribe.model.ConflictException;
import software.amazon.awssdk.services.transcribe.model.CreateVocabularyRequest;
import software.amazon.awssdk.services.transcribe.model.CreateVocabularyResponse;
import software.amazon.awssdk.services.transcribe.model.DeleteTranscriptionJobRequest;
import software.amazon.awssdk.services.transcribe.model.DeleteTranscriptionJobResponse;
import software.amazon.awssdk.services.transcribe.model.DeleteVocabularyRequest;
import software.amazon.awssdk.services.transcribe.model.DeleteVocabularyResponse;
import software.amazon.awssdk.services.transcribe.model.GetTranscriptionJobRequest;
import software.amazon.awssdk.services.transcribe.model.GetTranscriptionJobResponse;
import software.amazon.awssdk.services.transcribe.model.GetVocabularyRequest;
import software.amazon.awssdk.services.transcribe.model.GetVocabularyResponse;
import software.amazon.awssdk.services.transcribe.model.InternalFailureException;
import software.amazon.awssdk.services.transcribe.model.LimitExceededException;
import software.amazon.awssdk.services.transcribe.model.ListTranscriptionJobsRequest;
import software.amazon.awssdk.services.transcribe.model.ListTranscriptionJobsResponse;
import software.amazon.awssdk.services.transcribe.model.ListVocabulariesRequest;
import software.amazon.awssdk.services.transcribe.model.ListVocabulariesResponse;
import software.amazon.awssdk.services.transcribe.model.NotFoundException;
import software.amazon.awssdk.services.transcribe.model.StartTranscriptionJobRequest;
import software.amazon.awssdk.services.transcribe.model.StartTranscriptionJobResponse;
import software.amazon.awssdk.services.transcribe.model.TranscribeException;
import software.amazon.awssdk.services.transcribe.model.TranscribeRequest;
import software.amazon.awssdk.services.transcribe.model.UpdateVocabularyRequest;
import software.amazon.awssdk.services.transcribe.model.UpdateVocabularyResponse;
import software.amazon.awssdk.services.transcribe.paginators.ListTranscriptionJobsPublisher;
import software.amazon.awssdk.services.transcribe.paginators.ListVocabulariesPublisher;
import software.amazon.awssdk.services.transcribe.transform.CreateVocabularyRequestMarshaller;
import software.amazon.awssdk.services.transcribe.transform.DeleteTranscriptionJobRequestMarshaller;
import software.amazon.awssdk.services.transcribe.transform.DeleteVocabularyRequestMarshaller;
import software.amazon.awssdk.services.transcribe.transform.GetTranscriptionJobRequestMarshaller;
import software.amazon.awssdk.services.transcribe.transform.GetVocabularyRequestMarshaller;
import software.amazon.awssdk.services.transcribe.transform.ListTranscriptionJobsRequestMarshaller;
import software.amazon.awssdk.services.transcribe.transform.ListVocabulariesRequestMarshaller;
import software.amazon.awssdk.services.transcribe.transform.StartTranscriptionJobRequestMarshaller;
import software.amazon.awssdk.services.transcribe.transform.UpdateVocabularyRequestMarshaller;
import software.amazon.awssdk.utils.CompletableFutureUtils;

/**
 * Internal implementation of {@link TranscribeAsyncClient}.
 *
 * @see TranscribeAsyncClient#builder()
 */
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultTranscribeAsyncClient implements TranscribeAsyncClient {
    private static final Logger log = LoggerFactory.getLogger(DefaultTranscribeAsyncClient.class);

    private final AsyncClientHandler clientHandler;

    private final AwsJsonProtocolFactory protocolFactory;

    private final SdkClientConfiguration clientConfiguration;

    protected DefaultTranscribeAsyncClient(SdkClientConfiguration clientConfiguration) {
        this.clientHandler = new AwsAsyncClientHandler(clientConfiguration);
        this.clientConfiguration = clientConfiguration;
        this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build();
    }

    @Override
    public final String serviceName() {
        return SERVICE_NAME;
    }

    /**
     * 

* Creates a new custom vocabulary that you can use to change the way Amazon Transcribe handles transcription of an * audio file. *

* * @param createVocabularyRequest * @return A Java Future containing the result of the CreateVocabulary operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • BadRequestException Your request didn't pass one or more validation tests. For example, if the * transcription you're trying to delete doesn't exist or if it is in a non-terminal state (for example, * it's "in progress"). See the exception Message field for more information.
  • *
  • LimitExceededException Either you have sent too many requests or your input file is too long. Wait * before you resend your request, or use a smaller file and resend the request.
  • *
  • InternalFailureException There was an internal error. Check the error message and try your request * again.
  • *
  • ConflictException When you are using the StartTranscriptionJob operation, the * JobName field is a duplicate of a previously entered job name. Resend your request with a * different name.

    *

    * When you are using the UpdateVocabulary operation, there are two jobs running at the same * time. Resend the second request later.

  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • TranscribeException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample TranscribeAsyncClient.CreateVocabulary * @see AWS * API Documentation */ @Override public CompletableFuture createVocabulary(CreateVocabularyRequest createVocabularyRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, CreateVocabularyResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("CreateVocabulary") .withMarshaller(new CreateVocabularyRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(createVocabularyRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Deletes a previously submitted transcription job along with any other generated results such as the * transcription, models, and so on. *

* * @param deleteTranscriptionJobRequest * @return A Java Future containing the result of the DeleteTranscriptionJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • LimitExceededException Either you have sent too many requests or your input file is too long. Wait * before you resend your request, or use a smaller file and resend the request.
  • *
  • BadRequestException Your request didn't pass one or more validation tests. For example, if the * transcription you're trying to delete doesn't exist or if it is in a non-terminal state (for example, * it's "in progress"). See the exception Message field for more information.
  • *
  • InternalFailureException There was an internal error. Check the error message and try your request * again.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • TranscribeException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample TranscribeAsyncClient.DeleteTranscriptionJob * @see AWS API Documentation */ @Override public CompletableFuture deleteTranscriptionJob( DeleteTranscriptionJobRequest deleteTranscriptionJobRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, DeleteTranscriptionJobResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("DeleteTranscriptionJob") .withMarshaller(new DeleteTranscriptionJobRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(deleteTranscriptionJobRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Deletes a vocabulary from Amazon Transcribe. *

* * @param deleteVocabularyRequest * @return A Java Future containing the result of the DeleteVocabulary operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • NotFoundException We can't find the requested resource. Check the name and try your request again.
  • *
  • LimitExceededException Either you have sent too many requests or your input file is too long. Wait * before you resend your request, or use a smaller file and resend the request.
  • *
  • BadRequestException Your request didn't pass one or more validation tests. For example, if the * transcription you're trying to delete doesn't exist or if it is in a non-terminal state (for example, * it's "in progress"). See the exception Message field for more information.
  • *
  • InternalFailureException There was an internal error. Check the error message and try your request * again.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • TranscribeException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample TranscribeAsyncClient.DeleteVocabulary * @see AWS * API Documentation */ @Override public CompletableFuture deleteVocabulary(DeleteVocabularyRequest deleteVocabularyRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, DeleteVocabularyResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("DeleteVocabulary") .withMarshaller(new DeleteVocabularyRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(deleteVocabularyRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Returns information about a transcription job. To see the status of the job, check the * TranscriptionJobStatus field. If the status is COMPLETED, the job is finished and you * can find the results at the location specified in the TranscriptionFileUri field. *

* * @param getTranscriptionJobRequest * @return A Java Future containing the result of the GetTranscriptionJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • BadRequestException Your request didn't pass one or more validation tests. For example, if the * transcription you're trying to delete doesn't exist or if it is in a non-terminal state (for example, * it's "in progress"). See the exception Message field for more information.
  • *
  • LimitExceededException Either you have sent too many requests or your input file is too long. Wait * before you resend your request, or use a smaller file and resend the request.
  • *
  • InternalFailureException There was an internal error. Check the error message and try your request * again.
  • *
  • NotFoundException We can't find the requested resource. Check the name and try your request again.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • TranscribeException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample TranscribeAsyncClient.GetTranscriptionJob * @see AWS * API Documentation */ @Override public CompletableFuture getTranscriptionJob( GetTranscriptionJobRequest getTranscriptionJobRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, GetTranscriptionJobResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("GetTranscriptionJob") .withMarshaller(new GetTranscriptionJobRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(getTranscriptionJobRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Gets information about a vocabulary. *

* * @param getVocabularyRequest * @return A Java Future containing the result of the GetVocabulary operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • NotFoundException We can't find the requested resource. Check the name and try your request again.
  • *
  • LimitExceededException Either you have sent too many requests or your input file is too long. Wait * before you resend your request, or use a smaller file and resend the request.
  • *
  • InternalFailureException There was an internal error. Check the error message and try your request * again.
  • *
  • BadRequestException Your request didn't pass one or more validation tests. For example, if the * transcription you're trying to delete doesn't exist or if it is in a non-terminal state (for example, * it's "in progress"). See the exception Message field for more information.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • TranscribeException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample TranscribeAsyncClient.GetVocabulary * @see AWS API * Documentation */ @Override public CompletableFuture getVocabulary(GetVocabularyRequest getVocabularyRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, GetVocabularyResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("GetVocabulary") .withMarshaller(new GetVocabularyRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(getVocabularyRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Lists transcription jobs with the specified status. *

* * @param listTranscriptionJobsRequest * @return A Java Future containing the result of the ListTranscriptionJobs operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • BadRequestException Your request didn't pass one or more validation tests. For example, if the * transcription you're trying to delete doesn't exist or if it is in a non-terminal state (for example, * it's "in progress"). See the exception Message field for more information.
  • *
  • LimitExceededException Either you have sent too many requests or your input file is too long. Wait * before you resend your request, or use a smaller file and resend the request.
  • *
  • InternalFailureException There was an internal error. Check the error message and try your request * again.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • TranscribeException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample TranscribeAsyncClient.ListTranscriptionJobs * @see AWS API Documentation */ @Override public CompletableFuture listTranscriptionJobs( ListTranscriptionJobsRequest listTranscriptionJobsRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, ListTranscriptionJobsResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("ListTranscriptionJobs") .withMarshaller(new ListTranscriptionJobsRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(listTranscriptionJobsRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Lists transcription jobs with the specified status. *

*
*

* This is a variant of * {@link #listTranscriptionJobs(software.amazon.awssdk.services.transcribe.model.ListTranscriptionJobsRequest)} * operation. The return type is a custom publisher that can be subscribed to request a stream of response pages. * SDK will internally handle making service calls for you. *

*

* When the operation is called, an instance of this class is returned. At this point, no service calls are made yet * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the * failures only after you start streaming the data. The subscribe method should be called as a request to start * streaming data. For more info, see * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the * starting request. *

* *

* The following are few ways to use the response class: *

* 1) Using the subscribe helper method * *
     * {@code
     * software.amazon.awssdk.services.transcribe.paginators.ListTranscriptionJobsPublisher publisher = client.listTranscriptionJobsPaginator(request);
     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
     * future.get();
     * }
     * 
* * 2) Using a custom subscriber * *
     * {@code
     * software.amazon.awssdk.services.transcribe.paginators.ListTranscriptionJobsPublisher publisher = client.listTranscriptionJobsPaginator(request);
     * publisher.subscribe(new Subscriber() {
     * 
     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
     * 
     * 
     * public void onNext(software.amazon.awssdk.services.transcribe.model.ListTranscriptionJobsResponse response) { //... };
     * });}
     * 
* * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. *

* Note: If you prefer to have control on service calls, use the * {@link #listTranscriptionJobs(software.amazon.awssdk.services.transcribe.model.ListTranscriptionJobsRequest)} * operation. *

* * @param listTranscriptionJobsRequest * @return A custom publisher that can be subscribed to request a stream of response pages.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • BadRequestException Your request didn't pass one or more validation tests. For example, if the * transcription you're trying to delete doesn't exist or if it is in a non-terminal state (for example, * it's "in progress"). See the exception Message field for more information.
  • *
  • LimitExceededException Either you have sent too many requests or your input file is too long. Wait * before you resend your request, or use a smaller file and resend the request.
  • *
  • InternalFailureException There was an internal error. Check the error message and try your request * again.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • TranscribeException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample TranscribeAsyncClient.ListTranscriptionJobs * @see AWS API Documentation */ public ListTranscriptionJobsPublisher listTranscriptionJobsPaginator(ListTranscriptionJobsRequest listTranscriptionJobsRequest) { return new ListTranscriptionJobsPublisher(this, applyPaginatorUserAgent(listTranscriptionJobsRequest)); } /** *

* Returns a list of vocabularies that match the specified criteria. If no criteria are specified, returns the * entire list of vocabularies. *

* * @param listVocabulariesRequest * @return A Java Future containing the result of the ListVocabularies operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • BadRequestException Your request didn't pass one or more validation tests. For example, if the * transcription you're trying to delete doesn't exist or if it is in a non-terminal state (for example, * it's "in progress"). See the exception Message field for more information.
  • *
  • LimitExceededException Either you have sent too many requests or your input file is too long. Wait * before you resend your request, or use a smaller file and resend the request.
  • *
  • InternalFailureException There was an internal error. Check the error message and try your request * again.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • TranscribeException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample TranscribeAsyncClient.ListVocabularies * @see AWS * API Documentation */ @Override public CompletableFuture listVocabularies(ListVocabulariesRequest listVocabulariesRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, ListVocabulariesResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("ListVocabularies") .withMarshaller(new ListVocabulariesRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(listVocabulariesRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Returns a list of vocabularies that match the specified criteria. If no criteria are specified, returns the * entire list of vocabularies. *

*
*

* This is a variant of * {@link #listVocabularies(software.amazon.awssdk.services.transcribe.model.ListVocabulariesRequest)} operation. * The return type is a custom publisher that can be subscribed to request a stream of response pages. SDK will * internally handle making service calls for you. *

*

* When the operation is called, an instance of this class is returned. At this point, no service calls are made yet * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the * failures only after you start streaming the data. The subscribe method should be called as a request to start * streaming data. For more info, see * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the * starting request. *

* *

* The following are few ways to use the response class: *

* 1) Using the subscribe helper method * *
     * {@code
     * software.amazon.awssdk.services.transcribe.paginators.ListVocabulariesPublisher publisher = client.listVocabulariesPaginator(request);
     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
     * future.get();
     * }
     * 
* * 2) Using a custom subscriber * *
     * {@code
     * software.amazon.awssdk.services.transcribe.paginators.ListVocabulariesPublisher publisher = client.listVocabulariesPaginator(request);
     * publisher.subscribe(new Subscriber() {
     * 
     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
     * 
     * 
     * public void onNext(software.amazon.awssdk.services.transcribe.model.ListVocabulariesResponse response) { //... };
     * });}
     * 
* * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. *

* Note: If you prefer to have control on service calls, use the * {@link #listVocabularies(software.amazon.awssdk.services.transcribe.model.ListVocabulariesRequest)} * operation. *

* * @param listVocabulariesRequest * @return A custom publisher that can be subscribed to request a stream of response pages.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • BadRequestException Your request didn't pass one or more validation tests. For example, if the * transcription you're trying to delete doesn't exist or if it is in a non-terminal state (for example, * it's "in progress"). See the exception Message field for more information.
  • *
  • LimitExceededException Either you have sent too many requests or your input file is too long. Wait * before you resend your request, or use a smaller file and resend the request.
  • *
  • InternalFailureException There was an internal error. Check the error message and try your request * again.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • TranscribeException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample TranscribeAsyncClient.ListVocabularies * @see AWS * API Documentation */ public ListVocabulariesPublisher listVocabulariesPaginator(ListVocabulariesRequest listVocabulariesRequest) { return new ListVocabulariesPublisher(this, applyPaginatorUserAgent(listVocabulariesRequest)); } /** *

* Starts an asynchronous job to transcribe speech to text. *

* * @param startTranscriptionJobRequest * @return A Java Future containing the result of the StartTranscriptionJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • BadRequestException Your request didn't pass one or more validation tests. For example, if the * transcription you're trying to delete doesn't exist or if it is in a non-terminal state (for example, * it's "in progress"). See the exception Message field for more information.
  • *
  • LimitExceededException Either you have sent too many requests or your input file is too long. Wait * before you resend your request, or use a smaller file and resend the request.
  • *
  • InternalFailureException There was an internal error. Check the error message and try your request * again.
  • *
  • ConflictException When you are using the StartTranscriptionJob operation, the * JobName field is a duplicate of a previously entered job name. Resend your request with a * different name.

    *

    * When you are using the UpdateVocabulary operation, there are two jobs running at the same * time. Resend the second request later.

  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • TranscribeException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample TranscribeAsyncClient.StartTranscriptionJob * @see AWS API Documentation */ @Override public CompletableFuture startTranscriptionJob( StartTranscriptionJobRequest startTranscriptionJobRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, StartTranscriptionJobResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("StartTranscriptionJob") .withMarshaller(new StartTranscriptionJobRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(startTranscriptionJobRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Updates an existing vocabulary with new values. The UpdateVocabulary operation overwrites all of the * existing information with the values that you provide in the request. *

* * @param updateVocabularyRequest * @return A Java Future containing the result of the UpdateVocabulary operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • BadRequestException Your request didn't pass one or more validation tests. For example, if the * transcription you're trying to delete doesn't exist or if it is in a non-terminal state (for example, * it's "in progress"). See the exception Message field for more information.
  • *
  • LimitExceededException Either you have sent too many requests or your input file is too long. Wait * before you resend your request, or use a smaller file and resend the request.
  • *
  • InternalFailureException There was an internal error. Check the error message and try your request * again.
  • *
  • NotFoundException We can't find the requested resource. Check the name and try your request again.
  • *
  • ConflictException When you are using the StartTranscriptionJob operation, the * JobName field is a duplicate of a previously entered job name. Resend your request with a * different name.

    *

    * When you are using the UpdateVocabulary operation, there are two jobs running at the same * time. Resend the second request later.

  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • TranscribeException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample TranscribeAsyncClient.UpdateVocabulary * @see AWS * API Documentation */ @Override public CompletableFuture updateVocabulary(UpdateVocabularyRequest updateVocabularyRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, UpdateVocabularyResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("UpdateVocabulary") .withMarshaller(new UpdateVocabularyRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(updateVocabularyRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } @Override public void close() { clientHandler.close(); } private > T init(T builder) { return builder .clientConfiguration(clientConfiguration) .defaultServiceExceptionSupplier(TranscribeException::builder) .protocol(AwsJsonProtocol.AWS_JSON) .protocolVersion("1.1") .registerModeledException( ExceptionMetadata.builder().errorCode("ConflictException") .exceptionBuilderSupplier(ConflictException::builder).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("NotFoundException") .exceptionBuilderSupplier(NotFoundException::builder).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("InternalFailureException") .exceptionBuilderSupplier(InternalFailureException::builder).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("BadRequestException") .exceptionBuilderSupplier(BadRequestException::builder).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("LimitExceededException") .exceptionBuilderSupplier(LimitExceededException::builder).build()); } private T applyPaginatorUserAgent(T request) { Consumer userAgentApplier = b -> b.addApiName(ApiName.builder() .version(VersionInfo.SDK_VERSION).name("PAGINATED").build()); AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() .map(c -> c.toBuilder().applyMutation(userAgentApplier).build()) .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build())); return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); } private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory, JsonOperationMetadata operationMetadata) { return protocolFactory.createErrorResponseHandler(operationMetadata); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy