use of javax.mail.MessagingException in project nhin-d by DirectProject.
the class Message method extractMimeEntity.
/**
* Gets a copy of this message without any non-mime headers.
* @returns A copy of this message without any non-mime headers.
*/
@SuppressWarnings("unchecked")
public MimeEntity extractMimeEntity() {
MimeEntity retVal = null;
try {
InternetHeaders headers = new InternetHeaders();
if (this.headers.getAllHeaders().hasMoreElements()) {
Enumeration<javax.mail.Header> hEnum = this.headers.getAllHeaders();
while (hEnum.hasMoreElements()) {
javax.mail.Header hdr = hEnum.nextElement();
if (MimeStandard.startsWith(hdr.getName(), MimeStandard.HeaderPrefix))
headers.addHeader(hdr.getName(), hdr.getValue());
}
if (!headers.getAllHeaders().hasMoreElements()) {
throw new MimeException(MimeError.InvalidMimeEntity);
}
retVal = new MimeEntity(headers, getContentAsBytes());
}
} catch (MessagingException e) {
throw new MimeException(MimeError.InvalidMimeEntity, e);
}
return retVal;
}
use of javax.mail.MessagingException in project nhin-d by DirectProject.
the class Notification method serializeToBytes.
/**
* Serializes the notification to an array of bytes.
* @return byte array serialized form on this notification.
*/
public byte[] serializeToBytes() {
if (report == null)
updateReport();
ByteArrayOutputStream oStream = null;
try {
oStream = new ByteArrayOutputStream();
report.writeTo(oStream);
oStream.flush();
} catch (MessagingException e) {
} catch (IOException e) {
}
return oStream.toByteArray();
}
use of javax.mail.MessagingException in project nhin-d by DirectProject.
the class DefaultNHINDAgent_ProcessOutgoingMessage_Test method testMessageIsWrapped_WrapMessageIsNotCalled.
/**
*
* @throws Exception
*/
public void testMessageIsWrapped_WrapMessageIsNotCalled() throws Exception {
new TestPlan() {
protected OutgoingMessage createMessage() throws Exception {
MimeMessage mimeMsg = new SecondaryMimeMessage();
mimeMsg.setText("");
Message msg = new Message(mimeMsg) {
@Override
public String getContentType() throws MessagingException {
return MailStandard.MediaType.WrappedMessage;
}
};
NHINDAddressCollection recipients = new NHINDAddressCollection();
recipients.add(new NHINDAddress(""));
NHINDAddress sender = new NHINDAddress("");
theCreateMessage = new OutgoingMessage(msg, recipients, sender) {
@Override
protected void categorizeRecipients(TrustEnforcementStatus minTrustStatus) {
categorizeRecipientsCalls++;
categorizeRecipients_Internal(minTrustStatus);
}
};
return theCreateMessage;
}
protected void doAssertions() throws Exception {
assertEquals(0, wrapMessageCalls);
}
}.perform();
}
use of javax.mail.MessagingException in project nhin-d by DirectProject.
the class SMIMECryptographerImpl method decrypt.
/**
* Decrypts an entity with the provided certificates' private key.
* @param encryptedEntity The entity that will be decrypted.
* @param decryptingCertificate The certificates whose private keys will be used to decrypt the message.
* @return A MimeEntity containing the decrypted part.
*/
public MimeEntity decrypt(MimeEntity encryptedEntity, Collection<X509CertificateEx> decryptingCertificates) {
if (decryptingCertificates == null || decryptingCertificates.size() == 0) {
throw new IllegalArgumentException();
}
MimeEntity retEntity = null;
try {
if (LOGGER.isDebugEnabled()) {
final byte[] encryptedContent = encryptedEntity.getContentAsBytes();
writePreDecrypt(encryptedContent);
}
final SMIMEEnveloped m = new SMIMEEnveloped(encryptedEntity);
if (!this.isAllowedEncryptionAlgorithm(m.getEncryptionAlgOID()))
throw new NHINDException(MimeError.DisallowedEncryptionAlgorithm, "The encryption algorithm " + m.getEncryptionAlgOID() + " is not allowed");
for (X509CertificateEx decryptCert : decryptingCertificates) {
final RecipientId recId = generateRecipientSelector(decryptCert);
final RecipientInformationStore recipients = m.getRecipientInfos();
final DirectRecipientInformation recipient = decFactory.createInstance(recipients.get(recId), m);
if (recipient == null)
continue;
final byte[] decryptedPayload = recipient.getDecryptedContent(decryptCert.getPrivateKey());
if (LOGGER.isDebugEnabled()) {
writePostDecrypt(decryptedPayload);
}
final ByteArrayInputStream inStream = new ByteArrayInputStream(decryptedPayload);
retEntity = new MimeEntity(inStream);
break;
}
} catch (MessagingException e) {
throw new MimeException(MimeError.InvalidMimeEntity, e);
} catch (Exception e) {
throw new MimeException(MimeError.Unexpected, e);
}
if (retEntity == null) {
throw new NHINDException(MimeError.Unexpected, "None of the the provided decryption certs were found in message's RecipientsInfo set.");
}
return retEntity;
}
use of javax.mail.MessagingException in project nhin-d by DirectProject.
the class Notification method getInputStream.
/**
* Gets an input stream of this notification that can be serialized.
* @return An input stream of this notification
*/
public InputStream getInputStream() {
if (report == null)
updateReport();
ByteArrayOutputStream oStream = null;
try {
oStream = new ByteArrayOutputStream();
report.writeTo(oStream);
oStream.flush();
} catch (MessagingException e) {
} catch (IOException e) {
}
return new ByteArrayInputStream(oStream.toByteArray());
}
Aggregations