Search in sources :

Example 26 with AS4MimeMessage

use of com.helger.phase4.messaging.mime.AS4MimeMessage in project phase4 by phax.

the class UserMessageOneAttachmentTest method testUserMessageMimeSignedEncryptedSuccess.

@Test
public void testUserMessageMimeSignedEncryptedSuccess() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)).mimeTypeXML().build(), s_aResMgr));
    final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned(m_eSOAPVersion, null, aAttachments);
    final Document aSignedDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(), m_eSOAPVersion, aMsg.getMessagingID(), aAttachments, s_aResMgr, false, AS4SigningParams.createDefault());
    final AS4MimeMessage aMimeMsg = AS4Encryptor.encryptMimeMessage(m_eSOAPVersion, aSignedDoc, aAttachments, m_aCryptoFactory, false, s_aResMgr, m_aCryptParams);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains(ECryptoAlgorithmSign.SIGN_ALGORITHM_DEFAULT.getAlgorithmURI()));
    assertTrue(sResponse.contains(ECryptoAlgorithmSignDigest.SIGN_DIGEST_ALGORITHM_DEFAULT.getAlgorithmURI()));
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) Document(org.w3c.dom.Document) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 27 with AS4MimeMessage

use of com.helger.phase4.messaging.mime.AS4MimeMessage in project phase4 by phax.

the class UserMessageSoapBodyPayloadTest method testUserMessageSOAPBodyPayloadSignedMimeSuccess.

@Test
public void testUserMessageSOAPBodyPayloadSignedMimeSuccess() throws Exception {
    final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
    final AS4MimeMessage aMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, MockMessages.createUserMessageSigned(m_eSoapVersion, aPayload, null, s_aResMgr), null);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains(AS4TestConstants.NON_REPUDIATION_INFORMATION));
    assertTrue(sResponse.contains(ECryptoAlgorithmSign.SIGN_ALGORITHM_DEFAULT.getAlgorithmURI()));
    assertTrue(sResponse.contains(ECryptoAlgorithmSignDigest.SIGN_DIGEST_ALGORITHM_DEFAULT.getAlgorithmURI()));
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) Node(org.w3c.dom.Node) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 28 with AS4MimeMessage

use of com.helger.phase4.messaging.mime.AS4MimeMessage in project phase4 by phax.

the class TwoWayMEPTest method testReceiveUserMessageWithMimeAsResponseSuccessWithoutEncryption.

@Test
public void testReceiveUserMessageWithMimeAsResponseSuccessWithoutEncryption() throws Exception {
    m_aPMode.getLeg2().getSecurity().setX509EncryptionAlgorithm(null);
    MetaAS4Manager.getPModeMgr().createOrUpdatePMode(m_aPMode);
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML_XML)).mimeTypeXML().build(), s_aResMgr));
    final Document aDoc = modifyUserMessage(m_aPMode.getID(), null, null, createDefaultProperties(), aAttachments, null, null);
    final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, aDoc, aAttachments);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.USERMESSAGE_ASSERTCHECK));
    assertFalse(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains(m_aPMode.getLeg2().getSecurity().getX509SignatureAlgorithm().getAlgorithmURI()));
    // Checking if he adds the attachment to the response message, the mock spi
    // just adds the xml that gets sent in the original message and adds it to
    // the response
    assertTrue(sResponse.contains("<dummy>This is a test XML</dummy>"));
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) Document(org.w3c.dom.Document) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 29 with AS4MimeMessage

use of com.helger.phase4.messaging.mime.AS4MimeMessage in project phase4 by phax.

the class AS4CEFOneWayFuncTest method testAS4_TA28.

/**
 * Note: Only when using SBDH<br>
 * Prerequisite:<br>
 * SMSH and RMSH are configured to exchange AS4 messages according to the
 * e-SENS profile (One-Way/Push MEP). Producer submits two payloads, first
 * being an SBDH document, second being an actual payload (non-XML payload).
 * SMSH sends an AS4 User Message to the RMSH.<br>
 * <br>
 * Predicate: <br>
 * Message has two additional MIME parts. The first mime part is the SBDH
 * document and the second is the actual payload
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testAS4_TA28() 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));
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)).mimeType(CMimeType.IMAGE_JPG).build(), s_aResMgr));
    final AS4MimeMessage aMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, MockMessages.createUserMessageNotSigned(m_eSoapVersion, null, aAttachments).getAsSoapDocument(), aAttachments);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 30 with AS4MimeMessage

use of com.helger.phase4.messaging.mime.AS4MimeMessage in project phase4 by phax.

the class AS4CEFOneWayFuncTest method testAS4_TA13.

/**
 * Prerequisite:<br>
 * SMSH and RMSH are configured to exchange AS4 messages according to the
 * e-SENS profile (One-Way/Push MEP). SMSH is simulated to send an AS4 User
 * Message with compressed but damaged payloads. The SMSH sends the AS4 User
 * Message to the RMSH.<br>
 * <br>
 * Predicate: <br>
 * The RMSH sends back a synchronous error response with error code "Code =
 * EBMS:0303, Short Description = DecompressionFailure, Severity = Failure,
 * Category = Communication".
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testAS4_TA13() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    final WSS4JAttachment aAttachment = WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML_XML)).mimeTypeXML().compressionGZIP().build(), s_aResMgr);
    aAttachment.setCharset(StandardCharsets.UTF_8);
    aAttachments.add(aAttachment);
    final AS4UserMessage aMsg = createTestUserMessageSoapNotSigned(m_aPayload, aAttachments);
    // Damaged payload: txt file
    aAttachments.get(0).setSourceStreamProvider(new ClassPathResource("attachment/CompressedPayload.txt"));
    final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, aMsg.getAsSoapDocument(m_aPayload), aAttachments);
    sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), false, EEbmsError.EBMS_DECOMPRESSION_FAILURE.getErrorCode());
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Aggregations

AS4MimeMessage (com.helger.phase4.messaging.mime.AS4MimeMessage)46 HttpMimeMessageEntity (com.helger.phase4.http.HttpMimeMessageEntity)43 Test (org.junit.Test)42 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)39 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)37 Document (org.w3c.dom.Document)22 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)16 Nonnull (javax.annotation.Nonnull)5 IStringMap (com.helger.commons.collection.attr.IStringMap)3 StringMap (com.helger.commons.collection.attr.StringMap)3 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)3 ScopedConfig (com.helger.phase4.ScopedConfig)3 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)3 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)3 Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)3 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)3 Ebms3PayloadInfo (com.helger.phase4.ebms3header.Ebms3PayloadInfo)3 HttpProxyServer (org.littleshoot.proxy.HttpProxyServer)3 DefaultHttpProxyServer (org.littleshoot.proxy.impl.DefaultHttpProxyServer)3 Node (org.w3c.dom.Node)3