當前位置: 首頁>>代碼示例>>Java>>正文


Java SOAPMessage.addAttachmentPart方法代碼示例

本文整理匯總了Java中javax.xml.soap.SOAPMessage.addAttachmentPart方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPMessage.addAttachmentPart方法的具體用法?Java SOAPMessage.addAttachmentPart怎麽用?Java SOAPMessage.addAttachmentPart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.soap.SOAPMessage的用法示例。


在下文中一共展示了SOAPMessage.addAttachmentPart方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createMessage

import javax.xml.soap.SOAPMessage; //導入方法依賴的package包/類
private SOAPMessage createMessage(MessageFactory mf) throws SOAPException, IOException {
    SOAPMessage msg = mf.createMessage();
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
    Name name = envelope.createName("hello", "ex", "http://example.com");
    envelope.getBody().addChildElement(name).addTextNode("THERE!");

    String s = "<root><hello>THERE!</hello></root>";

    AttachmentPart ap = msg.createAttachmentPart(
            new StreamSource(new ByteArrayInputStream(s.getBytes())),
            "text/xml"
    );
    msg.addAttachmentPart(ap);
    msg.saveChanges();

    return msg;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:XmlTest.java

示例2: writeTo

import javax.xml.soap.SOAPMessage; //導入方法依賴的package包/類
@Override
public void writeTo(SOAPMessage saaj) throws SOAPException {
    AttachmentPart part = saaj.createAttachmentPart();
    part.setDataHandler(asDataHandler());
    part.setContentId(contentId);
    saaj.addAttachmentPart(part);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:JAXBAttachment.java

示例3: addAttachmentsToSOAPMessage

import javax.xml.soap.SOAPMessage; //導入方法依賴的package包/類
static protected void addAttachmentsToSOAPMessage(SOAPMessage msg, Message message) {
    for(Attachment att : message.getAttachments()) {
        AttachmentPart part = msg.createAttachmentPart();
        part.setDataHandler(att.asDataHandler());

        // Be safe and avoid double angle-brackets.
        String cid = att.getContentId();
        if (cid != null) {
            if (cid.startsWith("<") && cid.endsWith(">"))
                part.setContentId(cid);
            else
                part.setContentId('<' + cid + '>');
        }

        // Add any MIME headers beside Content-ID, which is already
        // accounted for above, and Content-Type, which is provided
        // by the DataHandler above.
        if (att instanceof AttachmentEx) {
            AttachmentEx ax = (AttachmentEx) att;
            Iterator<AttachmentEx.MimeHeader> imh = ax.getMimeHeaders();
            while (imh.hasNext()) {
                AttachmentEx.MimeHeader ame = imh.next();
                if ((!"Content-ID".equals(ame.getName()))
                        && (!"Content-Type".equals(ame.getName())))
                    part.addMimeHeader(ame.getName(), ame.getValue());
            }
        }
        msg.addAttachmentPart(part);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:31,代碼來源:SAAJFactory.java

示例4: echoUsingSAAJ

import javax.xml.soap.SOAPMessage; //導入方法依賴的package包/類
/**
 * This method sends a file as an attachment then 
 *  receives it as a return.  The returned file is
 *  compared to the source. Uses SAAJ API.
 *  @param The filename that is the source to send.
 *  @return True if sent and compared.
 */
public boolean echoUsingSAAJ(String filename) throws Exception {
    String endPointURLString =  "http://localhost:" +opts.getPort() + "/axis/services/urn:EchoAttachmentsService";

    SOAPConnectionFactory soapConnectionFactory =
            javax.xml.soap.SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection =
            soapConnectionFactory.createConnection();

    MessageFactory messageFactory =
            MessageFactory.newInstance();
    SOAPMessage soapMessage =
            messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope requestEnvelope =
            soapPart.getEnvelope();
    SOAPBody body = requestEnvelope.getBody();
    SOAPBodyElement operation = body.addBodyElement
            (requestEnvelope.createName("echo"));

    Vector dataHandlersToAdd = new Vector();
    dataHandlersToAdd.add(new DataHandler(new FileDataSource(new
            File(filename))));

    if (dataHandlersToAdd != null) {
        ListIterator dataHandlerIterator =
                dataHandlersToAdd.listIterator();

        while (dataHandlerIterator.hasNext()) {
            DataHandler dataHandler = (DataHandler)
                    dataHandlerIterator.next();
            javax.xml.soap.SOAPElement element =
                    operation.addChildElement(requestEnvelope.createName("source"));
            javax.xml.soap.AttachmentPart attachment =
                    soapMessage.createAttachmentPart(dataHandler);
            soapMessage.addAttachmentPart(attachment);
            element.addAttribute(requestEnvelope.createName
                                 ("href"), "cid:" + attachment.getContentId());
        }
    }
    javax.xml.soap.SOAPMessage returnedSOAPMessage =
            soapConnection.call(soapMessage, endPointURLString);
    Iterator iterator = returnedSOAPMessage.getAttachments();
    if (!iterator.hasNext()) {
        //The wrong type of object that what was expected.
        System.out.println("Received problem response from server");
        throw new AxisFault("", "Received problem response from server", null, null);

    }
    //Still here, so far so good.
    //Now lets brute force compare the source attachment
    // to the one we received.
    DataHandler rdh = (DataHandler) ((AttachmentPart)iterator.next()).getDataHandler();

    //From here we'll just treat the data resource as file.
    String receivedfileName = rdh.getName();//Get the filename. 

    if (receivedfileName == null) {
        System.err.println("Could not get the file name.");
        throw new AxisFault("", "Could not get the file name.", null, null);
    }


    System.out.println("Going to compare the files..");
    boolean retv = compareFiles(filename, receivedfileName);

    java.io.File receivedFile = new java.io.File(receivedfileName);

    receivedFile.delete();

    return retv;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:79,代碼來源:EchoAttachment.java

示例5: addSoapAttachement

import javax.xml.soap.SOAPMessage; //導入方法依賴的package包/類
void addSoapAttachement() {
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        AttachmentPart a = message.createAttachmentPart();
        a.setContentType("binary/octet-stream");
        message.addAttachmentPart(a);
    } catch (SOAPException e) {
        e.printStackTrace();
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:MailTest.java

示例6: writeTo

import javax.xml.soap.SOAPMessage; //導入方法依賴的package包/類
public void writeTo(SOAPMessage saaj) throws SOAPException {
    AttachmentPart part = saaj.createAttachmentPart();
    part.setRawContentBytes(data,0,len,getContentType());
    part.setContentId(contentId);
    saaj.addAttachmentPart(part);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:7,代碼來源:StreamAttachment.java

示例7: writeTo

import javax.xml.soap.SOAPMessage; //導入方法依賴的package包/類
public void writeTo(SOAPMessage saaj) throws SOAPException {
    AttachmentPart part = saaj.createAttachmentPart();
    part.setDataHandler(asDataHandler());
    part.setContentId(contentId);
    saaj.addAttachmentPart(part);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:7,代碼來源:ByteArrayAttachment.java

示例8: writeTo

import javax.xml.soap.SOAPMessage; //導入方法依賴的package包/類
public void writeTo(SOAPMessage saaj) throws SOAPException {
    AttachmentPart part = saaj.createAttachmentPart();
    part.setDataHandler(dh);
    part.setContentId(contentId);
    saaj.addAttachmentPart(part);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:7,代碼來源:DataHandlerAttachment.java


注:本文中的javax.xml.soap.SOAPMessage.addAttachmentPart方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。