Java Code Examples for com.amazonaws.http.HttpResponse#setStatusCode()

The following examples show how to use com.amazonaws.http.HttpResponse#setStatusCode() . 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: 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 2
Source File: AmazonKinesisMock.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public DescribeStreamResult describeStream(String streamName, String exclusiveStartShardId) {
  if (rateLimitDescribeStream-- > 0) {
    throw new LimitExceededException("DescribeStream rate limit exceeded");
  }
  int nextShardId = 0;
  if (exclusiveStartShardId != null) {
    nextShardId = parseInt(exclusiveStartShardId) + 1;
  }
  boolean hasMoreShards = nextShardId + 1 < shardedData.size();

  List<Shard> shards = new ArrayList<>();
  if (nextShardId < shardedData.size()) {
    shards.add(new Shard().withShardId(Integer.toString(nextShardId)));
  }

  HttpResponse response = new HttpResponse(null, null);
  response.setStatusCode(200);
  DescribeStreamResult result = new DescribeStreamResult();
  result.setSdkHttpMetadata(SdkHttpMetadata.from(response));
  result.withStreamDescription(
      new StreamDescription()
          .withHasMoreShards(hasMoreShards)
          .withShards(shards)
          .withStreamName(streamName));
  return result;
}
 
Example 3
Source File: AwsCoders.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public SdkHttpMetadata decode(InputStream inStream) throws CoderException, IOException {
  final int httpStatusCode = STATUS_CODE_CODER.decode(inStream);
  HttpResponse httpResponse = new HttpResponse(null, null);
  httpResponse.setStatusCode(httpStatusCode);
  if (includeHeaders) {
    Optional.ofNullable(HEADERS_ENCODER.decode(inStream))
        .ifPresent(
            headers ->
                headers.keySet().forEach(k -> httpResponse.addHeader(k, headers.get(k))));
  }
  return SdkHttpMetadata.from(httpResponse);
}
 
Example 4
Source File: PublishResultCodersTest.java    From beam with Apache License 2.0 5 votes vote down vote up
private PublishResult buildFullPublishResult() {
  PublishResult publishResult = new PublishResult().withMessageId(UUID.randomUUID().toString());
  publishResult.setSdkResponseMetadata(
      new ResponseMetadata(
          ImmutableMap.of(ResponseMetadata.AWS_REQUEST_ID, UUID.randomUUID().toString())));
  HttpResponse httpResponse = new HttpResponse(null, null);
  httpResponse.setStatusCode(200);
  httpResponse.addHeader("Content-Type", "application/json");
  publishResult.setSdkHttpMetadata(SdkHttpMetadata.from(httpResponse));
  return publishResult;
}
 
Example 5
Source File: AwsCodersTest.java    From beam with Apache License 2.0 4 votes vote down vote up
private SdkHttpMetadata buildSdkHttpMetadata() {
  HttpResponse httpResponse = new HttpResponse(null, null);
  httpResponse.setStatusCode(200);
  httpResponse.addHeader("Content-Type", "application/json");
  return SdkHttpMetadata.from(httpResponse);
}