use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class MIMETestUtils method createLargeDataSource.
private static final MimeBodyPart createLargeDataSource() {
try {
//Large body. Something bigger then the size of the boundary with folded headers.
final String body = "Has at possim tritani laoreet, vis te meis verear. Vel no vero quando oblique, eu blandit placerat nec, vide facilisi recusabo nec te. Veri labitur sensibus eum id. Quo omnis " + "putant erroribus ad, nonumes copiosae percipit in qui, id cibo meis clita pri. An brute mundi quaerendum duo, eu aliquip facilisis sea, eruditi invidunt dissentiunt eos ea.";
final MimeBodyPart dataPart = new MimeBodyPart();
final ContentType contentType = new ContentType(TEXT_PLAIN_CONTENT_TYPE);
dataPart.setContent(body, contentType.getBaseType());
//Modify the content type header to use folding. We will also use multiple headers that use folding to verify
//the integrity of the reader. Note that the Content-Type header uses parameters which are key/value pairs
//separated by '='. Note that we do not use two consecutive CRLFs anywhere since our implementation
//does not support this.
final StringBuffer contentTypeBuffer = new StringBuffer(contentType.toString());
contentTypeBuffer.append(";\r\n\t\t\t");
contentTypeBuffer.append("parameter1= value1");
contentTypeBuffer.append(";\r\n \t");
contentTypeBuffer.append("parameter2= value2");
//This is a custom header which is folded. It does not use parameters so it's values are separated by commas.
final StringBuffer customHeaderBuffer = new StringBuffer();
customHeaderBuffer.append("CustomValue1");
customHeaderBuffer.append(",\r\n\t \t");
customHeaderBuffer.append("CustomValue2");
customHeaderBuffer.append(",\r\n ");
customHeaderBuffer.append("CustomValue3");
dataPart.setHeader(HEADER_CONTENT_TYPE, contentTypeBuffer.toString());
dataPart.setHeader("AnotherCustomHeader", "AnotherCustomValue");
dataPart.setHeader("FoldedHeader", customHeaderBuffer.toString());
return dataPart;
} catch (Exception exception) {
Assert.fail();
}
return null;
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class MIMETestUtils method createHeaderLessBody.
private static final MimeBodyPart createHeaderLessBody() {
try {
//Header-less body. This has a body but no headers.
final String body = "A body without any headers.";
final MimeBodyPart dataPart = new MimeBodyPart();
final ContentType contentType = new ContentType(TEXT_PLAIN_CONTENT_TYPE);
dataPart.setContent(body, contentType.getBaseType());
return dataPart;
} catch (Exception exception) {
Assert.fail();
}
return null;
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class TestMIMEReader method testMultipleNormalBodiesDataSource.
@Test(dataProvider = "multipleNormalBodiesDataSource")
public void testMultipleNormalBodiesDataSource(final int chunkSize, final List<MimeBodyPart> bodyPartList) throws Exception {
MimeMultipart multiPartMimeBody = new MimeMultipart();
//Add your body parts
for (final MimeBodyPart bodyPart : bodyPartList) {
multiPartMimeBody.addBodyPart(bodyPart);
}
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
multiPartMimeBody.writeTo(byteArrayOutputStream);
final ByteString requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
executeRequestAndAssert(trimTrailingCRLF(requestPayload), chunkSize, multiPartMimeBody);
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class TestMIMEReader method testPreambleAndEpilogue.
//Just test the preamble and epilogue here
@Test(dataProvider = "preambleEpilogueDataSource")
public void testPreambleAndEpilogue(final int chunkSize, final List<MimeBodyPart> bodyPartList, final String preamble, final String epilogue) throws Exception {
MimeMultipart multiPartMimeBody = new MimeMultipart();
//Add your body parts
for (final MimeBodyPart bodyPart : bodyPartList) {
multiPartMimeBody.addBodyPart(bodyPart);
}
if (preamble != null) {
multiPartMimeBody.setPreamble(preamble);
}
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
multiPartMimeBody.writeTo(byteArrayOutputStream);
final ByteString requestPayload;
if (epilogue != null) {
//Javax mail does not support epilogue so we add it ourselves (other then the CRLF following the final
//boundary).
byteArrayOutputStream.write(epilogue.getBytes());
requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
} else {
//Our test desired no epilogue.
//Remove the CRLF introduced by javax mail at the end. We won't want a fake epilogue.
requestPayload = trimTrailingCRLF(ByteString.copy(byteArrayOutputStream.toByteArray()));
}
executeRequestAndAssert(requestPayload, chunkSize, multiPartMimeBody);
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class TestMIMEReader method testAllTypesOfBodiesDataSource.
@Test(dataProvider = "allTypesOfBodiesDataSource")
public void testAllTypesOfBodiesDataSource(final int chunkSize, final List<MimeBodyPart> bodyPartList) throws Exception {
MimeMultipart multiPartMimeBody = new MimeMultipart();
//Add your body parts
for (final MimeBodyPart bodyPart : bodyPartList) {
multiPartMimeBody.addBodyPart(bodyPart);
}
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
multiPartMimeBody.writeTo(byteArrayOutputStream);
final ByteString requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
executeRequestAndAssert(trimTrailingCRLF(requestPayload), chunkSize, multiPartMimeBody);
}
Aggregations