本文整理汇总了Java中com.amazonaws.AmazonServiceException.ErrorType类的典型用法代码示例。如果您正苦于以下问题:Java ErrorType类的具体用法?Java ErrorType怎么用?Java ErrorType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ErrorType类属于com.amazonaws.AmazonServiceException包,在下文中一共展示了ErrorType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unmarshall
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
/**
* @see com.amazonaws.transform.Unmarshaller#unmarshall(java.lang.Object)
*/
public AmazonServiceException unmarshall(Node in) throws Exception {
XPath xpath = xpath();
String errorCode = parseErrorCode(in, xpath);
String errorType = asString("ErrorResponse/Error/Type", in, xpath);
String requestId = asString("ErrorResponse/RequestId", in, xpath);
String message = asString("ErrorResponse/Error/Message", in, xpath);
AmazonServiceException ase = newException(message);
ase.setErrorCode(errorCode);
ase.setRequestId(requestId);
if (errorType == null) {
ase.setErrorType(ErrorType.Unknown);
} else if (errorType.equalsIgnoreCase("Receiver")) {
ase.setErrorType(ErrorType.Service);
} else if (errorType.equalsIgnoreCase("Sender")) {
ase.setErrorType(ErrorType.Client);
}
return ase;
}
示例2: unmarshall
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
@Override
public AmazonServiceException unmarshall(Node in) throws Exception {
XPath xpath = xpath();
String errorCode = parseErrorCode(in, xpath);
String message = asString("Response/Errors/Error/Message", in, xpath);
String requestId = asString("Response/RequestID", in, xpath);
String errorType = asString("Response/Errors/Error/Type", in, xpath);
Constructor<? extends AmazonServiceException> constructor = exceptionClass.getConstructor(String.class);
AmazonServiceException ase = constructor.newInstance(message);
ase.setErrorCode(errorCode);
ase.setRequestId(requestId);
if (errorType == null) {
ase.setErrorType(ErrorType.Unknown);
} else if (errorType.equalsIgnoreCase("server")) {
ase.setErrorType(ErrorType.Service);
} else if (errorType.equalsIgnoreCase("client")) {
ase.setErrorType(ErrorType.Client);
}
return ase;
}
示例3: handle_NullContent_ReturnsGenericAmazonServiceException
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
@Test
public void handle_NullContent_ReturnsGenericAmazonServiceException() throws Exception {
httpResponse.setStatusCode(500);
httpResponse.setContent(null);
AmazonServiceException ase = responseHandler.handle(httpResponse);
// We assert these common properties are set again to make sure that code path is exercised
// for unknown AmazonServiceExceptions as well
assertEquals(ERROR_CODE, ase.getErrorCode());
assertEquals(500, ase.getStatusCode());
assertEquals(SERVICE_NAME, ase.getServiceName());
assertEquals(ErrorType.Service, ase.getErrorType());
}
示例4: handle_UnmarshallerReturnsException_ClientErrorType
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
@Test
public void handle_UnmarshallerReturnsException_ClientErrorType() throws Exception {
httpResponse.setStatusCode(400);
expectUnmarshallerMatches();
when(unmarshaller.unmarshall((JsonNode) anyObject()))
.thenReturn(new CustomException("error"));
AmazonServiceException ase = responseHandler.handle(httpResponse);
assertEquals(ERROR_CODE, ase.getErrorCode());
assertEquals(400, ase.getStatusCode());
assertEquals(SERVICE_NAME, ase.getServiceName());
assertEquals(ErrorType.Client, ase.getErrorType());
}
示例5: handle_UnmarshallerReturnsException_ServiceErrorType
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
@Test
public void handle_UnmarshallerReturnsException_ServiceErrorType() throws Exception {
httpResponse.setStatusCode(500);
expectUnmarshallerMatches();
when(unmarshaller.unmarshall((JsonNode) anyObject()))
.thenReturn(new CustomException("error"));
AmazonServiceException ase = responseHandler.handle(httpResponse);
assertEquals(ErrorType.Service, ase.getErrorType());
}
示例6: getObjectMetadata
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
@Override
public ObjectMetadata getObjectMetadata(String bucketName, String key) throws AmazonServiceException {
AmazonS3Exception exception = new AmazonS3Exception("Internal Error");
exception.setStatusCode(500);
exception.setErrorType(ErrorType.Service);
throw exception;
}
示例7: getBucketInfo
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
private BucketInfo getBucketInfo(final String name) {
final BucketInfo info = getBucketInfoOrNull(name);
if (info == null) {
final AmazonServiceException e = new AmazonServiceException("The specified bucket does not exist");
e.setStatusCode(404);
e.setErrorType(ErrorType.Client);
e.setServiceName("Amazon S3");
e.setErrorCode("NoSuchBucket");
throw e;
}
return info;
}
示例8: getObject
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
private S3ObjectInfo getObject(final String key) {
final S3ObjectInfo info = getObjectOrNull(key);
if (info == null) {
final AmazonServiceException e = new AmazonServiceException("The specified key does not exist");
e.setErrorCode("NoSuchKey");
e.setErrorType(ErrorType.Client);
e.setServiceName("Amazon S3");
e.setStatusCode(404);
throw e;
}
return info;
}
示例9: listObjectsFailsIfNoBucket
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
@Test
public void listObjectsFailsIfNoBucket() {
try {
s3.listObjects("b");
} catch (final AmazonServiceException e) {
assertThat(e.getStatusCode(), is(404));
assertThat(e.getErrorCode(), is("NoSuchBucket"));
assertThat(e.getErrorType(), is(ErrorType.Client));
}
}
示例10: getObjectWithInvalidBucket
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
@Test
public void getObjectWithInvalidBucket() {
try {
s3.getObject("b", "a");
} catch (final AmazonServiceException e) {
assertThat(e.getStatusCode(), is(404));
assertThat(e.getErrorCode(), is("NoSuchBucket"));
assertThat(e.getErrorType(), is(ErrorType.Client));
}
}
示例11: getObjectWithInvalidKey
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
@Test
public void getObjectWithInvalidKey() {
s3.createBucket("b");
try {
s3.getObject("b", "a");
} catch (final AmazonServiceException e) {
assertThat(e.getStatusCode(), is(404));
assertThat(e.getErrorCode(), is("NoSuchKey"));
assertThat(e.getErrorType(), is(ErrorType.Client));
}
}
示例12: handle
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
public AmazonServiceException handle(HttpResponse response)
throws Exception {
JSONObject jsonBody = getBodyAsJson(response);
Class<? extends AmazonServiceException> exceptionClass = exceptionClasses.get(response.getStatusCode());
AmazonServiceException result;
// Support other attribute names for the message?
// TODO: Inspect exception type (caching details) and apply other values from the body
String message = jsonBody.has("message") ? jsonBody.getString("message") : jsonBody.getString("Message");
if (exceptionClass != null) {
result = exceptionClass.getConstructor(String.class).newInstance(message);
} else {
result = AmazonServiceException.class.getConstructor(String.class).newInstance(message);
}
result.setServiceName(response.getRequest().getServiceName());
result.setStatusCode(response.getStatusCode());
if (response.getStatusCode() < 500) {
result.setErrorType(ErrorType.Client);
} else {
result.setErrorType(ErrorType.Service);
}
for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) {
if (headerEntry.getKey().equalsIgnoreCase("X-Amzn-RequestId")) {
result.setRequestId(headerEntry.getValue());
}
}
return result;
}
示例13: getErrorTypeFromStatusCode
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
private ErrorType getErrorTypeFromStatusCode(int statusCode) {
return statusCode < 500 ? ErrorType.Client : ErrorType.Service;
}
示例14: shouldHandleServiceErrorForGetShardIterator
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
@Test
public void shouldHandleServiceErrorForGetShardIterator() {
shouldHandleGetShardIteratorError(newAmazonServiceException(ErrorType.Service),
TransientKinesisException.class);
}
示例15: shouldHandleClientErrorForGetShardIterator
import com.amazonaws.AmazonServiceException.ErrorType; //导入依赖的package包/类
@Test
public void shouldHandleClientErrorForGetShardIterator() {
shouldHandleGetShardIteratorError(newAmazonServiceException(ErrorType.Client),
RuntimeException.class);
}