本文整理匯總了Java中javax.xml.soap.SOAPMessage.getAttachments方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPMessage.getAttachments方法的具體用法?Java SOAPMessage.getAttachments怎麽用?Java SOAPMessage.getAttachments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPMessage
的用法示例。
在下文中一共展示了SOAPMessage.getAttachments方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import javax.xml.soap.SOAPMessage; //導入方法依賴的package包/類
public void test() throws Exception {
File file = new File("message.xml");
file.deleteOnExit();
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = createMessage(mf);
// Save the soap message to file
try (FileOutputStream sentFile = new FileOutputStream(file)) {
msg.writeTo(sentFile);
}
// See if we get the image object back
try (FileInputStream fin = new FileInputStream(file)) {
SOAPMessage newMsg = mf.createMessage(msg.getMimeHeaders(), fin);
newMsg.writeTo(new ByteArrayOutputStream());
Iterator<?> i = newMsg.getAttachments();
while (i.hasNext()) {
AttachmentPart att = (AttachmentPart) i.next();
Object obj = att.getContent();
if (!(obj instanceof StreamSource)) {
fail("Got incorrect attachment type [" + obj.getClass() + "], " +
"expected [javax.xml.transform.stream.StreamSource]");
}
}
}
}
示例2: getAttachmentsInfo
import javax.xml.soap.SOAPMessage; //導入方法依賴的package包/類
/**
* Returns a string containing info about all the SOAP attachments.
*
* @param soapMessage SOAP message
* @return String containing attachments info
*/
public static String getAttachmentsInfo(SOAPMessage soapMessage) {
try {
int numOfAttachments = soapMessage.countAttachments();
Iterator attachments = soapMessage.getAttachments();
StringBuilder buf = new StringBuilder("Number of attachments: ");
buf.append(numOfAttachments);
int count = 1;
while (attachments.hasNext()) {
AttachmentPart attachment = (AttachmentPart) attachments.next();
buf.append(" | #").append(count);
buf.append(" | Content Location: ").append(attachment.getContentLocation());
buf.append(" | Content Id: ").append(attachment.getContentId());
buf.append(" | Content Size: ").append(attachment.getSize());
buf.append(" | Content Type: ").append(attachment.getContentType());
count++;
}
return buf.toString();
} catch (SOAPException e) {
LOGGER.error(e.getMessage(), e);
return "";
}
}