in alibabacloud-gateway-oss/java/src/main/java/com/aliyun/gateway/oss/Client.java [242:343]
public void modifyResponse(com.aliyun.gateway.spi.models.InterceptorContext context, com.aliyun.gateway.spi.models.AttributeMap attributeMap) throws Exception {
com.aliyun.gateway.spi.models.InterceptorContext.InterceptorContextRequest request = context.request;
com.aliyun.gateway.spi.models.InterceptorContext.InterceptorContextResponse response = context.response;
String bodyStr = null;
if (com.aliyun.teautil.Common.is4xx(response.statusCode) || com.aliyun.teautil.Common.is5xx(response.statusCode)) {
bodyStr = com.aliyun.teautil.Common.readAsString(response.body);
if (!com.aliyun.teautil.Common.empty(bodyStr)) {
java.util.Map<String, Object> respMap = com.aliyun.teaxml.Client.parseXml(bodyStr, null);
java.util.Map<String, Object> err = com.aliyun.teautil.Common.assertAsMap(respMap.get("Error"));
throw new TeaException(TeaConverter.buildMap(
new TeaPair("code", err.get("Code")),
new TeaPair("message", err.get("Message")),
new TeaPair("data", TeaConverter.buildMap(
new TeaPair("statusCode", response.statusCode),
new TeaPair("requestId", err.get("RequestId")),
new TeaPair("ecCode", err.get("EC")),
new TeaPair("Recommend", err.get("RecommendDoc")),
new TeaPair("hostId", err.get("HostId")),
new TeaPair("AccessDeniedDetail", err.get("AccessDeniedDetail"))
))
));
} else {
java.util.Map<String, String> headers = response.headers;
String requestId = headers.get("x-oss-request-id");
String ecCode = headers.get("x-oss-ec-code");
throw new TeaException(TeaConverter.buildMap(
new TeaPair("code", response.statusCode),
new TeaPair("message", null),
new TeaPair("data", TeaConverter.buildMap(
new TeaPair("statusCode", response.statusCode),
new TeaPair("requestId", "" + requestId + ""),
new TeaPair("ecCode", ecCode)
))
));
}
}
java.util.Map<String, String> ctx = attributeMap.key;
if (!com.aliyun.teautil.Common.isUnset(ctx)) {
if (!com.aliyun.teautil.Common.isUnset(ctx.get("crc")) && !com.aliyun.teautil.Common.isUnset(response.headers.get("x-oss-hash-crc64ecma")) && !com.aliyun.darabonbastring.Client.equals(ctx.get("crc"), response.headers.get("x-oss-hash-crc64ecma"))) {
throw new TeaException(TeaConverter.buildMap(
new TeaPair("code", "CrcNotMatched"),
new TeaPair("data", TeaConverter.buildMap(
new TeaPair("clientCrc", ctx.get("crc")),
new TeaPair("serverCrc", response.headers.get("x-oss-hash-crc64ecma"))
))
));
}
if (!com.aliyun.teautil.Common.isUnset(ctx.get("md5")) && !com.aliyun.teautil.Common.isUnset(response.headers.get("content-md5")) && !com.aliyun.darabonbastring.Client.equals(ctx.get("md5"), response.headers.get("content-md5"))) {
throw new TeaException(TeaConverter.buildMap(
new TeaPair("code", "MD5NotMatched"),
new TeaPair("data", TeaConverter.buildMap(
new TeaPair("clientMD5", ctx.get("md5")),
new TeaPair("serverMD5", response.headers.get("content-md5"))
))
));
}
}
if (!com.aliyun.teautil.Common.isUnset(response.body)) {
if (com.aliyun.teautil.Common.equalNumber(response.statusCode, 204)) {
com.aliyun.teautil.Common.readAsString(response.body);
} else if (com.aliyun.darabonbastring.Client.equals(request.bodyType, "xml")) {
bodyStr = com.aliyun.teautil.Common.readAsString(response.body);
response.deserializedBody = bodyStr;
if (!com.aliyun.teautil.Common.empty(bodyStr)) {
Object result = com.aliyun.gateway.oss.util.Client.parseXml(bodyStr, request.action);
// for no util language
// var result : any = XML.parseXml(bodyStr, null);
try {
response.deserializedBody = com.aliyun.teautil.Common.assertAsMap(result);
} catch (TeaException error) {
response.deserializedBody = result;
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
response.deserializedBody = result;
}
}
} else if (com.aliyun.teautil.Common.equalString(request.bodyType, "binary")) {
response.deserializedBody = response.body;
} else if (com.aliyun.teautil.Common.equalString(request.bodyType, "byte")) {
byte[] byt = com.aliyun.teautil.Common.readAsBytes(response.body);
response.deserializedBody = byt;
} else if (com.aliyun.teautil.Common.equalString(request.bodyType, "string")) {
response.deserializedBody = com.aliyun.teautil.Common.readAsString(response.body);
} else if (com.aliyun.teautil.Common.equalString(request.bodyType, "json")) {
Object obj = com.aliyun.teautil.Common.readAsJSON(response.body);
java.util.Map<String, Object> res = com.aliyun.teautil.Common.assertAsMap(obj);
response.deserializedBody = res;
} else if (com.aliyun.teautil.Common.equalString(request.bodyType, "array")) {
response.deserializedBody = com.aliyun.teautil.Common.readAsJSON(response.body);
} else {
response.deserializedBody = com.aliyun.teautil.Common.readAsString(response.body);
}
}
}