in src/main/java/com/aliyun/mns/model/serialize/XMLDeserializer.java [105:136]
protected void safeAddPropertiesToMessage(Element root, Message message) {
Element userPropertiesElement = safeGetElement(root, USER_PROPERTIES_TAG);
if (userPropertiesElement != null) {
Map<String, MessagePropertyValue> userProperties = message.getUserProperties();
if (userProperties == null) {
userProperties = new HashMap<String, MessagePropertyValue>();
message.setUserProperties(userProperties);
}
for (Element propertyValueElement : safeGetElements(userPropertiesElement, MESSAGE_PROPERTY_TAG)) {
String name = safeGetElementContent(propertyValueElement, PROPERTY_NAME_TAG, null);
String value = safeGetElementContent(propertyValueElement, PROPERTY_VALUE_TAG, null);
String type = safeGetElementContent(propertyValueElement, PROPERTY_TYPE_TAG, null);
if (name != null && value != null && type != null) {
PropertyType typeEnum = PropertyType.valueOf(type);
// 如果是二进制类型,需要base64解码
if (typeEnum == PropertyType.BINARY) {
try {
byte[] decodedBytes = Base64.decodeBase64(value);
value = new String(decodedBytes, DEFAULT_CHARSET);
} catch (UnsupportedEncodingException e) {
throw new ClientException("Not support enconding:"
+ DEFAULT_CHARSET, null, e);
}
}
MessagePropertyValue propertyValue = new MessagePropertyValue(PropertyType.valueOf(type), value);
userProperties.put(name, propertyValue);
}
}
}
}