@Test
public void testXMLAttachmentContentEncryptionExternalReferenceList() throws Exception {
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecEncrypt encrypt = new WSSecEncrypt();
encrypt.setUserInfo("receiver", "default");
encrypt.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
List<WSEncryptionPart> parts = new ArrayList<WSEncryptionPart>();
parts.add(new WSEncryptionPart("Body", "http://schemas.xmlsoap.org/soap/envelope/", "Content"));
parts.add(new WSEncryptionPart("cid:Attachments", "Content"));
encrypt.setParts(parts);
String attachmentId = UUID.randomUUID().toString();
final Attachment attachment = new Attachment();
attachment.setMimeType("text/xml");
attachment.addHeaders(getHeaders(attachmentId));
attachment.setId(attachmentId);
attachment.setSourceStream(new ByteArrayInputStream(SOAPUtil.SAMPLE_SOAP_MSG.getBytes("UTF-8")));
AttachmentCallbackHandler attachmentCallbackHandler =
new AttachmentCallbackHandler(Collections.singletonList(attachment));
List<Attachment> encryptedAttachments = attachmentCallbackHandler.getResponseAttachments();
encrypt.setAttachmentCallbackHandler(attachmentCallbackHandler);
encrypt.prepare(doc, CryptoFactory.getInstance("transmitter-crypto.properties"));
Element refs = encrypt.encryptForRef(null, parts);
encrypt.addAttachmentEncryptedDataElements(secHeader);
encrypt.addExternalRefElement(refs, secHeader);
encrypt.prependToHeader(secHeader);
NodeList references = doc.getElementsByTagNameNS(WSConstants.ENC_NS, "DataReference");
Assert.assertEquals(2, references.getLength());
NodeList cipherReferences = doc.getElementsByTagNameNS(WSConstants.ENC_NS, "CipherReference");
Assert.assertEquals(1, cipherReferences.getLength());