// The attachments are sent out of order.
// The receiver should be smart enough to use the content id
// to establish the correct order
ByteArrayInputStream bais2 = new ByteArrayInputStream(bytes2);
AttachmentPart attachment2 = request.createAttachmentPart();
attachment2.setContentId("jpegImage2Request=SWAMTOMTestSOAPMessage");
attachment2.addMimeHeader("FVT-source", "STR_BODY_ELEMENT_1");
attachment2.setRawContent(bais2, "text/plain");
request.addAttachmentPart(attachment2);
ByteArrayInputStream bais1 = new ByteArrayInputStream(bytes1);
AttachmentPart attachment1 = request.createAttachmentPart();
attachment1.setContentId("jpegImage1Request=SWAMTOMTestSOAPMessage");
attachment1.addMimeHeader("FVT-source", "STR_BODY_ELEMENT_1");
attachment1.setRawContent(bais1, "text/plain");
request.addAttachmentPart(attachment1);
// invoke
SOAPMessage reply = dispatch.invoke(request);
// iterate over the attachments, there should only be one
Iterator it = reply.getAttachments();
AttachmentPart ap3 = null;
// verify that the attachment is not null or empty
if ((ap3 = (AttachmentPart) it.next()) == null){
fail("Attachment is null");
}
// Make sure the content id starts with the appropriate SWA name
if (!ap3.getContentId().startsWith("jpegImage1Response=")) {
fail("Expected content id to start with jpegImage1Response");
}
AttachmentPart ap4 = null;
// verify that the second attachment is not null or empty
if ((ap4 = (AttachmentPart) it.next()) == null){
fail("Attachment is null");
}
// Make sure the content id starts with the appropriate SWA name
if (!ap4.getContentId().startsWith("jpegImage2Response=")) {
fail("Expected content id to start with jpegImage2Response");
}
if (it.hasNext()){
fail("Detected more then 2 attachment");
}
SOAPBody sb = reply.getSOAPBody();
if (sb.getChildElements().hasNext()) {
fail("Message contains soap:body payload");
}
byte[] bytes3 = ap3.getRawContentBytes();
if (bytes3.length == 0) {
fail("Attachment is empty");
}
if (bytes3[0] != '3') {
fail("The response attachment is not correct");
}
byte[] bytes4 = ap4.getRawContentBytes();
if (bytes4.length == 0) {
fail("Attachment is empty");
}
if (bytes4[0] != '4') {
fail("The response attachment is not correct");