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