Java Code Examples for com.amazonaws.Response#getAwsResponse()

The following examples show how to use com.amazonaws.Response#getAwsResponse() . 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: GettingStartedIntegrationTest.java    From getting-started with MIT License 6 votes vote down vote up
@Test
void testGetTestCustomersInfoAPI() {
  JSONArray expectedTestCustomersResponse = TestUtil.parseJSONFileFromResourceToJSONArray(
      "GetTestCustomers.json");
  Response<JSONArray> actualTestCustomersResponse = GettingStarted.getTestCustomers();

  assertThat(actualTestCustomersResponse.getHttpResponse().getStatusCode())
      .as("Test if status code is 200/OK").isEqualTo(200);

  JSONArray actualTestCustomersJSONResponse = actualTestCustomersResponse.getAwsResponse();

  assertThat(actualTestCustomersJSONResponse.length())
      .as("Check if objects have same amount of fields")
      .isEqualTo(expectedTestCustomersResponse.length());
  JSONAssert.assertEquals(expectedTestCustomersResponse, actualTestCustomersJSONResponse , false);
}
 
Example 2
Source File: GettingStartedIntegrationTest.java    From getting-started with MIT License 6 votes vote down vote up
@Test
void testGetCurrencyConversion() {
  Response<JSONObject> response = GettingStarted.getCurrencyConversion("NOK", "EUR");

  assertThat(response.getHttpResponse().getStatusCode())
      .as("Test if status code is 200/OK").isEqualTo(200);

  JSONObject json = response.getAwsResponse();

  assertThat(json.length()).as("Check that object contains correct amount of parameters").isEqualTo(12);

  Set<String> keySet;
  keySet = json.keySet();
  assertThat(keySet.contains("quoteCurrency")).as("That object contains quoteCurrency").isTrue();
  assertThat(keySet.contains("country")).as("That object contains country").isTrue();
  assertThat(keySet.contains("amount")).as("That object contains amount").isTrue();
  assertThat(keySet.contains("buyRateTransfer")).as("That object contains buyRateTransfer").isTrue();
  assertThat(keySet.contains("midRate")).as("That object contains midRate").isTrue();
  assertThat(keySet.contains("sellRateTransfer")).as("That object contains sellRateTransfer").isTrue();
  assertThat(keySet.contains("sellRateCash")).as("That object contains sellRateCash").isTrue();
  assertThat(keySet.contains("changeInMidRate")).as("That object contains changeInMidRate").isTrue();
  assertThat(keySet.contains("buyRateCash")).as("That object contains buyRateCash").isTrue();
  assertThat(keySet.contains("updatedDate")).as("That object contains updatedDate").isTrue();
  assertThat(keySet.contains("previousMidRate")).as("That object contains previousMidRate").isTrue();
  assertThat(keySet.contains("baseCurrency")).as("That object contains baseCurrency").isTrue();
}
 
Example 3
Source File: TracingRequestHandler.java    From zipkin-aws with Apache License 2.0 6 votes vote down vote up
static void tagSpanWithRequestId(Span span, Response response) {
  String requestId = null;
  if (response != null) {
    if (response.getAwsResponse() instanceof AmazonWebServiceResult<?>) {
      ResponseMetadata metadata =
          ((AmazonWebServiceResult<?>) response.getAwsResponse()).getSdkResponseMetadata();
      if (null != metadata) {
        requestId = metadata.getRequestId();
      }
    } else if (response.getHttpResponse() != null) {
      if (response.getHttpResponse().getHeader("x-amz-request-id") != null) {
        requestId = response.getHttpResponse().getHeader("x-amz-request-id");
      }
    }
  }
  if (requestId != null) {
    span.tag("aws.request_id", requestId);
  }
}
 
Example 4
Source File: GettingStartedIntegrationTest.java    From getting-started with MIT License 5 votes vote down vote up
@Test
void testGetCurrencyConversions() {
  Response<JSONArray> actualCardDetailsResponse = GettingStarted.getCurrencyConversions("NOK");

  assertThat(actualCardDetailsResponse.getHttpResponse().getStatusCode())
      .as("Test if status code is 200/OK").isEqualTo(200);

  JSONArray actualCardDetailsJSONResponse = actualCardDetailsResponse.getAwsResponse();

  assertThat(actualCardDetailsJSONResponse.length())
      .as("Expecting 46 different currencies")
      .isEqualTo(46);

  JSONObject jsonObject;
  Set<String> keySet;
  for (int i = 0 ; i < actualCardDetailsJSONResponse.length() ; i++) {
    jsonObject = actualCardDetailsJSONResponse.getJSONObject(i);
    keySet = jsonObject.keySet();
    assertThat(keySet.size()).as("Check that object contains correct amount of parameters").isEqualTo(12);
    assertThat(keySet.contains("quoteCurrency")).as("That object contains quoteCurrency").isTrue();
    assertThat(keySet.contains("country")).as("That object contains country").isTrue();
    assertThat(keySet.contains("amount")).as("That object contains amount").isTrue();
    assertThat(keySet.contains("buyRateTransfer")).as("That object contains buyRateTransfer").isTrue();
    assertThat(keySet.contains("midRate")).as("That object contains midRate").isTrue();
    assertThat(keySet.contains("sellRateTransfer")).as("That object contains sellRateTransfer").isTrue();
    assertThat(keySet.contains("sellRateCash")).as("That object contains sellRateCash").isTrue();
    assertThat(keySet.contains("changeInMidRate")).as("That object contains changeInMidRate").isTrue();
    assertThat(keySet.contains("buyRateCash")).as("That object contains buyRateCash").isTrue();
    assertThat(keySet.contains("updatedDate")).as("That object contains updatedDate").isTrue();
    assertThat(keySet.contains("previousMidRate")).as("That object contains previousMidRate").isTrue();
    assertThat(keySet.contains("baseCurrency")).as("That object contains baseCurrency").isTrue();
  }
}
 
Example 5
Source File: TracingHandler.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
private void populateAndEndSubsegment(Subsegment currentSubsegment, Request<?> request, Response<?> response) {
    if (null != response) {
        String requestId = null;
        if (response.getAwsResponse() instanceof AmazonWebServiceResult<?>) {
            // Not all services return responses extending AmazonWebServiceResult (e.g. S3)
            ResponseMetadata metadata = ((AmazonWebServiceResult<?>) response.getAwsResponse()).getSdkResponseMetadata();
            if (null != metadata) {
                requestId = metadata.getRequestId();
                if (null != requestId) {
                    currentSubsegment.putAws(REQUEST_ID_SUBSEGMENT_KEY, requestId);
                }
            }
        } else if (null != response.getHttpResponse()) { // S3 does not follow request id header convention
            if (null != response.getHttpResponse().getHeader(S3_REQUEST_ID_HEADER_KEY)) {
                currentSubsegment.putAws(REQUEST_ID_SUBSEGMENT_KEY,
                                         response.getHttpResponse().getHeader(S3_REQUEST_ID_HEADER_KEY));
            }
            if (null != response.getHttpResponse().getHeader(EntityHeaderKeys.AWS.EXTENDED_REQUEST_ID_HEADER)) {
                currentSubsegment.putAws(EntityDataKeys.AWS.EXTENDED_REQUEST_ID_KEY,
                                         response.getHttpResponse().getHeader(
                                             EntityHeaderKeys.AWS.EXTENDED_REQUEST_ID_HEADER));
            }
        }
        currentSubsegment.putAllAws(extractResponseParameters(request, response.getAwsResponse()));
        currentSubsegment.putAllHttp(extractHttpResponseInformation(response.getHttpResponse()));
    }

    finalizeSubsegment(request);
}
 
Example 6
Source File: FaultInjectionRequestHandler.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void afterResponse(Request<?> request, Response<?> response) {
    /*
     * The following is a hit and miss for multi-threaded clients as the
     * cache size is only 50 entries
     */
    String awsRequestId = dynamoDBClient.getCachedResponseMetadata(request.getOriginalRequest()).getRequestId();
    logger.info("AWS RequestID: " + awsRequestId);

    /*
     * Here you could inspect and alter the response object to see how your
     * application behaves for specific data
     */
    if (request.getOriginalRequest() instanceof GetItemRequest) {
        GetItemResult result = (GetItemResult) response.getAwsResponse();

        Map<String, AttributeValue> item = result.getItem();

        if (item.get("name").getS().equals("Airplane")) {

            // Alter the item
            item.put("name", new AttributeValue("newAirplane"));
            item.put("new attr", new AttributeValue("new attr"));

            // Add some delay
            try {
                Thread.sleep(500);
            }
            catch (InterruptedException ie) {
                logger.info(ie);
                throw new RuntimeException(ie);
            }
        }
    }
}
 
Example 7
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 8
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 9
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 10
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 11
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 12
Source File: FaultInjectionRequestHandler.java    From aws-dynamodb-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void afterResponse(Request<?> request, Response<?> response)
{
    /*
     * The following is a hit and miss for multi-threaded clients as the
     * cache size is only 50 entries
     */
    String awsRequestId = dynamoDBClient.getCachedResponseMetadata(request.getOriginalRequest()).getRequestId();
    logger.info("AWS RequestID: " + awsRequestId);

    /*
     * Here you could inspect and alter the response object to see how your
     * application behaves for specific data
     */
    if (request.getOriginalRequest() instanceof GetItemRequest)
    {
        GetItemResult result = (GetItemResult) response.getAwsResponse();

        Map<String, AttributeValue> item = result.getItem();

        if (item.get("name").getS().equals("Airplane"))
        {

            // Alter the item
            item.put("name", new AttributeValue("newAirplane"));
            item.put("new attr", new AttributeValue("new attr"));

            // Add some delay
            try
            {
                Thread.sleep(500);
            }
            catch (InterruptedException ie)
            {
                logger.info(ie);
                throw new RuntimeException(ie);
            }
        }
    }
}