com.amazonaws.http.HttpResponse.setStatusCode()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中com.amazonaws.http.HttpResponse.setStatusCode()方法的一些代码示例,展示了HttpResponse.setStatusCode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.setStatusCode()方法的具体详情如下:
包路径:com.amazonaws.http.HttpResponse
类名称:HttpResponse
方法名:setStatusCode

HttpResponse.setStatusCode介绍

[英]Sets the HTTP status code that was returned with this response.
[中]设置此响应返回的HTTP状态代码。

代码示例

代码示例来源:origin: aws/aws-sdk-java

/**
 * Creates and initializes an HttpResponse object suitable to be passed to an HTTP response
 * handler object.
 *
 * @param request Marshalled request object.
 * @param method  The HTTP method that was invoked to get the response.
 * @param context The HTTP context associated with the request and response.
 * @return The new, initialized HttpResponse object ready to be passed to an HTTP response
 * handler object.
 * @throws IOException If there were any problems getting any response information from the
 *                     HttpClient method object.
 */
public static HttpResponse createResponse(Request<?> request,
                  HttpRequestBase method,
                  org.apache.http.HttpResponse apacheHttpResponse,
                  HttpContext context) throws IOException {
  HttpResponse httpResponse = new HttpResponse(request, method, context);
  if (apacheHttpResponse.getEntity() != null) {
    httpResponse.setContent(apacheHttpResponse.getEntity().getContent());
  }
  httpResponse.setStatusCode(apacheHttpResponse.getStatusLine().getStatusCode());
  httpResponse.setStatusText(apacheHttpResponse.getStatusLine().getReasonPhrase());
  for (Header header : apacheHttpResponse.getAllHeaders()) {
    httpResponse.addHeader(header.getName(), header.getValue());
  }
  return httpResponse;
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Dump the Netty {@link HttpResponse} to the SDK {@link com.amazonaws.http.HttpResponse} container.
 *
 * @param resp Response to adapt.
 */
private void dumpToSdkHttpResponse(HttpResponse resp) {
  errorResponse.setStatusCode(resp.status().code());
  errorResponse.setStatusText(resp.status().reasonPhrase());
  for (Map.Entry<String, String> header : resp.headers().entries()) {
    errorResponse.addHeader(header.getKey(), header.getValue());
  }
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

/**
 * Creates and initializes an HttpResponse object suitable to be passed to an HTTP response
 * handler object.
 *
 * @param request Marshalled request object.
 * @param method  The HTTP method that was invoked to get the response.
 * @param context The HTTP context associated with the request and response.
 * @return The new, initialized HttpResponse object ready to be passed to an HTTP response
 * handler object.
 * @throws IOException If there were any problems getting any response information from the
 *                     HttpClient method object.
 */
public static HttpResponse createResponse(Request<?> request,
                  HttpRequestBase method,
                  org.apache.http.HttpResponse apacheHttpResponse,
                  HttpContext context) throws IOException {
  HttpResponse httpResponse = new HttpResponse(request, method, context);
  if (apacheHttpResponse.getEntity() != null) {
    httpResponse.setContent(apacheHttpResponse.getEntity().getContent());
  }
  httpResponse.setStatusCode(apacheHttpResponse.getStatusLine().getStatusCode());
  httpResponse.setStatusText(apacheHttpResponse.getStatusLine().getReasonPhrase());
  for (Header header : apacheHttpResponse.getAllHeaders()) {
    httpResponse.addHeader(header.getName(), header.getValue());
  }
  return httpResponse;
}

代码示例来源:origin: Nextdoor/bender

/**
 * Creates and initializes an HttpResponse object suitable to be passed to an HTTP response
 * handler object.
 *
 * @param method  The HTTP method that was invoked to get the response.
 * @param context The HTTP context associated with the request and response.
 * @return The new, initialized HttpResponse object ready to be passed to an HTTP response
 * handler object.
 * @throws IOException If there were any problems getting any response information from the
 *                     HttpClient method object.
 */
private HttpResponse createResponse(HttpRequestBase method,
                  org.apache.http.HttpResponse apacheHttpResponse,
                  HttpContext context) throws IOException {
  HttpResponse httpResponse = new HttpResponse(request, method, context);
  if (apacheHttpResponse.getEntity() != null) {
    httpResponse.setContent(apacheHttpResponse.getEntity().getContent());
  }
  httpResponse.setStatusCode(apacheHttpResponse.getStatusLine().getStatusCode());
  httpResponse.setStatusText(apacheHttpResponse.getStatusLine().getReasonPhrase());
  for (Header header : apacheHttpResponse.getAllHeaders()) {
    httpResponse.addHeader(header.getName(), header.getValue());
  }
  return httpResponse;
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-kinesisvideo

/**
 * Dump the Netty {@link HttpResponse} to the SDK {@link com.amazonaws.http.HttpResponse} container.
 *
 * @param resp Response to adapt.
 */
private void dumpToSdkHttpResponse(HttpResponse resp) {
  errorResponse.setStatusCode(resp.status().code());
  errorResponse.setStatusText(resp.status().reasonPhrase());
  for (Map.Entry<String, String> header : resp.headers().entries()) {
    errorResponse.addHeader(header.getKey(), header.getValue());
  }
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-kinesis

@Override
public DescribeStreamResult describeStream(String streamName, String exclusiveStartShardId) {
 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;
}

代码示例来源:origin: Netflix/spectator

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);
}

相关文章