use of com.sun.mail.dsn.DispositionNotification in project nhin-d by DirectProject.
the class MDNFactory_createTest method getNotificationFieldsAsHeaders.
public static InternetHeaders getNotificationFieldsAsHeaders(MimeMultipart mm) {
InternetHeaders retVal = null;
if (mm == null)
throw new IllegalArgumentException("Multipart can not be null");
try {
if (mm.getCount() < 2)
throw new IllegalArgumentException("Multipart can not be null");
// the second part should be the notification
BodyPart part = mm.getBodyPart(1);
if (part.getContent() instanceof DispositionNotification) {
return ((DispositionNotification) part.getContent()).getNotifications();
}
// parse fields
retVal = new InternetHeaders();
String[] fields = Notification.getPartContentBodyAsString(part).split("\r\n");
for (String field : fields) {
int idx = field.indexOf(":");
if (idx > -1) {
String name = field.substring(0, idx);
String value = field.substring(idx + 1).trim();
retVal.setHeader(name, value);
}
}
} catch (Exception e) {
throw new NHINDException("Failed to parse notification fields.", e);
}
return retVal;
}
use of com.sun.mail.dsn.DispositionNotification in project nhin-d by DirectProject.
the class NotificationTest method testCreateNotification_AssertGetParts.
public void testCreateNotification_AssertGetParts() throws Exception {
Notification noti = new Notification(NotificationType.Processed);
ArrayList<MimeEntity> entities = (ArrayList<MimeEntity>) noti.getParts();
MimeEntity entity = entities.get(0);
assertEquals("Your message was successfully processed.", entity.getContent().toString());
entity = entities.get(1);
assertTrue(entity.getContentType().startsWith("message/disposition-notification"));
DispositionNotification notification = (DispositionNotification) entity.getContent();
assertEquals(notification.getNotifications().getHeader("disposition", ","), "automatic-action/MDN-sent-automatically;processed");
}
use of com.sun.mail.dsn.DispositionNotification in project nhin-d by DirectProject.
the class NotificationTest method testCreateNotification_AssertDispatched.
public void testCreateNotification_AssertDispatched() throws Exception {
Notification noti = new Notification(NotificationType.Dispatched);
ArrayList<MimeEntity> entities = (ArrayList<MimeEntity>) noti.getParts();
MimeEntity entity = entities.get(0);
assertEquals("Your message was successfully processed.", entity.getContent().toString());
entity = entities.get(1);
assertTrue(entity.getContentType().startsWith("message/disposition-notification"));
DispositionNotification notification = (DispositionNotification) entity.getContent();
assertEquals(notification.getNotifications().getHeader("disposition", ","), "automatic-action/MDN-sent-automatically;dispatched");
}
use of com.sun.mail.dsn.DispositionNotification in project nhin-d by DirectProject.
the class NotificationTest method testCreateNotification_AssertInputStream.
public void testCreateNotification_AssertInputStream() throws Exception {
Notification noti = new Notification(NotificationType.Processed);
ByteArrayDataSource dataSource = new ByteArrayDataSource(noti.getInputStream(), noti.getAsMultipart().getContentType());
MimeMultipart mm = new MimeMultipart(dataSource);
assertNotNull(mm);
assertEquals(2, mm.getCount());
BodyPart part = mm.getBodyPart(0);
assertTrue(part.getContentType().startsWith("text/plain"));
assertEquals("Your message was successfully processed.", part.getContent().toString());
part = mm.getBodyPart(1);
assertTrue(part.getContentType().startsWith("message/disposition-notification"));
DispositionNotification notification = (DispositionNotification) part.getContent();
assertEquals(notification.getNotifications().getHeader("disposition", ","), "automatic-action/MDN-sent-automatically;processed");
}
Aggregations