use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetBucketAcl.
/**
* Unmarshall get bucket acl response body to ACL.
*/
public static AccessControlList parseGetBucketAcl(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
AccessControlList acl = new AccessControlList();
String id = root.getChild("Owner").getChildText("ID");
String displayName = root.getChild("Owner").getChildText("DisplayName");
Owner owner = new Owner(id, displayName);
acl.setOwner(owner);
String aclString = root.getChild("AccessControlList").getChildText("Grant");
CannedAccessControlList cacl = CannedAccessControlList.parse(aclString);
acl.setCannedACL(cacl);
switch(cacl) {
case PublicRead:
acl.grantPermission(GroupGrantee.AllUsers, Permission.Read);
break;
case PublicReadWrite:
acl.grantPermission(GroupGrantee.AllUsers, Permission.FullControl);
break;
default:
break;
}
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 parseGetBucketTagging.
/**
* Unmarshall get bucket tagging response body to cors rules.
*/
@SuppressWarnings("unchecked")
public static TagSet parseGetBucketTagging(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
TagSet tagSet = new TagSet();
List<Element> tagElems = root.getChild("TagSet").getChildren("Tag");
for (Element tagElem : tagElems) {
String key = null;
String value = null;
if (tagElem.getChild("Key") != null) {
key = tagElem.getChildText("Key");
}
if (tagElem.getChild("Value") != null) {
value = tagElem.getChildText("Value");
}
tagSet.setTag(key, value);
}
return tagSet;
} 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 parseGetLiveChannelHistory.
/**
* Unmarshall get live channel history response body to corresponding
* result.
*/
@SuppressWarnings("unchecked")
public static List<LiveRecord> parseGetLiveChannelHistory(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
List<LiveRecord> liveRecords = new ArrayList<LiveRecord>();
List<Element> recordElements = root.getChildren("LiveRecord");
for (Element recordElem : recordElements) {
LiveRecord record = new LiveRecord();
record.setStartDate(DateUtil.parseIso8601Date(recordElem.getChildText("StartTime")));
record.setEndDate(DateUtil.parseIso8601Date(recordElem.getChildText("EndTime")));
record.setRemoteAddress(recordElem.getChildText("RemoteAddr"));
liveRecords.add(record);
}
return liveRecords;
} 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 parseImageStyle.
/**
* Unmarshall get image style response body to corresponding result.
*/
public static GetImageStyleResult parseImageStyle(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
GetImageStyleResult result = new GetImageStyleResult();
result.SetStyleName(root.getChildText("Name"));
result.SetStyle(root.getChildText("Content"));
result.SetLastModifyTime(DateUtil.parseRfc822Date(root.getChildText("LastModifyTime")));
result.SetCreationDate(DateUtil.parseRfc822Date(root.getChildText("CreateTime")));
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 parseGetLiveChannelStat.
/**
* Unmarshall get live channel stat response body to corresponding result.
*/
public static LiveChannelStat parseGetLiveChannelStat(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
LiveChannelStat result = new LiveChannelStat();
result.setPushflowStatus(PushflowStatus.parse(root.getChildText("Status")));
if (root.getChild("ConnectedTime") != null) {
result.setConnectedDate(DateUtil.parseIso8601Date(root.getChildText("ConnectedTime")));
}
if (root.getChild("RemoteAddr") != null) {
result.setRemoteAddress(root.getChildText("RemoteAddr"));
}
Element videoElem = root.getChild("Video");
if (videoElem != null) {
VideoStat videoStat = new VideoStat();
videoStat.setWidth(Integer.parseInt(videoElem.getChildText("Width")));
videoStat.setHeight(Integer.parseInt(videoElem.getChildText("Height")));
videoStat.setFrameRate(Integer.parseInt(videoElem.getChildText("FrameRate")));
videoStat.setBandWidth(Integer.parseInt(videoElem.getChildText("Bandwidth")));
videoStat.setCodec(videoElem.getChildText("Codec"));
result.setVideoStat(videoStat);
}
Element audioElem = root.getChild("Audio");
if (audioElem != null) {
AudioStat audioStat = new AudioStat();
audioStat.setBandWidth(Integer.parseInt(audioElem.getChildText("Bandwidth")));
audioStat.setSampleRate(Integer.parseInt(audioElem.getChildText("SampleRate")));
audioStat.setCodec(audioElem.getChildText("Codec"));
result.setAudioStat(audioStat);
}
return result;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
Aggregations