当前位置: 首页>>代码示例>>Java>>正文


Java SOAPMessage.getAttachments方法代码示例

本文整理汇总了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]");
                }
            }
        }

    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:XmlTest.java

示例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 "";
    }
}
 
开发者ID:vrk-kpa,项目名称:xrd4j,代码行数:30,代码来源:AdapterUtils.java


注:本文中的javax.xml.soap.SOAPMessage.getAttachments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。