for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) ('a' + ('z' - 'a') * Math.random());
}
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
AttachmentPart attachment = request.createAttachmentPart();
// Per WSI Spect, the swa content id must start with the part name
//http://www.ws-i.org/Profiles/AttachmentsProfile-1.0.html#Value-space_of_Content-Id_Header
attachment.setContentId("jpegImageRequest=SWAMTOMTestSOAPMessage");
attachment.addMimeHeader("FVT-source", "STR_BODY_ELEMENT_1");
attachment.setRawContent(bais, "text/plain");
request.addAttachmentPart(attachment);
// invoke
SOAPMessage reply = dispatch.invoke(request);
// iterate over the attachments, there should only be one
Iterator it = reply.getAttachments();
AttachmentPart ap = null;
// verify that the attachment is not null or empty
if ((ap = (AttachmentPart) it.next()) == null){
fail("Attachment is null");
}
// Make sure the content id starts with the appropriate SWA name
if (!ap.getContentId().startsWith("jpegImageResponse=")) {
fail("Expected content id to start with jpegImageResponse");
}
// verify that the attachment is not null or empty
if (it.hasNext()){
fail("Detected more then 1 attachment");
}
SOAPBody sb = reply.getSOAPBody();
if (sb.getChildElements().hasNext()) {
fail("Message contains soap:body payload");
}
bytes = ap.getRawContentBytes();
if (bytes.length == 0) {
fail("Attachment is empty");
}
// verify that endpoint has been able to modify the attachment