com.amazonaws.http.ExecutionContext Java Examples

The following examples show how to use com.amazonaws.http.ExecutionContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 6 votes vote down vote up
private <Y> Request<Y> prepareRequest(Request<Y> request, ExecutionContext executionContext, boolean signRequest) {
    request.setEndpoint(endpoint);
    request.setTimeOffset(timeOffset);

    AWSCredentials credentials = awsCredentialsProvider.getCredentials();

    AmazonWebServiceRequest originalRequest = request.getOriginalRequest();
    if (originalRequest != null && originalRequest.getRequestCredentials() != null) {
        credentials = originalRequest.getRequestCredentials();
    }
    if (signRequest) {
        // expiration date is not currently supported on service side, but presignRequest method requires
        // this argument so one with default value is provided.
        Date expirationDate = DateTime.now(DateTimeZone.UTC)
                .plusMinutes(DEFAULT_GET_REQUEST_EXPIRATION_MINUTES).toDate();
        signer.presignRequest(request, credentials, expirationDate);
    } else {
        executionContext.setSigner(signer);
        executionContext.setCredentials(credentials);
    }
    return request;
}
 
Example #2
Source File: GettingStarted.java    From getting-started with MIT License 5 votes vote down vote up
private static RequestExecutionBuilder buildRequest(final Request request) {
  try {
    return new AmazonHttpClient(new ClientConfiguration()).requestExecutionBuilder()
        .executionContext(new ExecutionContext(true)).request(request)
        .errorResponseHandler(new ErrorResponseHandler(false));
  } catch (AmazonServiceException exception) {
    System.out.println("Unexpected status code in response: " + exception.getStatusCode());
    System.out.println("Content: " + exception.getRawResponseContent());
    throw new RuntimeException("Failed request. Aborting.");
  }
}
 
Example #3
Source File: GenericApiGatewayClient.java    From apigateway-generic-java-sdk with Apache License 2.0 5 votes vote down vote up
private GenericApiGatewayResponse execute(HttpMethodName method, String resourcePath, Map<String, String> headers, Map<String,List<String>> parameters, InputStream content) {
    final ExecutionContext executionContext = buildExecutionContext();

    DefaultRequest request = new DefaultRequest(API_GATEWAY_SERVICE_NAME);
    request.setHttpMethod(method);
    request.setContent(content);
    request.setEndpoint(this.endpoint);
    request.setResourcePath(resourcePath);
    request.setHeaders(buildRequestHeaders(headers, apiKey));
    if (parameters != null) {
        request.setParameters(parameters);
    }
    return this.client.execute(request, responseHandler, errorResponseHandler, executionContext).getAwsResponse();
}
 
Example #4
Source File: GenericApiGatewayClient.java    From apigateway-generic-java-sdk with Apache License 2.0 5 votes vote down vote up
private ExecutionContext buildExecutionContext() {
    final ExecutionContext executionContext = ExecutionContext.builder().withSignerProvider(
            new DefaultSignerProvider(this, signer)).build();
    executionContext.setCredentialsProvider(credentials);
    executionContext.setSigner(signer);
    return executionContext;
}
 
Example #5
Source File: EsHttpRequest.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Perform this request.	
 */
@Override
public T perform() {
    final Response<T> rsp = new AmazonHttpClient(new ClientConfiguration())
        .requestExecutionBuilder()
        .executionContext(new ExecutionContext(true))
        .request(this.request)
        .errorResponseHandler(this.errHandler)
        .execute(this.respHandler);
    return rsp.getAwsResponse();
}
 
Example #6
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public CreateSpeechResult createSpeech(CreateSpeechRequest createSpeechRequest) throws AmazonServiceException,
        AmazonClientException {

    ExecutionContext executionContext = createExecutionContext(createSpeechRequest);
    Request<CreateSpeechRequest> request = CreateSpeechRequestMarshallerFactory.getMarshaller(
            createSpeechRequest.getMethodType()).marshall(createSpeechRequest);
    CreateSpeechResultUnmarshaller unmarshaller = new CreateSpeechResultUnmarshaller();
    StreamResponseHandler<CreateSpeechResult> responseHandler =
            new StreamResponseHandler<CreateSpeechResult>(unmarshaller);
    Response<CreateSpeechResult> response = invoke(request, responseHandler, executionContext);
    return response.getAwsResponse();
}
 
Example #7
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public ListVoicesResult listVoices(ListVoicesRequest listVoicesRequest) throws AmazonServiceException,
        AmazonClientException {

    ExecutionContext executionContext = createExecutionContext(listVoicesRequest);
    Request<ListVoicesRequest> request = ListVoicesRequestMarshallerFactory.getMarshaller(
            listVoicesRequest.getMethodType()).marshall(listVoicesRequest);
    Unmarshaller<ListVoicesResult, JsonUnmarshallerContext> unmarshaller = new ListVoicesResultJsonUnmarshaller();
    JsonResponseHandler<ListVoicesResult> responseHandler =
            new JsonResponseHandler<ListVoicesResult>(unmarshaller);
    Response<ListVoicesResult> response = invoke(request, responseHandler, executionContext);
    return response.getAwsResponse();
}
 
Example #8
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteLexicon(DeleteLexiconRequest deleteLexiconRequest)
        throws AmazonServiceException, AmazonClientException {

    ExecutionContext executionContext = createExecutionContext(deleteLexiconRequest);
    DeleteLexiconRequestMarshaller marshaller = new DeleteLexiconPostRequestMarshaller();
    Request<DeleteLexiconRequest> request = marshaller.marshall(deleteLexiconRequest);
    JsonResponseHandler<Void> responseHandler = new JsonResponseHandler<Void>(null);

    invoke(request, responseHandler, executionContext);
}
 
Example #9
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public GetLexiconResult getLexicon(GetLexiconRequest getLexiconRequest)
        throws AmazonServiceException, AmazonClientException {

    ExecutionContext executionContext = createExecutionContext(getLexiconRequest);
    GetLexiconRequestMarshaller marshaller = new GetLexiconPostRequestMarshaller();
    Request<GetLexiconRequest> request = marshaller.marshall(getLexiconRequest);
    Unmarshaller<GetLexiconResult, JsonUnmarshallerContext> unmarshaller = new GetLexiconResultJsonUnmarshaller();
    JsonResponseHandler<GetLexiconResult> responseHandler = new JsonResponseHandler<GetLexiconResult>(unmarshaller);

    Response<GetLexiconResult> response = invoke(request, responseHandler, executionContext);
    return response.getAwsResponse();
}
 
Example #10
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public ListLexiconsResult listLexicons() {
    ListLexiconsRequest listLexiconsRequest = new ListLexiconsRequest();
    ExecutionContext executionContext = createExecutionContext(listLexiconsRequest);
    ListLexiconsRequestMarshaller marshaller = new ListLexiconsPostRequestMarshaller();
    Request<ListLexiconsRequest> request = marshaller.marshall(listLexiconsRequest);
    Unmarshaller<ListLexiconsResult, JsonUnmarshallerContext> unmarshaller =
            new ListLexiconsResultJsonUnmarshaller();
    JsonResponseHandler<ListLexiconsResult> responseHandler =
            new JsonResponseHandler<ListLexiconsResult>(unmarshaller);

    Response<ListLexiconsResult> response = invoke(request, responseHandler, executionContext);
    return response.getAwsResponse();
}
 
Example #11
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public void putLexicon(PutLexiconRequest putLexiconRequest)
        throws AmazonServiceException, AmazonClientException {

    ExecutionContext executionContext = createExecutionContext(putLexiconRequest);
    PutLexiconRequestMarshaller marshaller = new PutLexiconPostRequestMarshaller();
    Request<PutLexiconRequest> request = marshaller.marshall(putLexiconRequest);
    JsonResponseHandler<Void> responseHandler = new JsonResponseHandler<Void>(null);

    invoke(request, responseHandler, executionContext);
}
 
Example #12
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
private <X, Y extends AmazonWebServiceRequest> Response<X> invoke(
        Request<Y> request,
        HttpResponseHandler<AmazonWebServiceResponse<X>> responseHandler,
        ExecutionContext executionContext) {

    JsonErrorResponseHandler errorResponseHandler = new JsonErrorResponseHandler(exceptionUnmarshallers);

    Response<X> result = client.execute(
            prepareRequest(request, executionContext),
            responseHandler,
            errorResponseHandler,
            executionContext);

    return result;
}
 
Example #13
Source File: GenericApiGatewayClient.java    From nifi with Apache License 2.0 5 votes vote down vote up
private GenericApiGatewayResponse execute(HttpMethodName method, String resourcePath, Map<String, String> headers, Map<String,List<String>> parameters, InputStream content) {
    final ExecutionContext executionContext = buildExecutionContext();

    DefaultRequest request = new DefaultRequest(API_GATEWAY_SERVICE_NAME);
    request.setHttpMethod(method);
    request.setContent(content);
    request.setEndpoint(this.endpoint);
    request.setResourcePath(resourcePath);
    request.setHeaders(buildRequestHeaders(headers, apiKey));
    if (parameters != null) {
        request.setParameters(parameters);
    }
    return this.client.execute(request, responseHandler, errorResponseHandler, executionContext).getAwsResponse();
}
 
Example #14
Source File: GenericApiGatewayClient.java    From nifi with Apache License 2.0 5 votes vote down vote up
private ExecutionContext buildExecutionContext() {
    final ExecutionContext executionContext = ExecutionContext.builder().withSignerProvider(
            new DefaultSignerProvider(this, signer)).build();
    executionContext.setCredentialsProvider(credentials);
    executionContext.setSigner(signer);
    return executionContext;
}
 
Example #15
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 4 votes vote down vote up
private <Y> Request<Y> prepareRequest(Request<Y> request, ExecutionContext executionContext) {
    return prepareRequest(request, executionContext, false);
}