in src/main/java/com/aliyun/mns/model/serialize/topic/TopicMessageSerializer.java [70:156]
public InputStream serialize(PublishMessageRequest request, String encoding) throws Exception {
Document doc = getDocumentBuilder().newDocument();
TopicMessage msg = request.getMessage();
Element root = doc.createElementNS(DEFAULT_XML_NAMESPACE, MESSAGE_TAG);
doc.appendChild(root);
Element node = safeCreateContentElement(doc, MESSAGE_BODY_TAG,
msg.getOriginalMessageBody(), "");
if (node != null) {
root.appendChild(node);
}
node = safeCreateContentElement(doc, MESSAGE_TAG_TAG, msg.getMessageTag(), null);
if (node != null) {
root.appendChild(node);
}
MessageAttributes messageAttributes = request.getMessageAttributes();
if (messageAttributes != null) {
Element attributesNode = doc.createElement(MESSAGE_ATTRIBUTES_TAG);
root.appendChild(attributesNode);
if (messageAttributes.getMailAttributes() != null) {
node = safeCreateContentElement(doc, DIRECT_MAIL_TAG,
messageAttributes.getMailAttributes().toJson(getGson()), null);
if (node != null) {
attributesNode.appendChild(node);
}
}
if (messageAttributes.getDayuAttributes() != null) {
node = safeCreateContentElement(doc, DAYU_TAG, messageAttributes.getDayuAttributes().toJson(getGson()),
null);
if (node != null) {
attributesNode.appendChild(node);
}
}
if (messageAttributes.getSmsAttributes() != null) {
node = safeCreateContentElement(doc, SMS_TAG, messageAttributes.getSmsAttributes().toJson(getGson()),
null);
if (node != null) {
attributesNode.appendChild(node);
}
}
if (messageAttributes.getBatchSmsAttributes() != null) {
node = safeCreateContentElement(doc, SMS_TAG,
messageAttributes.getBatchSmsAttributes().toJson(getGson()), null);
if (node != null) {
attributesNode.appendChild(node);
}
}
if (messageAttributes.getWebSocketAttributes() != null) {
node = safeCreateContentElement(doc, WEBSOCKET_TAG,
messageAttributes.getWebSocketAttributes().toJson(getGson()), null);
if (node != null) {
attributesNode.appendChild(node);
}
}
if (messageAttributes.getPushAttributes() != null) {
node = safeCreateContentElement(doc, PUSH_TAG, messageAttributes.getPushAttributes().toJson(getGson()),
null);
if (node != null) {
attributesNode.appendChild(node);
}
}
}
node = safeCreatePropertiesNode(doc, msg.getUserProperties(), USER_PROPERTIES_TAG, MESSAGE_PROPERTY_TAG);
if (node != null) {
root.appendChild(node);
}
node = safeCreatePropertiesNode(doc, msg.getSystemProperties(), SYSTEM_PROPERTIES_TAG,
MESSAGE_SYSTEM_PROPERTY_TAG);
if (node != null) {
root.appendChild(node);
}
String xml = XmlUtil.xmlNodeToString(doc, encoding);
return new ByteArrayInputStream(xml.getBytes(encoding));
}