Search in sources :

Example 11 with Response

use of software.amazon.awssdk.core.Response in project aws-sdk-java-v2 by aws.

the class BaseSyncClientHandler method execute.

@Override
public <InputT extends SdkRequest, OutputT extends SdkResponse> OutputT execute(ClientExecutionParams<InputT, OutputT> executionParams) {
    return measureApiCallSuccess(executionParams, () -> {
        // Running beforeExecution interceptors and modifyRequest interceptors.
        ExecutionContext executionContext = invokeInterceptorsAndCreateExecutionContext(executionParams);
        HttpResponseHandler<Response<OutputT>> combinedResponseHandler = createCombinedResponseHandler(executionParams, executionContext);
        return doExecute(executionParams, executionContext, combinedResponseHandler);
    });
}
Also used : Response(software.amazon.awssdk.core.Response) SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) SdkResponse(software.amazon.awssdk.core.SdkResponse) ExecutionContext(software.amazon.awssdk.core.http.ExecutionContext)

Example 12 with Response

use of software.amazon.awssdk.core.Response in project aws-sdk-java-v2 by aws.

the class CombinedResponseAsyncHttpResponseHandlerTest method successResponse_shouldCompleteHeaderFuture.

@Test
void successResponse_shouldCompleteHeaderFuture() {
    when(successResponseHandler.prepare()).thenReturn(CompletableFuture.completedFuture(null));
    CompletableFuture<Response<Void>> future = responseHandler.prepare();
    SdkHttpFullResponse sdkHttpFullResponse = SdkHttpFullResponse.builder().statusCode(200).build();
    Flowable<ByteBuffer> publisher = publisher();
    responseHandler.onHeaders(sdkHttpFullResponse);
    responseHandler.onStream(publisher);
    verify(successResponseHandler).prepare();
    verify(successResponseHandler).onStream(publisher);
    assertThat(future).isDone();
    assertThat(future.join().httpResponse()).isEqualTo(sdkHttpFullResponse);
}
Also used : Response(software.amazon.awssdk.core.Response) SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 13 with Response

use of software.amazon.awssdk.core.Response in project aws-sdk-java-v2 by aws.

the class DefaultXmlClient method streamingInputOperation.

/**
 * Some operation with a streaming input
 *
 * @param streamingInputOperationRequest
 * @param requestBody
 *        The content to send to the service. A {@link RequestBody} can be created using one of several factory
 *        methods for various sources of data. For example, to create a request body from a file you can do the
 *        following.
 *
 *        <pre>
 * {@code RequestBody.fromFile(new File("myfile.txt"))}
 * </pre>
 *
 *        See documentation in {@link RequestBody} for additional details and which sources of data are supported.
 *        The service documentation for the request content is as follows 'This be a stream'
 * @return Result of the StreamingInputOperation operation returned by the service.
 * @throws SdkException
 *         Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
 *         catch all scenarios.
 * @throws SdkClientException
 *         If any client side error occurs such as an IO related failure, failure to get credentials, etc.
 * @throws XmlException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample XmlClient.StreamingInputOperation
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/xml-service-2010-05-08/StreamingInputOperation"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public StreamingInputOperationResponse streamingInputOperation(StreamingInputOperationRequest streamingInputOperationRequest, RequestBody requestBody) throws AwsServiceException, SdkClientException, XmlException {
    HttpResponseHandler<Response<StreamingInputOperationResponse>> responseHandler = protocolFactory.createCombinedResponseHandler(StreamingInputOperationResponse::builder, new XmlOperationMetadata().withHasStreamingSuccessResponse(false));
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation");
        return clientHandler.execute(new ClientExecutionParams<StreamingInputOperationRequest, StreamingInputOperationResponse>().withOperationName("StreamingInputOperation").withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector).withInput(streamingInputOperationRequest).withRequestBody(requestBody).withMarshaller(StreamingRequestMarshaller.builder().delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)).requestBody(requestBody).build()));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : StreamingInputOperationResponse(software.amazon.awssdk.services.xml.model.StreamingInputOperationResponse) GetOperationWithChecksumResponse(software.amazon.awssdk.services.xml.model.GetOperationWithChecksumResponse) StreamingOutputOperationResponse(software.amazon.awssdk.services.xml.model.StreamingOutputOperationResponse) PutOperationWithChecksumResponse(software.amazon.awssdk.services.xml.model.PutOperationWithChecksumResponse) Response(software.amazon.awssdk.core.Response) APostOperationWithOutputResponse(software.amazon.awssdk.services.xml.model.APostOperationWithOutputResponse) APostOperationResponse(software.amazon.awssdk.services.xml.model.APostOperationResponse) OperationWithChecksumRequiredResponse(software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredResponse) StreamingInputOperationRequestMarshaller(software.amazon.awssdk.services.xml.transform.StreamingInputOperationRequestMarshaller) StreamingInputOperationRequest(software.amazon.awssdk.services.xml.model.StreamingInputOperationRequest) StreamingInputOperationResponse(software.amazon.awssdk.services.xml.model.StreamingInputOperationResponse) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) XmlOperationMetadata(software.amazon.awssdk.protocols.xml.XmlOperationMetadata)

Example 14 with Response

use of software.amazon.awssdk.core.Response in project aws-sdk-java-v2 by aws.

the class DefaultXmlClient method operationWithChecksumRequired.

/**
 * Invokes the OperationWithChecksumRequired operation.
 *
 * @param operationWithChecksumRequiredRequest
 * @return Result of the OperationWithChecksumRequired operation returned by the service.
 * @throws SdkException
 *         Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
 *         catch all scenarios.
 * @throws SdkClientException
 *         If any client side error occurs such as an IO related failure, failure to get credentials, etc.
 * @throws XmlException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample XmlClient.OperationWithChecksumRequired
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/xml-service-2010-05-08/OperationWithChecksumRequired"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public OperationWithChecksumRequiredResponse operationWithChecksumRequired(OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) throws AwsServiceException, SdkClientException, XmlException {
    HttpResponseHandler<Response<OperationWithChecksumRequiredResponse>> responseHandler = protocolFactory.createCombinedResponseHandler(OperationWithChecksumRequiredResponse::builder, new XmlOperationMetadata().withHasStreamingSuccessResponse(false));
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired");
        return clientHandler.execute(new ClientExecutionParams<OperationWithChecksumRequiredRequest, OperationWithChecksumRequiredResponse>().withOperationName("OperationWithChecksumRequired").withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector).withInput(operationWithChecksumRequiredRequest).putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, HttpChecksumRequired.create()).withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory)));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : StreamingInputOperationResponse(software.amazon.awssdk.services.xml.model.StreamingInputOperationResponse) GetOperationWithChecksumResponse(software.amazon.awssdk.services.xml.model.GetOperationWithChecksumResponse) StreamingOutputOperationResponse(software.amazon.awssdk.services.xml.model.StreamingOutputOperationResponse) PutOperationWithChecksumResponse(software.amazon.awssdk.services.xml.model.PutOperationWithChecksumResponse) Response(software.amazon.awssdk.core.Response) APostOperationWithOutputResponse(software.amazon.awssdk.services.xml.model.APostOperationWithOutputResponse) APostOperationResponse(software.amazon.awssdk.services.xml.model.APostOperationResponse) OperationWithChecksumRequiredResponse(software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredResponse) OperationWithChecksumRequiredRequest(software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredRequest) OperationWithChecksumRequiredResponse(software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredResponse) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) XmlOperationMetadata(software.amazon.awssdk.protocols.xml.XmlOperationMetadata) OperationWithChecksumRequiredRequestMarshaller(software.amazon.awssdk.services.xml.transform.OperationWithChecksumRequiredRequestMarshaller)

Example 15 with Response

use of software.amazon.awssdk.core.Response in project aws-sdk-java-v2 by aws.

the class DefaultXmlClient method aPostOperation.

/**
 * <p>
 * Performs a post operation to the xml service and has no output
 * </p>
 *
 * @param aPostOperationRequest
 * @return Result of the APostOperation operation returned by the service.
 * @throws InvalidInputException
 *         The request was rejected because an invalid or out-of-range value was supplied for an input parameter.
 * @throws SdkException
 *         Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
 *         catch all scenarios.
 * @throws SdkClientException
 *         If any client side error occurs such as an IO related failure, failure to get credentials, etc.
 * @throws XmlException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample XmlClient.APostOperation
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/xml-service-2010-05-08/APostOperation" target="_top">AWS
 *      API Documentation</a>
 */
@Override
public APostOperationResponse aPostOperation(APostOperationRequest aPostOperationRequest) throws InvalidInputException, AwsServiceException, SdkClientException, XmlException {
    HttpResponseHandler<Response<APostOperationResponse>> responseHandler = protocolFactory.createCombinedResponseHandler(APostOperationResponse::builder, new XmlOperationMetadata().withHasStreamingSuccessResponse(false));
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation");
        String hostPrefix = "foo-";
        String resolvedHostExpression = "foo-";
        return clientHandler.execute(new ClientExecutionParams<APostOperationRequest, APostOperationResponse>().withOperationName("APostOperation").withCombinedResponseHandler(responseHandler).withMetricCollector(apiCallMetricCollector).hostPrefixExpression(resolvedHostExpression).withInput(aPostOperationRequest).withMarshaller(new APostOperationRequestMarshaller(protocolFactory)));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : StreamingInputOperationResponse(software.amazon.awssdk.services.xml.model.StreamingInputOperationResponse) GetOperationWithChecksumResponse(software.amazon.awssdk.services.xml.model.GetOperationWithChecksumResponse) StreamingOutputOperationResponse(software.amazon.awssdk.services.xml.model.StreamingOutputOperationResponse) PutOperationWithChecksumResponse(software.amazon.awssdk.services.xml.model.PutOperationWithChecksumResponse) Response(software.amazon.awssdk.core.Response) APostOperationWithOutputResponse(software.amazon.awssdk.services.xml.model.APostOperationWithOutputResponse) APostOperationResponse(software.amazon.awssdk.services.xml.model.APostOperationResponse) OperationWithChecksumRequiredResponse(software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredResponse) APostOperationResponse(software.amazon.awssdk.services.xml.model.APostOperationResponse) APostOperationRequest(software.amazon.awssdk.services.xml.model.APostOperationRequest) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) APostOperationRequestMarshaller(software.amazon.awssdk.services.xml.transform.APostOperationRequestMarshaller) XmlOperationMetadata(software.amazon.awssdk.protocols.xml.XmlOperationMetadata)

Aggregations

Response (software.amazon.awssdk.core.Response)19 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)14 MetricPublisher (software.amazon.awssdk.metrics.MetricPublisher)12 NoOpMetricCollector (software.amazon.awssdk.metrics.NoOpMetricCollector)12 XmlOperationMetadata (software.amazon.awssdk.protocols.xml.XmlOperationMetadata)12 APostOperationResponse (software.amazon.awssdk.services.xml.model.APostOperationResponse)12 APostOperationWithOutputResponse (software.amazon.awssdk.services.xml.model.APostOperationWithOutputResponse)12 GetOperationWithChecksumResponse (software.amazon.awssdk.services.xml.model.GetOperationWithChecksumResponse)12 OperationWithChecksumRequiredResponse (software.amazon.awssdk.services.xml.model.OperationWithChecksumRequiredResponse)12 PutOperationWithChecksumResponse (software.amazon.awssdk.services.xml.model.PutOperationWithChecksumResponse)12 StreamingInputOperationResponse (software.amazon.awssdk.services.xml.model.StreamingInputOperationResponse)12 StreamingOutputOperationResponse (software.amazon.awssdk.services.xml.model.StreamingOutputOperationResponse)12 CompletableFuture (java.util.concurrent.CompletableFuture)8 Collections (java.util.Collections)7 List (java.util.List)7 Executor (java.util.concurrent.Executor)7 Consumer (java.util.function.Consumer)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 Generated (software.amazon.awssdk.annotations.Generated)7