use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class OSSErrorResponseHandler method handle.
public void handle(ResponseMessage response) throws OSSException, ClientException {
if (response.isSuccessful()) {
return;
}
String requestId = response.getRequestId();
int statusCode = response.getStatusCode();
if (response.getContent() == null) {
/**
* When HTTP response body is null, handle status code 404 Not
* Found, 304 Not Modified, 412 Precondition Failed especially.
*/
if (statusCode == HttpStatus.SC_NOT_FOUND) {
throw ExceptionFactory.createOSSException(requestId, OSSErrorCode.NO_SUCH_KEY, "Not Found");
} else if (statusCode == HttpStatus.SC_NOT_MODIFIED) {
throw ExceptionFactory.createOSSException(requestId, OSSErrorCode.NOT_MODIFIED, "Not Modified");
} else if (statusCode == HttpStatus.SC_PRECONDITION_FAILED) {
throw ExceptionFactory.createOSSException(requestId, OSSErrorCode.PRECONDITION_FAILED, "Precondition Failed");
} else {
throw ExceptionFactory.createUnknownOSSException(requestId, statusCode);
}
}
JAXBResponseParser parser = new JAXBResponseParser(OSSErrorResult.class);
try {
OSSErrorResult errorResult = (OSSErrorResult) parser.parse(response);
throw ExceptionFactory.createOSSException(errorResult, response.getErrorResponseAsString());
} catch (ResponseParseException e) {
throw ExceptionFactory.createInvalidResponseException(requestId, response.getErrorResponseAsString(), e);
} finally {
safeCloseResponse(response);
}
}
use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class OSSOperation method doOperation.
protected <T> T doOperation(RequestMessage request, ResponseParser<T> parser, String bucketName, String key, boolean keepResponseOpen, List<RequestHandler> requestHandlers, List<ResponseHandler> reponseHandlers) throws OSSException, ClientException {
final WebServiceRequest originalRequest = request.getOriginalRequest();
request.getHeaders().putAll(client.getClientConfiguration().getDefaultHeaders());
request.getHeaders().putAll(originalRequest.getHeaders());
request.getParameters().putAll(originalRequest.getParameters());
ExecutionContext context = createDefaultContext(request.getMethod(), bucketName, key);
if (context.getCredentials().useSecurityToken() && !request.isUseUrlSignature()) {
request.addHeader(OSSHeaders.OSS_SECURITY_TOKEN, context.getCredentials().getSecurityToken());
}
context.addRequestHandler(new RequestProgressHanlder());
if (requestHandlers != null) {
for (RequestHandler handler : requestHandlers) context.addRequestHandler(handler);
}
if (client.getClientConfiguration().isCrcCheckEnabled()) {
context.addRequestHandler(new RequestChecksumHanlder());
}
context.addResponseHandler(new ResponseProgressHandler(originalRequest));
if (reponseHandlers != null) {
for (ResponseHandler handler : reponseHandlers) context.addResponseHandler(handler);
}
if (client.getClientConfiguration().isCrcCheckEnabled()) {
context.addResponseHandler(new ResponseChecksumHandler());
}
List<RequestSigner> signerHandlers = this.client.getClientConfiguration().getSignerHandlers();
if (signerHandlers != null) {
for (RequestSigner signer : signerHandlers) {
context.addSignerHandler(signer);
}
}
ResponseMessage response = send(request, context, keepResponseOpen);
try {
return parser.parse(response);
} catch (ResponseParseException rpe) {
OSSException oe = ExceptionFactory.createInvalidResponseException(response.getRequestId(), rpe.getMessage(), rpe);
logException("Unable to parse response error: ", rpe);
throw oe;
}
}
use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetObjectAcl.
/**
* Unmarshall object acl response body to object ACL.
*/
public static ObjectAcl parseGetObjectAcl(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
ObjectAcl acl = new ObjectAcl();
String id = root.getChild("Owner").getChildText("ID");
String displayName = root.getChild("Owner").getChildText("DisplayName");
Owner owner = new Owner(id, displayName);
acl.setOwner(owner);
String grantString = root.getChild("AccessControlList").getChildText("Grant");
acl.setPermission(ObjectPermission.parsePermission(grantString));
return acl;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetLiveChannelInfo.
/**
* Unmarshall get live channel info response body to corresponding result.
*/
public static LiveChannelInfo parseGetLiveChannelInfo(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
LiveChannelInfo result = new LiveChannelInfo();
result.setDescription(root.getChildText("Description"));
result.setStatus(LiveChannelStatus.parse(root.getChildText("Status")));
Element targetElem = root.getChild("Target");
LiveChannelTarget target = new LiveChannelTarget();
target.setType(targetElem.getChildText("Type"));
target.setFragDuration(Integer.parseInt(targetElem.getChildText("FragDuration")));
target.setFragCount(Integer.parseInt(targetElem.getChildText("FragCount")));
target.setPlaylistName(targetElem.getChildText("PlaylistName"));
result.setTarget(target);
return result;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseInitiateMultipartUpload.
/**
* Unmarshall initiate multipart upload response body to corresponding
* result.
*/
public static InitiateMultipartUploadResult parseInitiateMultipartUpload(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
InitiateMultipartUploadResult result = new InitiateMultipartUploadResult();
if (root.getChild("Bucket") != null) {
result.setBucketName(root.getChildText("Bucket"));
}
if (root.getChild("Key") != null) {
result.setKey(root.getChildText("Key"));
}
if (root.getChild("UploadId") != null) {
result.setUploadId(root.getChildText("UploadId"));
}
return result;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
Aggregations