/** * Adds attachments if present in soap web service message. * * @param soapMessage the web service message. * @param message the response message builder. */ protected void handleInboundAttachments(final org.springframework.ws.soap.SoapMessage soapMessage, final SoapMessage message) { final Iterator<Attachment> attachments = soapMessage.getAttachments(); while (attachments.hasNext()) { final Attachment attachment = attachments.next(); final SoapAttachment soapAttachment = SoapAttachment.from(attachment); if (log.isDebugEnabled()) { log.debug(String.format("SOAP message contains attachment with contentId '%s'", soapAttachment.getContentId())); } message.addAttachment(soapAttachment); } }
@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; }
/** * Populates soap message headers and attachments from soap response * * @param inOrOut * {@link Message} * @param soapMessage * {@link SoapMessage} */ private void populateHeaderAndAttachmentsFromResponse(Message inOrOut, SoapMessage soapMessage) { if (soapMessage.getSoapHeader() != null && getEndpoint().getConfiguration().isAllowResponseHeaderOverride()) { populateMessageHeaderFromResponse(inOrOut, soapMessage.getSoapHeader()); } if (soapMessage.getAttachments() != null && getEndpoint().getConfiguration().isAllowResponseAttachmentOverride()) { populateMessageAttachmentsFromResponse(inOrOut, soapMessage.getAttachments()); } }