📄 soapencoder.java
字号:
}
}
}
sb.append("Content-Type:" + "multipart/related;" + "start=\"" + strtempID
+ "\";type=\"application/smil\"" + ";boundary=\"SubPart_7452684322002_77645\""
+ "\r\n");
}
else {
sb.append("Content-Type:" + parentContent.getContentType().getPrimaryType() + "/"
+ parentContent.getContentType().getSubType()
+ ";boundary=\"SubPart_7452684322002_77645\"" + "\r\n");
}
}
else
sb.append("Content-Type:" + "multipart/mixed" + ";boundary=\"SubPart_7452684322002_77645\""
+ "\r\n");
if (parentContent.isContentIDExist())
sb.append("Content-ID:" + parentContent.getContentID() + "\r\n");
else
sb.append("Content-ID:<SaturnPics-01020930>" + "\r\n");
sb.append("Content-Transfer-Encoding:8bit" + "\r\n");
if (parentContent.isContentLocationExist())
sb.append("Content-Location:" + parentContent.getContentLocation() + "\r\n");
sb.append("\r\n");
ByteArrayOutputStream Subbaos = new ByteArrayOutputStream();
if (parentContent.isMultipart()) {
List subContent = new ArrayList();
subContent = parentContent.getSubContents();
for (int i = 0; i < subContent.size(); i++) {
ContentBuffer = new StringBuffer();
ContentBuffer.append("--SubPart_7452684322002_77645\r\n");
MMContent content = (MMContent) subContent.get(i);
if (content.getContentType() != null) {
ContentBuffer.append("Content-Type:" + content.getContentType().getPrimaryType() + "/"
+ content.getContentType().getSubType());
if (content.getContentType().getPrimaryType().equalsIgnoreCase("text")) {
if (content.getCharset() == null || content.getCharset().length() == 0)
ContentBuffer.append(";charset=" + mm7Config.getCharSet());
else
ContentBuffer.append(";charset=" + content.getCharset());
}
ContentBuffer.append("\r\n");
}
else {
if (content.isContentIDExist()) {
String strContentID = content.getContentID();
int index = strContentID.indexOf(".");
String type = strContentID.substring(index + 1);
type = type.toLowerCase();
if (type.equals("txt")) {
ContentBuffer.append("Content-Type:text/plain;charset="
+ mm7Config.getCharSet() + "\r\n");
}
else if (type.equals("jpg")) {
ContentBuffer.append("Content-Type:image/jpeg" + "\r\n");
}
else if (type.equals("gif")) {
ContentBuffer.append("Content-Type:image/gif" + "\r\n");
}
}
}
ContentBuffer.append("Content-Transfer-Encoding:8bit" + "\r\n");
if (content.getContentType().getSubType().equalsIgnoreCase("related")) {
if (content.isContentIDExist())
ContentBuffer.append("Content-ID:" + content.getContentID() + "\r\n");
else
ContentBuffer.append("Content-ID:<START>\r\n");
}
else {
if (content.isContentIDExist())
ContentBuffer.append("Content-ID:" + content.getContentID() + "\r\n");
}
if (content.isContentLocationExist())
ContentBuffer.append("Content-Location:" + content.getContentLocation() + "\r\n");
ContentBuffer.append("\r\n");
try {
Subbaos.write(ContentBuffer.toString().getBytes());
Subbaos.write(content.getContent());
Subbaos.write("\r\n\r\n".getBytes());
}
catch (IOException e) {
e.printStackTrace();
}
}
Subbaos.write("--SubPart_7452684322002_77645--\r\n".getBytes());
Subbaos.write("----NextPart_0_2817_24856--\r\n".getBytes());
byteOutput.write(sb.toString().getBytes("" + mm7Config.getCharSet()));
byteOutput.write(Subbaos.toByteArray());
}
}
else {
// sb.append("</mm7:SubmitReq>");
sb.append("</SubmitReq>");
sb.append("</env:Body></env:Envelope>");
// Cancel by hudm 2004-06-21
// sb.append("----NextPart_0_2817_24856--\r\n");
// end Cancel by hudm 2004-06-21
byteOutput.write(sb.toString().getBytes());
}
}
/**
* 若发送的消息为MM7CancelReq
*/
else if (mm7VaspReq instanceof MM7CancelReq) {
MM7CancelReq cancelReq = (MM7CancelReq) mm7VaspReq;
sb
.append("<CancelReq xmlns:mm7=\"http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-0\" env:mustUnderstand=\"1\">");
if (cancelReq.isMM7VersionExist())
sb.append("<MM7Version>" + cancelReq.getMM7Version() + "</MM7Version>");
else
// System.out.println("MM7Version 不许为空!");
log.warn("SOAPEncoder.encodeMessage():MM7Version 不许为空!");
if (cancelReq.isVASPIDExist() || cancelReq.isVASIDExist()) {
sb.append("<SenderIdentification>");
if (cancelReq.isVASPIDExist())
sb.append("<VASPID>" + cancelReq.getVASPID() + "</VASPID>");
if (cancelReq.isVASIDExist())
sb.append("<VASID>" + cancelReq.getVASID() + "</VASID>");
sb.append("</SenderIdentification>");
}
if (cancelReq.isSenderAddressExist())
sb.append("<SenderAddress>" + cancelReq.getSenderAddress() + "</SenderAddress>");
if (cancelReq.isMessageIDExist())
sb.append("<MessageID>" + cancelReq.getMessageID() + "</MessageID>");
else
// System.out.println("待取消的消息的标识符MessageID不许为空!");
log.warn("SOAPEncoder.encodeMessage():待取消的消息的标识符MessageID不许为空!");
sb.append("</CancelReq>");
sb.append("</env:Body></env:Envelope>");
// Cancel by hudm 2004-06-21
// sb.append("----NextPart_0_2817_24856--");
// end Cancel by hudm 2004-06-21
byteOutput.write(sb.toString().getBytes());
}
/**
* 若发送的消息为MM7ReplaceReq
*/
else if (mm7VaspReq instanceof MM7ReplaceReq) {
MM7ReplaceReq replaceReq = (MM7ReplaceReq) mm7VaspReq;
sb
.append("<ReplaceReq xmlns:mm7=\"http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-0\" env:mustUnderstand=\"1\">");
if (replaceReq.isMM7VersionExist())
sb.append("<MM7Version>" + replaceReq.getMM7Version() + "</MM7Version>");
if (replaceReq.isVASPIDExist() || replaceReq.isVASIDExist()) {
sb.append("<SenderIdentification>");
if (replaceReq.isVASPIDExist())
sb.append("<VASPID>" + replaceReq.getVASPID() + "</VASPID>");
if (replaceReq.isVASIDExist())
sb.append("<VASID>" + replaceReq.getVASID() + "</VASID>");
sb.append("</SenderIdentification>");
}
if (replaceReq.isMessageIDExist())
sb.append("<MessageID>" + replaceReq.getMessageID() + "</MessageID>");
else
// System.out.println("被当前消息所替换的消息的标识符MessageID 不许为空!");
log.warn("SOAPEncoder.encodeMessage():被当前消息所替换的消息的标识符MessageID 不许为空!");
if (replaceReq.isServiceCodeExist())
sb.append("<ServiceCode>" + replaceReq.getServiceCode() + "</ServiceCode>");
if (replaceReq.isTimeStampExist())
sb.append("<TimeStamp>" + sdf.format(replaceReq.getTimeStamp()) + "</TimeStamp>");
if (replaceReq.isEarliestDeliveryTimeExist()) {
String earliestTime = sdf.format(new Date(replaceReq.getEarliestDeliveryTimeRelative())) + "+08:00";
sb.append("<EarliestDeliveryTime>" + earliestTime + "</EarliestDeliveryTime>");
}
if (replaceReq.isEarliestDeliveryTimeAbsoluteExist())
sb.append("<EarliestDeliveryTime>" + sdf.format(replaceReq.getEarliestDeliveryTimeAbsolute())
+ "+08:00" + "</EarliestDeliveryTime>");
if (replaceReq.isReadReplyExist())
sb.append("<ReadReply>" + replaceReq.getReadReply() + "</ReadReply>");
if (replaceReq.isDistributionIndicatorExist())
sb.append("<DistributionIndicator>" + replaceReq.getDistributionIndicator()
+ "</DistributionIndicator>");
if (replaceReq.isContentExist()) {
/*
* if(replaceReq.getContent().isContentIDExist())
* sb.append("<Content
* href=\"cid:"+replaceReq.getContent().getContentID()+"\"");
* if(replaceReq.isAllowAdaptationsExist())
* sb.append(";allowAdaptions=\"True\"/>"); else
* sb.append("/>");
*/// ;allowAdaptions=\"False\"*/
sb.append("</ReplaceReq>");
sb.append("</env:Body></env:Envelope>" + "\r\n");
sb.append("----NextPart_0_2817_24856\r\n");
MMContent parentContent = replaceReq.getContent();
if (parentContent.getContentType() != null) {
/*
* sb.append("Content-Type:" +
* parentContent.getContentType().getPrimaryType() +"/"
* +parentContent.getContentType().getSubType()+
* ";boundary=\"SubPart_7452684322002_77645\"" +
* "\r\n");
*/
String strSubType = "";
String strtempID = "<START>";
strSubType = parentContent.getContentType().getSubType();
if (strSubType.equalsIgnoreCase("related")) {
if (parentContent.isMultipart()) {
List tempSub = new ArrayList();
tempSub = parentContent.getSubContents();
for (int x = 0; x < tempSub.size(); x++) {
MMContent tempCon = (MMContent) tempSub.get(x);
if (tempCon.getContentType().getSubType().equalsIgnoreCase("smil")) {
if (tempCon.isContentIDExist())
strtempID = tempCon.getContentID();
else
strtempID = "<START>";
break;
}
}
}
sb.append("Content-Type:" + "multipart/related;" + "start=\"" + strtempID
+ "\";type=\"application/smil\"" + ";boundary=\"SubPart_7452684322002_77645\""
+ "\r\n");
}
else {
sb.append("Content-Type:" + parentContent.getContentType().getPrimaryType() + "/"
+ parentContent.getContentType().getSubType()
+ ";boundary=\"SubPart_7452684322002_77645\"" + "\r\n");
}
}
else {
sb.append("Content-Type:" + "multipart/mixed" + ";boundary=\"SubPart_7452684322002_77645\""
+ "\r\n");
}
sb.append("Content-Transfer-Encoding:8bit" + "\r\n");
if (parentContent.isContentIDExist())
sb.append("Content-ID:" + parentContent.getContentID() + "\r\n");
else
sb.append("Content-ID:<SaturnPics-01020930>" + "\r\n");
if (parentContent.isContentLocationExist())
sb.append("Content-Location:" + parentContent.getContentLocation() + "\r\n");
sb.append("\r\n");
ByteArrayOutputStream Subbaos = new ByteArrayOutputStream();
if (parentContent.isMultipart()) {
List subContent = new ArrayList();
subContent = parentContent.getSubContents();
for (int i = 0; i < subContent.size(); i++) {
ContentBuffer = new StringBuffer();
ContentBuffer.append("----SubPart_7452684322002_77645" + "\r\n");
MMContent content = (MMContent) subContent.get(i);
if (content.getContentType() != null)
ContentBuffer.append("Content-Type:" + content.getContentType().getPrimaryType() + "/"
+ content.getContentType().getSubType() + "\r\n");
else {
if (content.isContentIDExist()) {
String strContentID = content.getContentID();
int index = strContentID.indexOf(".");
String type = strContentID.substring(index + 1);
type = type.toLowerCase();
if (type.equals("txt")) {
ContentBuffer.append("Content-Type:text/plain" + "\r\n");
}
else if (type.equals("jpg")) {
ContentBuffer.append("Content-Type:image/jpeg" + "\r\n");
}
else if (type.equals("gif")) {
ContentBuffer.append("Content-Type:image/gif" + "\r\n");
}
}
}
ContentBuffer.append("Content-Transfer-Encoding:8bit" + "\r\n");
if (content.isContentIDExist())
ContentBuffer.append("Content-ID:" + content.getContentID() + "\r\n");
if (content.isContentLocationExist())
ContentBuffer.append("Content-Location:" + content.getContentLocation() + "\r\n");
ContentBuffer.append("\r\n");
try {
Subbaos.write(ContentBuffer.toString().getBytes());
Subbaos.write(content.getContent());
Subbaos.write("\r\n\r\n".getBytes());
}
catch (IOException e) {
e.printStackTrace();
}
}
Subbaos.write("--SubPart_7452684322002_77645--\r\n".getBytes());
Subbaos.write("----NextPart_0_2817_24856--".getBytes());
byteOutput.write(sb.toString().getBytes());
byteOutput.write(Subbaos.toByteArray());
}
}
else {
sb.append("</ReplaceReq>");
sb.append("</env:Body></env:Envelope>");
// Cancel by hudm 2004-06-21
// sb.append("----NextPart_0_2817_24856--");
// end Cancel by hudm 2004-06-21
byteOutput.write(sb.toString().getBytes());
}
}
bEncoder = true;
}
catch (Exception e) {
// System.err.println(e);
log.error("SOAPEncoder.encodeMessage():"+e);
}
}
/** 进行BASE64编码 */
public static String getBASE64(String value) {
if (value == null)
return null;
BASE64Encoder BaseEncode = new BASE64Encoder();
return (BaseEncode.encode(value.getBytes()));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -