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

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

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

HttpResponse.getStatusText介绍

[英]Returns the HTTP status text associated with this response.
[中]返回与此响应关联的HTTP状态文本。

代码示例

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

private AmazonS3Exception createExceptionFromHeaders(
    HttpResponse errorResponse, String errorResponseXml) {
  final Map<String, String> headers = errorResponse.getHeaders();
  final int statusCode = errorResponse.getStatusCode();
  final AmazonS3ExceptionBuilder exceptionBuilder = new AmazonS3ExceptionBuilder();
  exceptionBuilder.setErrorMessage(errorResponse.getStatusText());
  exceptionBuilder.setErrorResponseXml(errorResponseXml);
  exceptionBuilder.setStatusCode(statusCode);
  exceptionBuilder
      .setExtendedRequestId(headers.get(Headers.EXTENDED_REQUEST_ID));
  exceptionBuilder.setRequestId(headers.get(Headers.REQUEST_ID));
  exceptionBuilder.setCloudFrontId(headers.get(Headers.CLOUD_FRONT_ID));
  exceptionBuilder
      .setErrorCode(statusCode + " " + errorResponse.getStatusText());
  exceptionBuilder.addAdditionalDetail(Headers.S3_BUCKET_REGION,
      errorResponse.getHeaders().get(Headers.S3_BUCKET_REGION));
  return exceptionBuilder.build();
}

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

@Override
public AmazonServiceException handle(HttpResponse errorResponse) throws Exception {
  AmazonServiceException ase = createAse(errorResponse);
  if (ase == null) {
    throw new SdkClientException("Unable to unmarshall error response from service");
  }
  ase.setHttpHeaders(errorResponse.getHeaders());
  if (StringUtils.isNullOrEmpty(ase.getErrorCode())) {
    ase.setErrorCode(errorResponse.getStatusCode() + " " + errorResponse.getStatusText());
  }
  return ase;
}

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

@Override
public T handle(HttpResponse response) throws Exception {
  final AmazonWebServiceResponse<T> awsResponse = delegate.handle(response);
  if (awsResponse == null) {
    throw new RuntimeException("Unable to unmarshall response metadata. Response Code: "
                  + response.getStatusCode() + ", Response Text: " +
                  response.getStatusText());
  }
  AmazonWebServiceRequest userRequest = request.getOriginalRequest();
  if (userRequest.getCloneRoot() != null) {
    userRequest = userRequest.getCloneRoot();
  }
  responseMetadataCache.add(userRequest, awsResponse.getResponseMetadata());
  final String awsRequestId = awsResponse.getRequestId();
  if (requestLog.isDebugEnabled()) {
    requestLog
        .debug("Received successful response: " + response.getStatusCode() +
            ", AWS Request ID: " + awsRequestId);
  }
  if (!logHeaderRequestId(response)) {
    // Logs the AWS request ID extracted from the payload if
    // it is not available from the response header.
    logResponseRequestId(awsRequestId);
  }
  awsRequestMetrics.addProperty(AWSRequestMetrics.Field.AWSRequestID, awsRequestId);
  return fillInResponseMetadata(awsResponse, response);
}

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

"Unable to unmarshall response (" + e.getMessage() + "). Response Code: "
    + httpResponse.getStatusCode() + ", Response Text: " +
    httpResponse.getStatusText();
throw new SdkClientException(errorMessage, e);

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

/**
 * Returns the HTTP status text associated with this response.
 *
 * @return The HTTP status text associated with this response.
 */
public String getStatusText() {
  return response.getStatusText();
}

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

private AmazonServiceException handleAse(HttpResponse response) throws Exception {
  final int statusCode = response.getStatusCode();
  try {
    return delegate.handle(response);
  } catch(InterruptedException e) {
    throw e;
  } catch (Exception e) {
    // If the errorResponseHandler doesn't work, then check for error responses that don't have any content
    if (statusCode == 413) {
      AmazonServiceException exception = new AmazonServiceException("Request entity too large");
      exception.setServiceName(response.getRequest().getServiceName());
      exception.setStatusCode(statusCode);
      exception.setErrorType(AmazonServiceException.ErrorType.Client);
      exception.setErrorCode("Request entity too large");
      return exception;
    } else if (statusCode >= 500 && statusCode < 600) {
      AmazonServiceException exception = new AmazonServiceException(response.getStatusText());
      exception.setServiceName(response.getRequest().getServiceName());
      exception.setStatusCode(statusCode);
      exception.setErrorType(AmazonServiceException.ErrorType.Service);
      exception.setErrorCode(response.getStatusText());
      return exception;
    } else {
      throw e;
    }
  }
}

代码示例来源:origin: apache/nifi

statusExplanation = EnglishReasonPhraseCatalog.INSTANCE.getReason(statusCode, null);
} else {
  statusExplanation = response.getHttpResponse().getStatusText();

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

/**
 * Used to create an {@link AmazonS3Exception} when we failed to read the
 * error response or parsed the error response as XML.
 */
private AmazonS3Exception newAmazonS3Exception(String errmsg, HttpResponse httpResponse) {
  final AmazonS3Exception ase = new AmazonS3Exception(errmsg);
  final int statusCode = httpResponse.getStatusCode();
  ase.setErrorCode(statusCode + " " + httpResponse.getStatusText());
  ase.setStatusCode(statusCode);
  ase.setErrorType(errorTypeOf(statusCode));
  final Map<String, String> headers = httpResponse.getHeaders();
  ase.setRequestId(headers.get(Headers.REQUEST_ID));
  ase.setExtendedRequestId(headers.get(Headers.EXTENDED_REQUEST_ID));
  ase.setCloudFrontId(headers.get(Headers.CLOUD_FRONT_ID));
  final Map<String, String> additionalDetails = new HashMap<String, String>();
  additionalDetails.put(Headers.S3_BUCKET_REGION,
      headers.get(Headers.S3_BUCKET_REGION));
  ase.setAdditionalDetails(additionalDetails);
  return ase;
}

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

@Override
public AmazonServiceException handle(HttpResponse errorResponse) throws Exception {
  AmazonServiceException ase = createAse(errorResponse);
  if (ase == null) {
    throw new SdkClientException("Unable to unmarshall error response from service");
  }
  ase.setHttpHeaders(errorResponse.getHeaders());
  if (StringUtils.isNullOrEmpty(ase.getErrorCode())) {
    ase.setErrorCode(errorResponse.getStatusCode() + " " + errorResponse.getStatusText());
  }
  return ase;
}

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

/**
 * Used to create an {@link newAmazonServiceException} when we failed to
 * read the error response or parsed the error response as XML.
 */
private AmazonServiceException newAmazonServiceException(String errmsg,
    HttpResponse httpResponse, Exception readFailure) {
  AmazonServiceException exception = new AmazonServiceException(errmsg, readFailure);
  final int statusCode = httpResponse.getStatusCode();
  exception.setErrorCode(statusCode + " " + httpResponse.getStatusText());
  exception.setErrorType(AmazonServiceException.ErrorType.Unknown);
  exception.setStatusCode(statusCode);
  return exception;
}

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

"Unable to unmarshall response metadata. Response Code: " +
          response.getStatusCode() + ", Response Text: "
          + response.getStatusText());
final String errorMessage = "Unable to unmarshall response (" + e.getMessage()
    + "). Response Code: " +
    response.getStatusCode() + ", Response Text: " + response.getStatusText();
throw new AmazonClientException(errorMessage, e);

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

@Override
public T handle(HttpResponse response) throws Exception {
  final AmazonWebServiceResponse<T> awsResponse = delegate.handle(response);
  if (awsResponse == null) {
    throw new RuntimeException("Unable to unmarshall response metadata. Response Code: "
                  + response.getStatusCode() + ", Response Text: " +
                  response.getStatusText());
  }
  AmazonWebServiceRequest userRequest = request.getOriginalRequest();
  if (userRequest.getCloneRoot() != null) {
    userRequest = userRequest.getCloneRoot();
  }
  responseMetadataCache.add(userRequest, awsResponse.getResponseMetadata());
  final String awsRequestId = awsResponse.getRequestId();
  if (requestLog.isDebugEnabled()) {
    requestLog
        .debug("Received successful response: " + response.getStatusCode() +
            ", AWS Request ID: " + awsRequestId);
  }
  if (!logHeaderRequestId(response)) {
    // Logs the AWS request ID extracted from the payload if
    // it is not available from the response header.
    logResponseRequestId(awsRequestId);
  }
  awsRequestMetrics.addProperty(AWSRequestMetrics.Field.AWSRequestID, awsRequestId);
  return fillInResponseMetadata(awsResponse, response);
}

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

"Unable to unmarshall response (" + e.getMessage() + "). Response Code: "
    + httpResponse.getStatusCode() + ", Response Text: " +
    httpResponse.getStatusText();
throw new SdkClientException(errorMessage, e);

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

@Override
public AmazonServiceException handle(
    com.amazonaws.http.HttpResponse response) throws Exception {
  AmazonServiceException ase = new AmazonServiceException("Fake service exception.");
  ase.setStatusCode(response.getStatusCode());
  ase.setErrorCode(response.getStatusText());
  return ase;
}

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

@Test
public void testCreateResponse() throws URISyntaxException, IOException {
  final HttpRequest request = new HttpRequest("PUT", new URI("https://www.test.com"));
  final MockHttpURLConnection conn = new MockHttpURLConnection(new URL("https://www.test.com"));
  final Map<String, List<String>> headerFields = new HashMap<String, List<String>>();
  final List<String> header1 = new ArrayList<String>();
  header1.add("value1");
  header1.add("ExtraValue");
  headerFields.put("key1", header1);
  final List<String> header2 = new ArrayList<String>();
  header2.add("value2");
  headerFields.put("key2", header2);
  final List<String> nullHeader = new ArrayList<String>();
  headerFields.put(null, nullHeader);
  conn.setHeaderFields(headerFields);
  conn.setResponseCode(200);
  conn.setErrorStream(null);
  final ByteArrayInputStream bais = new ByteArrayInputStream("test".getBytes(StringUtils.UTF8));
  conn.setInputStream(bais);
  conn.setResponseMessage("TestMessage");
  final HttpResponse response = client.createHttpResponse(request, conn);
  assertEquals(response.getHeaders().get("key1"), "value1");
  assertEquals(response.getHeaders().get("key2"), "value2");
  assertEquals(response.getHeaders().size(), 2);
  assertEquals(response.getStatusCode(), 200);
  assertEquals(response.getStatusText(), "TestMessage");
  assertSame(response.getContent(), bais);
}

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

private AmazonServiceException handleAse(HttpResponse response) throws Exception {
  final int statusCode = response.getStatusCode();
  try {
    return delegate.handle(response);
  } catch(InterruptedException e) {
    throw e;
  } catch (Exception e) {
    // If the errorResponseHandler doesn't work, then check for error responses that don't have any content
    if (statusCode == 413) {
      AmazonServiceException exception = new AmazonServiceException("Request entity too large");
      exception.setServiceName(response.getRequest().getServiceName());
      exception.setStatusCode(statusCode);
      exception.setErrorType(AmazonServiceException.ErrorType.Client);
      exception.setErrorCode("Request entity too large");
      return exception;
    } else if (statusCode >= 500 && statusCode < 600) {
      AmazonServiceException exception = new AmazonServiceException(response.getStatusText());
      exception.setServiceName(response.getRequest().getServiceName());
      exception.setStatusCode(statusCode);
      exception.setErrorType(AmazonServiceException.ErrorType.Service);
      exception.setErrorCode(response.getStatusText());
      return exception;
    } else {
      throw e;
    }
  }
}

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

exception.setErrorCode("Request entity too large");
} else if (status == HTTP_STATUS_SERVICE_UNAVAILABLE
    && "Service Unavailable".equalsIgnoreCase(response.getStatusText())) {
  exception = new AmazonServiceException("Service unavailable");
  exception.setServiceName(request.getServiceName());
  final String errorMessage = "Unable to unmarshall error response (" + e.getMessage()
      + "). Response Code: " + status
      + ", Response Text: " + response.getStatusText()
      + ", Response Headers: " + response.getHeaders();
  throw new AmazonClientException(errorMessage, e);

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

return newAmazonS3Exception(errorResponse.getStatusText(), errorResponse);
  log.debug("Failed in reading the error response", ex);
return newAmazonS3Exception(errorResponse.getStatusText(), errorResponse);

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

@Test
public void testBuilder() throws Exception {
  builder = HttpResponse.builder()
      .statusCode(statusCode)
      .statusText(statusText)
      .content(content);
  for (int i = 0; i < 10; i++) {
    builder.header("key" + i, "value" + i);
  }
  response = builder.build();
  assertEquals("status text", statusText, response.getStatusText());
  assertTrue("status code", statusCode == response.getStatusCode());
  assertTrue("has headers", 10 == response.getHeaders().size());
  assertEquals("content", content, response.getContent());
}

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

@Test
public void testDefaultErrorResponseHandlerCannotGetContent() throws Exception {
  List<Unmarshaller<AmazonServiceException, Node>> unmarshallerList = new ArrayList<Unmarshaller<AmazonServiceException, Node>>();
  HttpResponse errorResponse = new HttpResponse.Builder()
      .statusCode(400)
      .statusText("Error")
      .content(new InputStream() {
        @Override
        public int read() throws IOException {
          throw new IOException("Test IOException");
        }
      })
      .build();
  DefaultErrorResponseHandler handler = new DefaultErrorResponseHandler(unmarshallerList);
  AmazonServiceException e = handler.handle(errorResponse);
  assertEquals(e.getErrorCode(),
      errorResponse.getStatusCode() + " " + errorResponse.getStatusText());
  assertEquals(e.getStatusCode(), 400);
  assertEquals(e.getErrorType(), ErrorType.Unknown);
}

相关文章