📄 soapdecoder.java
字号:
break;
loc_index3++;
}
c = attachment.toString().charAt(loc_index3 - 1);
if (c == '"')
loc_index3--;
String location = attachment.toString().substring(loc_index2 + 1, loc_index3).trim();
subContent.setContentLocation(location);
}
deliverContent.addSubContent(subContent);
}
else
continue;
}
deliverReq.setContent(deliverContent);
return deliverReq;
}
/** 对SOAP的Envelope部分进行解码 */
private MM7RSReq parseXML(String xmlContent) {
String xml = "";
int index1 = xmlContent.indexOf("encoding=\"UTF-8\"");
if (index1 > 0) {
xml = xmlContent.substring(0, index1) + "encoding=\"GB2312\""
+ xmlContent.substring(index1 + "encoding=\"UTF-8\"".length());
xmlContent = xml;
}
if (xmlContent.lastIndexOf("Envelope>") > 0) {
SAXBuilder sax = new SAXBuilder();
try {
ByteArrayInputStream in = new ByteArrayInputStream(xmlContent.getBytes("GB2312"));
Document doc = sax.build(in);
Element root = doc.getRootElement();
Element envBody = (Element) root.getChildren().get(1);
Element Message = (Element) envBody.getChildren().get(0);
mm7rsReq = DecodeBody(Message);
Element envHeader = (Element) root.getChildren().get(0);
Element transID = (Element) envHeader.getChildren().get(0);
String transactionID = transID.getTextTrim();
if (transactionID != null || !transactionID.equals(""))
mm7rsReq.setTransactionID(transactionID);
else
// System.err.println("TransactionID必须有。");
log.warn("SOAPDecoder.parseXML():TransactionID必须有!");
return mm7rsReq;
}
catch (JDOMException jdome) {
// jdome.printStackTrace();
log.error("SOAPDecoder.parseXML():" + jdome);
return null;
}
catch (Exception e) {
// System.out.println("e=" + e);
log.error("SOAPDecoder.parseXML():" + e);
return null;
}
}
else {
return null;
}
}
/** 对soap Envelope中的env:Body部分进行解码 */
private MM7RSReq DecodeBody(Element message) {
String messageType = message.getName();
MessageName = messageType;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
int size = message.getChildren().size();
try {
if (messageType.equals("DeliverReq")) {
MM7DeliverReq deliverReq = new MM7DeliverReq();
for (int i = 0; i < size; i++) {
Element child = (Element) message.getChildren().get(i);
String name = child.getName();
if (name.equals("Sender")) {
// Element sub = (Element)child.getChildren().get(0);
deliverReq.setSender(child.getTextTrim());
// deliverReq.setSender(sub.getTextTrim());
continue;
}
if (name.equals("Recipients")) {
List To = new ArrayList();
List Cc = new ArrayList();
List Bcc = new ArrayList();
int recsize = child.getChildren().size();
for (int j = 0; j < recsize; j++) {
Element rec = (Element) child.getChildren().get(j);
if (rec.getName().equals("To")) {
int tosize = rec.getChildren().size();
for (int m = 0; m < tosize; m++) {
Element ele = (Element) rec.getChildren().get(m);
if (ele.getName().equals("Number") || ele.getName().equals("RFC2822Address")
|| ele.getName().equals("ShortCode"))
To.add(ele.getTextTrim());
}
continue;
}
if (rec.getName().equals("Cc")) {
int ccsize = rec.getChildren().size();
for (int m = 0; m < ccsize; m++) {
Element ele = (Element) rec.getChildren().get(m);
if (ele.getName().equals("Number") || ele.getName().equals("RFC2822Address")
|| ele.getName().equals("ShortCode"))
Cc.add(ele.getTextTrim());
}
continue;
}
if (rec.getName().equals("Bcc")) {
int bccsize = rec.getChildren().size();
for (int m = 0; m < bccsize; m++) {
Element ele = (Element) rec.getChildren().get(m);
if (ele.getName().equals("Number") || ele.getName().equals("RFC2822Address")
|| ele.getName().equals("ShortCode"))
Bcc.add(ele.getTextTrim());
}
continue;
}
}
if (!To.isEmpty())
deliverReq.setTo(To);
if (!Cc.isEmpty())
deliverReq.setCc(Cc);
if (!Bcc.isEmpty())
deliverReq.setBcc(Bcc);
continue;
}
if (name.equals("LinkedID")) {
deliverReq.setLinkedID(child.getTextTrim());
continue;
}
if (name.equals("MMSRelayServerID")) {
deliverReq.setMMSRelayServerID(child.getTextTrim());
continue;
}
if (name.equals("ReplyChargingID")) {
deliverReq.setReplyChargingID(child.getTextTrim());
continue;
}
if (name.equals("Subject")) {
deliverReq.setSubject(child.getTextTrim());
continue;
}
if (name.equals("Priority")) {
if (child.getTextTrim().equalsIgnoreCase("Low"))
deliverReq.setPriority((byte) 0);
else if (child.getTextTrim().equalsIgnoreCase("Normal"))
deliverReq.setPriority((byte) 1);
else if (child.getTextTrim().equalsIgnoreCase("High"))
deliverReq.setPriority((byte) 2);
continue;
}
if (name.equals("TimeStamp")) {
String time = child.getTextTrim();
if (time.length() > 19) {
time = time.substring(0, 19);
}
deliverReq.setTimeStamp(sdf.parse(time));
continue;
}
}
return deliverReq;
}
else if (messageType.equals("DeliveryReportReq")) {
MM7DeliveryReportReq deliveryReportReq = new MM7DeliveryReportReq();
for (int i = 0; i < size; i++) {
Element child = (Element) message.getChildren().get(i);
String name = child.getName();
if (name.equals("MMSRelayServerID")) {
deliveryReportReq.setMMSRelayServerID(child.getTextTrim());
continue;
}
if (name.equals("MessageID")) {
deliveryReportReq.setMessageID(child.getTextTrim());
continue;
}
if (name.equals("Recipient")) {
int recsize = child.getChildren().size();
for (int j = 0; j < recsize; j++) {
Element rec = (Element) child.getChildren().get(j);
deliveryReportReq.setRecipient(rec.getTextTrim());
continue;
}
}
if (name.equals("Sender")) {
deliveryReportReq.setSender(child.getTextTrim());
continue;
}
if (name.equals("TimeStamp")) {
String time = child.getTextTrim();
if (time.length() > 19) {
time = time.substring(0, 19);
}
deliveryReportReq.setTimeStamp(sdf.parse(time));
continue;
}
if (name.equals("MMStatus")) {
if (child.getTextTrim().equalsIgnoreCase("Expired"))
deliveryReportReq.setMMStatus((byte) 0);
else if (child.getTextTrim().equalsIgnoreCase("Retrieved"))
deliveryReportReq.setMMStatus((byte) 1);
else if (child.getTextTrim().equalsIgnoreCase("Rejected"))
deliveryReportReq.setMMStatus((byte) 2);
else if (child.getTextTrim().equalsIgnoreCase("System Rejected"))
deliveryReportReq.setMMStatus((byte) 2);
else if (child.getTextTrim().equalsIgnoreCase("Recipient Rejected"))
deliveryReportReq.setMMStatus((byte) 3);
else if (child.getTextTrim().equalsIgnoreCase("Indeterminate"))
deliveryReportReq.setMMStatus((byte) 4);
else if (child.getTextTrim().equalsIgnoreCase("Forwarded"))
deliveryReportReq.setMMStatus((byte) 5);
else
deliveryReportReq.setMMStatus((byte) 4);
continue;
}
if (name.equals("StatusText")) {
deliveryReportReq.setStatusText(child.getTextTrim());
continue;
}
}
mm7rsReq = deliveryReportReq;
}
else if (messageType.equals("ReadReplyReq")) {
MM7ReadReplyReq readReplyReq = new MM7ReadReplyReq();
for (int i = 0; i < size; i++) {
Element child = (Element) message.getChildren().get(i);
String name = child.getName();
if (name.equals("MMSReplayServerID")) {
readReplyReq.setMMSRelayServerID(child.getTextTrim());
continue;
}
if (name.equals("MessageID")) {
readReplyReq.setMessageID(child.getTextTrim());
continue;
}
if (name.equals("Recipient")) {
int recsize = child.getChildren().size();
for (int j = 0; j < recsize; j++) {
Element rec = (Element) child.getChildren().get(j);
readReplyReq.setRecipient(rec.getTextTrim());
continue;
}
}
if (name.equals("Sender")) {
readReplyReq.setSender(child.getTextTrim());
continue;
}
if (name.equals("TimeStamp")) {
String time = child.getTextTrim();
if (time.length() > 19) {
time = time.substring(0, 19);
}
readReplyReq.setTimeStamp(sdf.parse(time));
continue;
}
if (name.equals("MMStatus")) {
String strReadStatus = child.getTextTrim().trim();
byte bReadStatus = 2;
if (strReadStatus.equalsIgnoreCase("read"))
bReadStatus = 0;
else if (strReadStatus.equalsIgnoreCase("deleted"))
bReadStatus = 1;
else
bReadStatus = 2;
readReplyReq.setMMStatus(bReadStatus);
// readReplyReq.setMMStatus(Byte.parseByte(child.getTextTrim()));
continue;
}
if (name.equals("StatusText")) {
readReplyReq.setStatusText(child.getTextTrim());
continue;
}
}
mm7rsReq = readReplyReq;
}
else
return null;
return mm7rsReq;
}
catch (ParseException e) {
e.printStackTrace();
return null;
}
}
/** 对内容进行BASE64解码 */
// 将 BASE64 编码的字符串 s 进行解码
public static ByteArrayOutputStream getFromBASE64(String s) {
if (s == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
ByteArrayOutputStream decodebaos = new ByteArrayOutputStream();
try {
byte[] b = decoder.decodeBuffer(s);
decodebaos.write(b);
return decodebaos;
}
catch (Exception e) {
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -