private void copyAttachments(MimeMessage source, MimeMessage target) { for (Iterator<Attachment> attachments = source.getAttachments(); attachments.hasNext(); ) { Attachment attachment = attachments.next(); target.addAttachment(attachment.getContentId(), attachment.getDataHandler()); } }
/** * Static construction method from Spring mime attachment. * @param attachment * @return */ public static SoapAttachment from(Attachment attachment) { SoapAttachment soapAttachment = new SoapAttachment(); String contentId = attachment.getContentId(); if (contentId.startsWith("<") && contentId.endsWith(">")) { contentId = contentId.substring(1, contentId.length() - 1); } soapAttachment.setContentId(contentId); soapAttachment.setContentType(attachment.getContentType()); if (attachment.getContentType().startsWith("text")) { try { soapAttachment.setContent(FileUtils.readToString(attachment.getInputStream()).trim()); } catch (IOException e) { throw new CitrusRuntimeException("Failed to read SOAP attachment content", e); } } else { // Binary content soapAttachment.setDataHandler(attachment.getDataHandler()); } soapAttachment.setCharsetName(Citrus.CITRUS_FILE_ENCODING); return soapAttachment; }
@Override public DataHandler getAttachment(String contentId) { Attachment attachment = mimeMessage.getAttachment(contentId); return attachment != null ? attachment.getDataHandler() : null; } }
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "addTodoEntryRequest") @ResponsePayload public AddTodoEntryResponse addTodoEntry(@RequestPayload AddTodoEntryRequest request, MessageContext messageContext) { TodoEntry entry = new TodoEntry(request.getTitle(), request.getDescription()); Iterator<org.springframework.ws.mime.Attachment> it = ((SoapMessage)messageContext.getRequest()).getAttachments(); if (it.hasNext()) { org.springframework.ws.mime.Attachment attachment = it.next(); Attachment todoAttachment = new Attachment(); String contentId = attachment.getContentId(); if (contentId.startsWith("<") && contentId.endsWith(">")) { contentId = contentId.substring(1, contentId.length() - 1); } todoAttachment.setCid(contentId); todoAttachment.setContentType(attachment.getContentType()); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); FileCopyUtils.copy(attachment.getInputStream(), out); todoAttachment.setData(Base64.getEncoder().encodeToString(out.toByteArray())); } catch (IOException e) { throw new RuntimeException("Failed to read attachment", e); } entry.setAttachment(todoAttachment); } todoListService.addEntry(entry); AddTodoEntryResponse response = new AddTodoEntryResponse(); response.setSuccess(true); return response; }
private void copySoapAttachments(final TestContext context, final org.springframework.ws.soap.SoapMessage soapRequest, final SoapMessage soapMessage) { for (final Attachment attachment : soapMessage.getAttachments()) { String contentId = context.replaceDynamicContentInString(attachment.getContentId()); if (!contentId.startsWith("<")) { contentId = "<" + contentId + ">"; } if (log.isDebugEnabled()) { log.debug(String.format("Adding attachment to SOAP message: '%s' ('%s')", contentId, attachment.getContentType())); } soapRequest.addAttachment(contentId, attachment::getInputStream, attachment.getContentType()); } }
assertEquals("text/plain", myAttachment.getContentType()); assertEquals("my_data", FileCopyUtils.copyToString(new InputStreamReader(myAttachment.getInputStream())));
controlAttachment.getContentId().equals(attachment.getContentId())) { matching = attachment;
@Override public DataHandler getAttachment(String contentId) { Attachment attachment = mimeMessage.getAttachment(contentId); return attachment != null ? attachment.getDataHandler() : null; } }
/** * Populates message attachments from soap response attachments * @param inOrOut {@link Message} * @param soapMessage {@link SoapMessage} */ private void populateMessageAttachmentsFromResponse(Message inOrOut, Iterator<Attachment> attachments) { while (attachments.hasNext()) { Attachment attachment = attachments.next(); inOrOut.getAttachments().put(attachment.getContentId(), attachment.getDataHandler()); } }
@Override public DataHandler getAttachment(String contentId) { Attachment attachment = mimeMessage.getAttachment(contentId); return attachment != null ? attachment.getDataHandler() : null; } }
private void extractAttachmentsFromRequest(final WebServiceMessage request, final SpringWebserviceMessage inMessage) { if (request instanceof MimeMessage) { Iterator<Attachment> attachmentsIterator = ((MimeMessage)request).getAttachments(); while (attachmentsIterator.hasNext()) { Attachment attachment = attachmentsIterator.next(); inMessage.addAttachment(attachment.getContentId(), attachment.getDataHandler()); } } }
public DataHandler getAttachment(String contentId) { Attachment attachment = mimeMessage.getAttachment(contentId); return attachment != null ? attachment.getDataHandler() : null; } }