com.amazonaws.Request Java Examples

The following examples show how to use com.amazonaws.Request. 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: AbstractSdkMetricsCollector.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public final void collectMetrics(Request<?> request, Response<?> response)
{
    TimingInfo timingInfo = request.getAWSRequestMetrics().getTimingInfo();

    Number requestCounts = timingInfo.getCounter(RequestCount.name());
    if (requestCounts != null) {
        recordRequestCount(requestCounts.longValue());
    }

    Number retryCounts = timingInfo.getCounter(HttpClientRetryCount.name());
    if (retryCounts != null) {
        recordRetryCount(retryCounts.longValue());
    }

    Number throttleExceptions = timingInfo.getCounter(ThrottleException.name());
    if (throttleExceptions != null) {
        recordThrottleExceptionCount(throttleExceptions.longValue());
    }

    recordSubTimingDurations(timingInfo, HttpRequestTime, this::recordHttpRequestTime);
    recordSubTimingDurations(timingInfo, ClientExecuteTime, this::recordClientExecutionTime);
    recordSubTimingDurations(timingInfo, RetryPauseTime, this::recordRetryPauseTime);
}
 
Example #2
Source File: GetApplicationRequestProtocolMarshaller.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
public Request<GetApplicationRequest> marshall(GetApplicationRequest getApplicationRequest) {

        if (getApplicationRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<GetApplicationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    getApplicationRequest);

            protocolMarshaller.startMarshalling();
            GetApplicationRequestMarshaller.getInstance().marshall(getApplicationRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
 
Example #3
Source File: UpdateApplicationRequestProtocolMarshaller.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
public Request<UpdateApplicationRequest> marshall(UpdateApplicationRequest updateApplicationRequest) {

        if (updateApplicationRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<UpdateApplicationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    updateApplicationRequest);

            protocolMarshaller.startMarshalling();
            UpdateApplicationRequestMarshaller.getInstance().marshall(updateApplicationRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
 
Example #4
Source File: DeleteApplicationRequestProtocolMarshaller.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
public Request<DeleteApplicationRequest> marshall(DeleteApplicationRequest deleteApplicationRequest) {

        if (deleteApplicationRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<DeleteApplicationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    deleteApplicationRequest);

            protocolMarshaller.startMarshalling();
            DeleteApplicationRequestMarshaller.getInstance().marshall(deleteApplicationRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
 
Example #5
Source File: DeleteApplicationRequestProtocolMarshaller.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
public Request<DeleteApplicationRequest> marshall(DeleteApplicationRequest deleteApplicationRequest) {

    if (deleteApplicationRequest == null) {
      throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
      final ProtocolRequestMarshaller<DeleteApplicationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
              deleteApplicationRequest);

      protocolMarshaller.startMarshalling();
      DeleteApplicationRequestMarshaller.getInstance().marshall(deleteApplicationRequest, protocolMarshaller);
      return protocolMarshaller.finishMarshalling();
    } catch (Exception e) {
      throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
  }
 
Example #6
Source File: CreateApplicationRequestProtocolMarshaller.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
public Request<CreateApplicationRequest> marshall(CreateApplicationRequest createApplicationRequest) {

        if (createApplicationRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<CreateApplicationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    createApplicationRequest);

            protocolMarshaller.startMarshalling();
            CreateApplicationRequestMarshaller.getInstance().marshall(createApplicationRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
 
Example #7
Source File: ListApplicationsRequestProtocolMarshaller.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
public Request<ListApplicationsRequest> marshall(ListApplicationsRequest listApplicationsRequest) {

    if (listApplicationsRequest == null) {
      throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
      final ProtocolRequestMarshaller<ListApplicationsRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
              listApplicationsRequest);

      protocolMarshaller.startMarshalling();
      ListApplicationsRequestMarshaller.getInstance().marshall(listApplicationsRequest, protocolMarshaller);
      return protocolMarshaller.finishMarshalling();
    } catch (Exception e) {
      throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
  }
 
Example #8
Source File: UpdateApplicationRequestProtocolMarshaller.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
public Request<UpdateApplicationRequest> marshall(UpdateApplicationRequest updateApplicationRequest) {

    if (updateApplicationRequest == null) {
      throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
      final ProtocolRequestMarshaller<UpdateApplicationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
              updateApplicationRequest);

      protocolMarshaller.startMarshalling();
      UpdateApplicationRequestMarshaller.getInstance().marshall(updateApplicationRequest, protocolMarshaller);
      return protocolMarshaller.finishMarshalling();
    } catch (Exception e) {
      throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
  }
 
Example #9
Source File: CreateApplicationRequestProtocolMarshaller.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
public Request<CreateApplicationRequest> marshall(CreateApplicationRequest createApplicationRequest) {

    if (createApplicationRequest == null) {
      throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
      final ProtocolRequestMarshaller<CreateApplicationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
              createApplicationRequest);

      protocolMarshaller.startMarshalling();
      CreateApplicationRequestMarshaller.getInstance().marshall(createApplicationRequest, protocolMarshaller);
      return protocolMarshaller.finishMarshalling();
    } catch (Exception e) {
      throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
  }
 
Example #10
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 #11
Source File: TracingHandler.java    From aws-xray-sdk-java with Apache License 2.0 6 votes vote down vote up
private void populateAndEndSubsegment(
    Subsegment currentSubsegment, Request<?> request, Response<?> response, AmazonServiceException ase) {
    if (null != response) {
        populateAndEndSubsegment(currentSubsegment, request, response);
        return;
    } else if (null != ase) {
        if (null != ase.getRequestId()) {
            currentSubsegment.putAws(REQUEST_ID_SUBSEGMENT_KEY, ase.getRequestId());
        }
        if (null != ase.getHttpHeaders() &&
            null != ase.getHttpHeaders().get(EntityHeaderKeys.AWS.EXTENDED_REQUEST_ID_HEADER)) {
            currentSubsegment.putAws(EntityDataKeys.AWS.EXTENDED_REQUEST_ID_KEY,
                                     ase.getHttpHeaders().get(EntityHeaderKeys.AWS.EXTENDED_REQUEST_ID_HEADER));
        }
        if (null != ase.getErrorMessage()) {
            currentSubsegment.getCause().setMessage(ase.getErrorMessage());
        }
        currentSubsegment.putAllHttp(extractHttpResponseInformation(ase));
    }

    finalizeSubsegment(request);
}
 
Example #12
Source File: GetApplicationRequestProtocolMarshaller.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
public Request<GetApplicationRequest> marshall(GetApplicationRequest getApplicationRequest) {

    if (getApplicationRequest == null) {
      throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
      final ProtocolRequestMarshaller<GetApplicationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
              getApplicationRequest);

      protocolMarshaller.startMarshalling();
      GetApplicationRequestMarshaller.getInstance().marshall(getApplicationRequest, protocolMarshaller);
      return protocolMarshaller.finishMarshalling();
    } catch (Exception e) {
      throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
  }
 
Example #13
Source File: SpectatorRequestMetricCollectorTest.java    From spectator with Apache License 2.0 6 votes vote down vote up
private void execRequest(String endpoint, int status) {
  AWSRequestMetrics metrics = new AWSRequestMetricsFullSupport();
  metrics.addProperty(AWSRequestMetrics.Field.ServiceName, "AmazonCloudWatch");
  metrics.addProperty(AWSRequestMetrics.Field.ServiceEndpoint, endpoint);
  metrics.addProperty(AWSRequestMetrics.Field.StatusCode, "" + status);
  if (status == 503) {
    metrics.addProperty(AWSRequestMetrics.Field.AWSErrorCode, "Throttled");
  }
  String counterName = "BytesProcessed";
  String timerName = "ClientExecuteTime";
  metrics.setCounter(counterName, 12345);
  metrics.getTimingInfo().addSubMeasurement(timerName, TimingInfo.unmodifiableTimingInfo(100000L, 200000L));

  Request<?> req = new DefaultRequest(new ListMetricsRequest(), "AmazonCloudWatch");
  req.setAWSRequestMetrics(metrics);
  req.setEndpoint(URI.create(endpoint));

  HttpResponse hr = new HttpResponse(req, new HttpPost(endpoint));
  hr.setStatusCode(status);
  Response<?> resp = new Response<>(null, new HttpResponse(req, new HttpPost(endpoint)));

  collector.collectMetrics(req, resp);
}
 
Example #14
Source File: ListApplicationsRequestProtocolMarshaller.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
public Request<ListApplicationsRequest> marshall(ListApplicationsRequest listApplicationsRequest) {

        if (listApplicationsRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<ListApplicationsRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    listApplicationsRequest);

            protocolMarshaller.startMarshalling();
            ListApplicationsRequestMarshaller.getInstance().marshall(listApplicationsRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
 
Example #15
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 #16
Source File: CreateSpeechGetRequestMarshaller.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
public Request<CreateSpeechRequest> marshall(CreateSpeechRequest createSpeechRequest) {
    if (createSpeechRequest == null) {
        throw new AmazonClientException("null createSpeechRequest passed to marshall(...)");
    }

    Request<CreateSpeechRequest> request = new DefaultRequest<CreateSpeechRequest>(createSpeechRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    setRequestParameters(request, createSpeechRequest);
    request.setHttpMethod(HttpMethodName.GET);
    request.setResourcePath(RESOURCE_PATH);

    return request;
}
 
Example #17
Source File: PutLexiconPostRequestMarshaller.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
public Request<PutLexiconRequest> marshall(PutLexiconRequest putLexiconRequest) {
    if (putLexiconRequest == null) {
        throw new AmazonClientException("null putLexiconRequest passed to marshall(...)");
    }

    Request<PutLexiconRequest> request = new DefaultRequest<PutLexiconRequest>(putLexiconRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    request.setHttpMethod(HttpMethodName.POST);
    setRequestPayload(request, putLexiconRequest);
    request.setResourcePath(RESOURCE_PATH);

    return request;
}
 
Example #18
Source File: ListVoicesGetRequestMarshaller.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
protected void setRequestParameters(Request<ListVoicesRequest> request, ListVoicesRequest listVoicesRequest) {
    Map<String, List<String>> parameters = new HashMap<String, List<String>>();

    if (listVoicesRequest.getVoice() != null) {
        MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_NAME,
                listVoicesRequest.getVoice().getName());
        MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_LANGUAGE,
                listVoicesRequest.getVoice().getLanguage());
        MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_GENDER,
                listVoicesRequest.getVoice().getGender());
    }

    request.setParameters(parameters);
}
 
Example #19
Source File: ListVoicesGetRequestMarshaller.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
public Request<ListVoicesRequest> marshall(ListVoicesRequest listVoicesRequest) {

        if (listVoicesRequest == null) {
            throw new AmazonClientException("null listVoicesRequest passed to marshall(...)");
        }

        Request<ListVoicesRequest> request = new DefaultRequest<ListVoicesRequest>(listVoicesRequest,
                IvonaSpeechCloudClient.SERVICE_NAME);
        request.setHttpMethod(HttpMethodName.GET);
        request.setResourcePath(RESOURCE_PATH);

        setRequestParameters(request, listVoicesRequest);

        return request;
    }
 
Example #20
Source File: DeleteLexiconPostRequestMarshaller.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
public Request<DeleteLexiconRequest> marshall(DeleteLexiconRequest deleteLexiconRequest) {
    if (deleteLexiconRequest == null) {
        throw new AmazonClientException("null deleteLexiconRequest passed to marshall(...)");
    }

    Request<DeleteLexiconRequest> request = new DefaultRequest<DeleteLexiconRequest>(deleteLexiconRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    request.setHttpMethod(HttpMethodName.POST);
    setRequestPayload(request, deleteLexiconRequest);
    request.setResourcePath(RESOURCE_PATH);

    return request;
}
 
Example #21
Source File: ListVoicesPostRequestMarshaller.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
public Request<ListVoicesRequest> marshall(ListVoicesRequest listVoicesRequest) {

        if (listVoicesRequest == null) {
            throw new AmazonClientException("null listVoicesRequest passed to marshall(...)");
        }

        Request<ListVoicesRequest> request = new DefaultRequest<ListVoicesRequest>(listVoicesRequest,
                IvonaSpeechCloudClient.SERVICE_NAME);
        request.setHttpMethod(HttpMethodName.POST);
        request.setResourcePath(RESOURCE_PATH);
        setRequestPayload(request, listVoicesRequest);
        return request;
    }
 
Example #22
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 #23
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 #24
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public URL getListVoicesUrl(ListVoicesRequest listVoicesRequest) throws UnsupportedEncodingException {
    listVoicesRequest.setMethodType(MethodType.GET);
    Request<ListVoicesRequest> request = ListVoicesRequestMarshallerFactory.getMarshaller(
            listVoicesRequest.getMethodType()).marshall(listVoicesRequest);
    return ServiceUtils.convertRequestToUrl(prepareRequestForGetUrl(request));
}
 
Example #25
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public URL getCreateSpeechUrl(CreateSpeechRequest createSpeechRequest) throws UnsupportedEncodingException {
    createSpeechRequest.setMethodType(MethodType.GET);
    Request<CreateSpeechRequest> request = CreateSpeechRequestMarshallerFactory.getMarshaller(
            createSpeechRequest.getMethodType()).marshall(createSpeechRequest);
    return ServiceUtils.convertRequestToUrl(prepareRequestForGetUrl(request));
}
 
Example #26
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 #27
Source File: SpectatorRequestMetricCollector.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Override
public void collectMetrics(Request<?> request, Response<?> response) {
  final AWSRequestMetrics metrics = request.getAWSRequestMetrics();
  if (metrics.isEnabled()) {
    final Map<String, String> allTags = getAllTags(request);
    final TimingInfo timing = metrics.getTimingInfo();

    for (Field counter : COUNTERS) {
      Optional.ofNullable(timing.getCounter(counter.name()))
          .filter(v -> v.longValue() > 0)
          .ifPresent(v -> registry.counter(metricId(counter, allTags)).increment(v.longValue()));
    }

    for (Field timer : TIMERS) {
      Optional.ofNullable(timing.getLastSubMeasurement(timer.name()))
          .filter(TimingInfo::isEndTimeKnown)
          .ifPresent(t -> registry.timer(metricId(timer, allTags))
              .record(t.getEndTimeNano() - t.getStartTimeNano(), TimeUnit.NANOSECONDS));
    }

    notEmpty(metrics.getProperty(Field.ThrottleException)).ifPresent(throttleExceptions -> {
      final Id throttling = metricId("throttling", allTags);
      throttleExceptions.forEach(ex ->
          registry.counter(throttling.withTag(TAG_THROTTLE_EXCEPTION,
                  ex.getClass().getSimpleName())).increment());
    });
  }
}
 
Example #28
Source File: SignedRequestTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * SignedRequest can perform the original {@link AwsHttpRequest}
 */
@Test
public void performsRequest() {
    AwsHttpRequest<String> signed = new SignedRequest<>(
        new AwsHttpRequest.FakeAwsHttpRequest(),
        new AccessKeyId.Fake("access_key"),
        new SecretKey.Fake("secret"),
        new Region.Fake("ro")
    );
    MatcherAssert.assertThat(
        signed.perform(),
        Matchers.equalTo("performed fake request")
    );
    signed.perform();
    signed.perform();
    Request<Void> req = signed.request();
    MatcherAssert.assertThat(
        req.getHeaders().get("X-Amz-Date"),
        Matchers.notNullValue()
    );
    MatcherAssert.assertThat(
        req.getHeaders().get("Authorization"),
        Matchers.containsString("Signature")
    );
    MatcherAssert.assertThat(
        req.getHeaders().get("Host"),
        Matchers.notNullValue()
    );
}
 
Example #29
Source File: KMSProviderBuilderIntegrationTests.java    From aws-encryption-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void whenUserAgentsOverridden_originalUAsPreserved() throws Exception {
    RequestHandler2 handler = spy(new RequestHandler2() {});

    KmsMasterKeyProvider mkp = KmsMasterKeyProvider.builder()
                                                   .withClientBuilder(
                                                           AWSKMSClientBuilder.standard().withRequestHandlers(handler)
                                                           .withClientConfiguration(
                                                                   new ClientConfiguration()
                                                                       .withUserAgentPrefix("TEST-UA-PREFIX")
                                                                       .withUserAgentSuffix("TEST-UA-SUFFIX")
                                                           )
                                                   )
                                                   .withKeysForEncryption(KMSTestFixtures.TEST_KEY_IDS[0])
                                                   .clone().build();

    new AwsCrypto().encryptData(mkp, new byte[0]);

    ArgumentCaptor<Request> captor = ArgumentCaptor.forClass(Request.class);
    verify(handler, atLeastOnce()).beforeRequest(captor.capture());

    String ua = (String)captor.getValue().getHeaders().get("User-Agent");

    assertTrue(ua.contains("TEST-UA-PREFIX"));
    assertTrue(ua.contains("TEST-UA-SUFFIX"));
    assertTrue(ua.contains(VersionInfo.USER_AGENT));
}
 
Example #30
Source File: KmsMasterKeyProvider.java    From aws-encryption-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override public void afterError(final Request<?> request, final Response<?> response, final Exception e) {
    if (ranBefore_) return;
    if (e instanceof AmazonServiceException) {
        ranBefore_ = true;
        cache_.putIfAbsent(region_, client_);
    }
}