Search in sources :

Example 16 with ResponseParseException

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);
    }
}
Also used : OSSErrorResult(com.aliyun.oss.internal.model.OSSErrorResult) JAXBResponseParser(com.aliyun.oss.common.parser.JAXBResponseParser) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 17 with ResponseParseException

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;
    }
}
Also used : ResponseHandler(com.aliyun.oss.common.comm.ResponseHandler) RequestChecksumHanlder(com.aliyun.oss.common.comm.RequestChecksumHanlder) OSSException(com.aliyun.oss.OSSException) ResponseMessage(com.aliyun.oss.common.comm.ResponseMessage) RequestProgressHanlder(com.aliyun.oss.common.comm.RequestProgressHanlder) ResponseProgressHandler(com.aliyun.oss.common.comm.ResponseProgressHandler) ExecutionContext(com.aliyun.oss.common.comm.ExecutionContext) WebServiceRequest(com.aliyun.oss.model.WebServiceRequest) RequestHandler(com.aliyun.oss.common.comm.RequestHandler) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ResponseChecksumHandler(com.aliyun.oss.common.comm.ResponseChecksumHandler) RequestSigner(com.aliyun.oss.common.auth.RequestSigner)

Example 18 with ResponseParseException

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);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) Owner(com.aliyun.oss.model.Owner) ObjectAcl(com.aliyun.oss.model.ObjectAcl) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 19 with ResponseParseException

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);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) Element(org.jdom.Element) LiveChannelInfo(com.aliyun.oss.model.LiveChannelInfo) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) LiveChannelTarget(com.aliyun.oss.model.LiveChannelTarget) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 20 with ResponseParseException

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);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) InitiateMultipartUploadResult(com.aliyun.oss.model.InitiateMultipartUploadResult) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Aggregations

ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)41 ParseException (java.text.ParseException)39 JDOMParseException (org.jdom.input.JDOMParseException)39 Element (org.jdom.Element)37 ArrayList (java.util.ArrayList)15 Date (java.util.Date)6 Owner (com.aliyun.oss.model.Owner)5 BigInteger (java.math.BigInteger)3 Bucket (com.aliyun.oss.model.Bucket)2 CannedAccessControlList (com.aliyun.oss.model.CannedAccessControlList)2 CannedUdfAcl (com.aliyun.oss.model.CannedUdfAcl)2 InstanceFlavor (com.aliyun.oss.model.InstanceFlavor)2 UdfApplicationInfo (com.aliyun.oss.model.UdfApplicationInfo)2 OSSException (com.aliyun.oss.OSSException)1 RequestSigner (com.aliyun.oss.common.auth.RequestSigner)1 ExecutionContext (com.aliyun.oss.common.comm.ExecutionContext)1 RequestChecksumHanlder (com.aliyun.oss.common.comm.RequestChecksumHanlder)1 RequestHandler (com.aliyun.oss.common.comm.RequestHandler)1 RequestProgressHanlder (com.aliyun.oss.common.comm.RequestProgressHanlder)1 ResponseChecksumHandler (com.aliyun.oss.common.comm.ResponseChecksumHandler)1