jpegAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
jpegAttach.setContentId("submitSampleImage@apache.org");
jpegAttach.setContentType("image/jpg");
request.addAttachmentPart(jpegAttach);
SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage response = sCon.call(request, getAddress());
int attachmentCount = response.countAttachments();
assertTrue(attachmentCount == 2);
Iterator attachIter = response.getAttachments();
int i = 0;
while (attachIter.hasNext()) {
AttachmentPart attachment = (AttachmentPart)attachIter.next();
final Object content = attachment.getDataHandler().getContent();
if (content instanceof String) {
assertEquals(sampleMessage, (String)content);
} else if (content instanceof ByteArrayInputStream) {
ByteArrayInputStream bais = (ByteArrayInputStream)content;
byte[] b = new byte[15000];
final int lengthRead = bais.read(b);
FileOutputStream fos =
new FileOutputStream(new File(System.getProperty("basedir", ".") + "/" +
"target/test-resources/result" + (i++) + ".jpg"));
fos.write(b, 0, lengthRead);
fos.flush();
fos.close();
assertTrue(attachment.getContentType().equals("image/jpeg")
|| attachment.getContentType().equals("text/plain"));
}
}
sCon.close();
}