use of com.helger.phase4.messaging.mime.SoapMimeMultipart in project phase4 by phax.
the class MimeMessageCreator method generateMimeMessage.
@Nonnull
public static AS4MimeMessage generateMimeMessage(@Nonnull final ESoapVersion eSoapVersion, @Nonnull final Document aSoapEnvelope, @Nullable final ICommonsList<WSS4JAttachment> aEncryptedAttachments) throws MessagingException {
ValueEnforcer.notNull(eSoapVersion, "SoapVersion");
ValueEnforcer.notNull(aSoapEnvelope, "SoapEnvelope");
final Charset aCharset = AS4XMLHelper.XWS.getCharset();
final SoapMimeMultipart aMimeMultipart = new SoapMimeMultipart(eSoapVersion, aCharset);
final EContentTransferEncoding eCTE = EContentTransferEncoding.BINARY;
final String sContentType = eSoapVersion.getMimeType(aCharset).getAsString();
{
// Message Itself (repeatable)
final MimeBodyPart aMessagePart = new MimeBodyPart();
aMessagePart.setDataHandler(new DataHandler(new DOMSource(aSoapEnvelope), sContentType));
aMessagePart.setHeader(CHttpHeader.CONTENT_TRANSFER_ENCODING, eCTE.getID());
aMimeMultipart.addBodyPart(aMessagePart);
}
boolean bIsRepeatable = true;
if (aEncryptedAttachments != null)
for (final WSS4JAttachment aEncryptedAttachment : aEncryptedAttachments) {
aEncryptedAttachment.addToMimeMultipart(aMimeMultipart);
if (!aEncryptedAttachment.isRepeatable())
bIsRepeatable = false;
}
// Build main message
final AS4MimeMessage aMsg = new AS4MimeMessage((Session) null, bIsRepeatable);
aMsg.setContent(aMimeMultipart);
aMsg.saveChanges();
return aMsg;
}
use of com.helger.phase4.messaging.mime.SoapMimeMultipart in project phase4 by phax.
the class UserMessageFailureForgeryTest method testUserMessageEncryptedMimeAttachmentForged.
// Encryption
// Cannot be tested easily, since the error gets only thrown if the SPI tries
// to read the stream of the attachment
// @Ignore
@Test
public void testUserMessageEncryptedMimeAttachmentForged() throws Exception {
final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML_XML)).mimeTypeXML().build(), s_aResMgr));
final AS4MimeMessage aMimeMsg = AS4Encryptor.encryptMimeMessage(m_eSoapVersion, MockMessages.createUserMessageNotSigned(m_eSoapVersion, null, aAttachments).getAsSoapDocument(), aAttachments, m_aCryptoFactory, true, s_aResMgr, m_aCryptParams);
final SoapMimeMultipart aMultipart = (SoapMimeMultipart) aMimeMsg.getContent();
// Since we want to change the attachment
final MimeBodyPart aMimeBodyPart = (MimeBodyPart) aMultipart.getBodyPart(1);
aMimeBodyPart.setContent("Crappy text".getBytes(StandardCharsets.ISO_8859_1), CMimeType.APPLICATION_OCTET_STREAM.getAsString());
aMimeMsg.saveChanges();
sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), false, EEbmsError.EBMS_FAILED_DECRYPTION.getErrorCode());
}
use of com.helger.phase4.messaging.mime.SoapMimeMultipart in project phase4 by phax.
the class UserMessageFailureForgeryTest method testUserMessageWithAttachmentPartInfoOnly.
@Test
public void testUserMessageWithAttachmentPartInfoOnly() throws Exception {
final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_TEST_XML_GZ)).mimeTypeXML().build(), s_aResMgr));
final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, MockMessages.createUserMessageNotSigned(m_eSoapVersion, null, aAttachments).getAsSoapDocument(), aAttachments);
final SoapMimeMultipart aMultipart = (SoapMimeMultipart) aMimeMsg.getContent();
// Since we want to remove the attachment
aMultipart.removeBodyPart(1);
aMimeMsg.saveChanges();
sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), false, EEbmsError.EBMS_EXTERNAL_PAYLOAD_ERROR.getErrorCode());
}
Aggregations