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


Java AttachmentPart.addMimeHeader方法代码示例

本文整理汇总了Java中javax.xml.soap.AttachmentPart.addMimeHeader方法的典型用法代码示例。如果您正苦于以下问题:Java AttachmentPart.addMimeHeader方法的具体用法?Java AttachmentPart.addMimeHeader怎么用?Java AttachmentPart.addMimeHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.soap.AttachmentPart的用法示例。


在下文中一共展示了AttachmentPart.addMimeHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addAttachmentsToSOAPMessage

import javax.xml.soap.AttachmentPart; //导入方法依赖的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

示例2: addRequestPayload

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
@Override
public boolean addRequestPayload(Payload [] payloads){
	if (this.request == null)
		return false;

	for (int i = 0; i < payloads.length; i++){
		if (payloads[i] != null){
			AttachmentPart ap = this.request.createAttachmentPart();
			if (ap != null){
				// Create file datasource.							
				FileDataSource fileDS = new FileDataSource(new File(payloads[i].getFilePath()));
				ap.setDataHandler(new DataHandler(fileDS));
				ap.setContentType(payloads[i].getContentType());
				ap.addMimeHeader("Content-Disposition", "attachment; filename=" + fileDS.getName());
				this.request.addAttachmentPart(ap);
				if (this.log != null){
					this.log.info(fileDS.getName());
					this.log.info("Adding Payload " + i + " " + payloads[i].getFilePath());
				}
			} else{
				if (this.log != null){
					this.log.error("Unable to create attachment part in SOAP request at :" + i);
				}
			}
		}
	}
	this.setRequestDirty(true);
	return true;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:30,代码来源:AS2MessageSender.java

示例3: addAttachment

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
public static void addAttachment(SOAPMessage soapMessage,String contentId,String contentType,InputStream content,Map<String,String> headers) throws Exception {
        AttachmentPart attachmentPart = soapMessage.createAttachmentPart();
        //attachmentPart.setContentId(encodeContentId(contentId));
        attachmentPart.setMimeHeader("Content-ID",encodeContentId(contentId));
//        attachmentPart.setMimeHeader("Content-ID",contentId);
        attachmentPart.setContentType(contentType);
        attachmentPart.setRawContent(content,contentType);
        for(Map.Entry<String,String> header : headers.entrySet()) {
            attachmentPart.addMimeHeader(header.getKey(), header.getValue());
        }
        soapMessage.addAttachmentPart(attachmentPart);
        soapMessage.saveChanges();
        soapMessage.getMimeHeaders().setHeader("Content-Type",soapMessage.getMimeHeaders().getHeader("Content-Type")[0] + "; start=\"<[email protected]>\"");

    }
 
开发者ID:jentrata,项目名称:jentrata,代码行数:16,代码来源:EbmsUtils.java

示例4: testSendReceiveMessageWithAttachment

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
@Validated @Test
public void testSendReceiveMessageWithAttachment() throws Exception {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage request = mf.createMessage();

    //create the SOAPPart
    createSOAPPart(request);

    //Attach a text/plain object with the SOAP request
    String sampleMessage = "Sample Message: Hello World!";
    AttachmentPart textAttach = request.createAttachmentPart(sampleMessage, "text/plain");
    textAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
    textAttach.setContentId("[email protected]");
    request.addAttachmentPart(textAttach);

    //Attach a java.awt.Image object to the SOAP request
    DataHandler imageDH = new DataHandler(TestUtils.getTestFileAsDataSource("axis2.jpg"));
    AttachmentPart jpegAttach = request.createAttachmentPart(imageDH);
    jpegAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
    jpegAttach.setContentId("[email protected]");
    jpegAttach.setContentType("image/jpg");
    request.addAttachmentPart(jpegAttach);

    SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage response = sCon.call(request, getAddress());

    assertEquals(2, response.countAttachments());

    Iterator attachIter = response.getAttachments();

    int i = 0;
    while (attachIter.hasNext()) {
        AttachmentPart attachment = (AttachmentPart)attachIter.next();
        final Object content = attachment.getDataHandler().getContent();
        if (content instanceof String) {
            assertEquals(sampleMessage, (String)content);
        } else if (content instanceof ByteArrayInputStream) {
            ByteArrayInputStream bais = (ByteArrayInputStream)content;
            byte[] b = new byte[15000];
            final int lengthRead = bais.read(b);
            FileOutputStream fos =
                    new FileOutputStream(new File(System.getProperty("basedir", ".") + "/" +
                            "target/test-resources/result" + (i++) + ".jpg"));
            fos.write(b, 0, lengthRead);
            fos.flush();
            fos.close();

            assertTrue(attachment.getContentType().equals("image/jpeg")
                    || attachment.getContentType().equals("text/plain"));
        }
    }

    sCon.close();

}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:56,代码来源:IntegrationTest.java


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