MessageFactory factory = MessageFactory.newInstance();
SOAPMessage request = factory.createMessage(null,
new ByteArrayInputStream(msg.getBytes()));
// Add the Attachment
AttachmentPart ap = request.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
ap.setContentId(SoapMessageProvider.ID);
request.addAttachmentPart(ap);
TestLogger.logger.debug("Request Message:");
request.writeTo(System.out);
// Dispatch
TestLogger.logger.debug(">> Invoking SourceMessageProviderDispatch");
SOAPMessage response = dispatch.invoke(request);
// Check assertions and get the data element
SOAPElement dataElement = assertResponseXML(response, SoapMessageProvider.XML_ATTACHMENT_RESPONSE);
assertTrue(countAttachments(response) == 1);
// Get the Attachment
AttachmentPart attachmentPart = (AttachmentPart) response.getAttachments().next();
// Check the attachment
StreamSource contentSS = (StreamSource) attachmentPart.getContent();
String content = SoapMessageProvider.getAsString(contentSS);
assertTrue(content != null);
assertTrue(content.contains(SoapMessageProvider.TEXT_XML_ATTACHMENT));
// Print out the response