use of software.amazon.awssdk.protocols.query.unmarshall.XmlElement in project aws-sdk-java-v2 by aws.
the class DecorateErrorFromResponseBodyUnmarshallerTest method status500_bodyWithError.
@Test
public void status500_bodyWithError() {
DecorateErrorFromResponseBodyUnmarshaller decorateErrorFromResponseBodyUnmarshaller = DecorateErrorFromResponseBodyUnmarshaller.of(xml -> xml.getOptionalElementByName("test-error"));
SdkHttpFullResponse sdkHttpFullResponse = SdkHttpFullResponse.builder().statusCode(500).build();
XmlElement parsedError = XmlElement.builder().elementName("test-error").build();
XmlElement parsedBody = XmlElement.builder().elementName("Error").addChildElement(parsedError).build();
AwsXmlUnmarshallingContext context = AwsXmlUnmarshallingContext.builder().sdkHttpFullResponse(sdkHttpFullResponse).parsedXml(parsedBody).build();
AwsXmlUnmarshallingContext result = decorateErrorFromResponseBodyUnmarshaller.apply(context);
assertThat(result.isResponseSuccess()).isFalse();
assertThat(result.parsedErrorXml()).isSameAs(parsedError);
}
use of software.amazon.awssdk.protocols.query.unmarshall.XmlElement in project aws-sdk-java-v2 by aws.
the class DecorateErrorFromResponseBodyUnmarshallerTest method status500_bodyWithNoError.
@Test
public void status500_bodyWithNoError() {
DecorateErrorFromResponseBodyUnmarshaller decorateErrorFromResponseBodyUnmarshaller = DecorateErrorFromResponseBodyUnmarshaller.of(xml -> xml.getOptionalElementByName("test-error"));
SdkHttpFullResponse sdkHttpFullResponse = SdkHttpFullResponse.builder().statusCode(500).build();
XmlElement parsedBody = XmlElement.builder().elementName("ValidResponse").build();
AwsXmlUnmarshallingContext context = AwsXmlUnmarshallingContext.builder().sdkHttpFullResponse(sdkHttpFullResponse).parsedXml(parsedBody).build();
AwsXmlUnmarshallingContext result = decorateErrorFromResponseBodyUnmarshaller.apply(context);
assertThat(result.isResponseSuccess()).isFalse();
assertThat(result.parsedErrorXml()).isNull();
}
use of software.amazon.awssdk.protocols.query.unmarshall.XmlElement in project aws-sdk-java-v2 by aws.
the class DecorateErrorFromResponseBodyUnmarshallerTest method status200_bodyWithNoError.
@Test
public void status200_bodyWithNoError() {
DecorateErrorFromResponseBodyUnmarshaller decorateErrorFromResponseBodyUnmarshaller = DecorateErrorFromResponseBodyUnmarshaller.of(FAIL_TEST_ERROR_ROOT_LOCATOR);
SdkHttpFullResponse sdkHttpFullResponse = SdkHttpFullResponse.builder().statusCode(200).build();
XmlElement parsedBody = XmlElement.builder().elementName("ValidResponse").build();
AwsXmlUnmarshallingContext context = AwsXmlUnmarshallingContext.builder().sdkHttpFullResponse(sdkHttpFullResponse).parsedXml(parsedBody).build();
AwsXmlUnmarshallingContext result = decorateErrorFromResponseBodyUnmarshaller.apply(context);
assertThat(result.isResponseSuccess()).isTrue();
assertThat(result.parsedErrorXml()).isNull();
}
use of software.amazon.awssdk.protocols.query.unmarshall.XmlElement in project aws-sdk-java-v2 by aws.
the class DecorateErrorFromResponseBodyUnmarshallerTest method status200_bodyWithError.
@Test
public void status200_bodyWithError() {
DecorateErrorFromResponseBodyUnmarshaller decorateErrorFromResponseBodyUnmarshaller = DecorateErrorFromResponseBodyUnmarshaller.of(FAIL_TEST_ERROR_ROOT_LOCATOR);
SdkHttpFullResponse sdkHttpFullResponse = SdkHttpFullResponse.builder().statusCode(200).build();
XmlElement parsedError = XmlElement.builder().elementName("test-error").build();
XmlElement parsedBody = XmlElement.builder().elementName("Error").addChildElement(parsedError).build();
AwsXmlUnmarshallingContext context = AwsXmlUnmarshallingContext.builder().sdkHttpFullResponse(sdkHttpFullResponse).parsedXml(parsedBody).build();
AwsXmlUnmarshallingContext result = decorateErrorFromResponseBodyUnmarshaller.apply(context);
assertThat(result.isResponseSuccess()).isFalse();
assertThat(result.parsedErrorXml()).isSameAs(parsedBody);
}
use of software.amazon.awssdk.protocols.query.unmarshall.XmlElement in project aws-sdk-java-v2 by aws.
the class AwsXmlErrorUnmarshaller method unmarshall.
/**
* Unmarshal an AWS XML exception
* @param documentRoot The parsed payload document
* @param errorRoot The specific element of the parsed payload document that contains the error to be marshalled
* or empty if it could not be located.
* @param documentBytes The raw bytes of the original payload document if they are available
* @param response The HTTP response object
* @param executionAttributes {@link ExecutionAttributes} for the current execution
* @return An {@link AwsServiceException} unmarshalled from the XML.
*/
public AwsServiceException unmarshall(XmlElement documentRoot, Optional<XmlElement> errorRoot, Optional<SdkBytes> documentBytes, SdkHttpFullResponse response, ExecutionAttributes executionAttributes) {
String errorCode = getErrorCode(errorRoot);
AwsServiceException.Builder builder = errorRoot.map(e -> invokeSafely(() -> unmarshallFromErrorCode(response, e, errorCode))).orElseGet(this::defaultException);
AwsErrorDetails awsErrorDetails = AwsErrorDetails.builder().errorCode(errorCode).errorMessage(builder.message()).rawResponse(documentBytes.orElse(null)).sdkHttpResponse(response).serviceName(executionAttributes.getAttribute(AwsExecutionAttribute.SERVICE_NAME)).build();
builder.requestId(getRequestId(response, documentRoot)).extendedRequestId(getExtendedRequestId(response)).statusCode(response.statusCode()).clockSkew(getClockSkew(executionAttributes)).awsErrorDetails(awsErrorDetails);
return builder.build();
}
Aggregations