Search in sources :

Example 41 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.

the class HolodeckFuncTest method testSendToHolodeck.

@Test
public void testSendToHolodeck() 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));
    // New message ID
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(false, aAttachments);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(true ? null : m_aESENSOneWayPMode.getID(), true ? null : DEFAULT_AGREEMENT, COLLABORATION_INFO_SERVICE_TYPE, COLLABORATION_INFO_SERVICE, COLLABORATION_INFO_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, "phase4-sender", CAS4.DEFAULT_RESPONDER_URL, TO_PARTY_ID);
    // Add properties
    final ICommonsList<Ebms3Property> aEbms3Properties = new CommonsArrayList<>(MessageHelperMethods.createEbms3Property(CAS4.ORIGINAL_SENDER, null, "C1"), MessageHelperMethods.createEbms3Property(CAS4.FINAL_RECIPIENT, null, "C4"));
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property("trackingidentifier", "tracker"));
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final AS4UserMessage aUserMsg = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, m_eSoapVersion).setMustUnderstand(true);
    // Sign payload document
    final Document aSignedDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aUserMsg.getAsSoapDocument(), m_eSoapVersion, aUserMsg.getMessagingID(), aAttachments, s_aResMgr, false, AS4SigningParams.createDefault());
    final AS4MimeMessage aMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, aSignedDoc, aAttachments);
    sendMimeMessage(new HttpMimeMessageEntity(aMsg), true, null);
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Document(org.w3c.dom.Document) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Test(org.junit.Test)

Example 42 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.

the class UserMessageOneAttachmentTest method testUserMessageOneAttachmentMimeSuccess.

@Test
public void testUserMessageOneAttachmentMimeSuccess() 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 AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSOAPVersion, aMsg.getAsSoapDocument(), aAttachments);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
}
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) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 43 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.

the class UserMessageOneAttachmentTest method testUserMessageOneAttachmentSignedMimeSuccess.

@Test
public void testUserMessageOneAttachmentSignedMimeSuccess() 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 AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSOAPVersion, AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(), m_eSOAPVersion, aMsg.getMessagingID(), aAttachments, s_aResMgr, false, AS4SigningParams.createDefault()), aAttachments);
    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) 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 44 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.

the class AbstractUserMessageTestSetUpExt method modifyUserMessage.

/**
 * Modify the standard user message to try special cases or provoke failure
 * messages.
 *
 * @param sAnotherOrWrongPModeID
 * @param sAnotherOrWrongPartyIdInitiator
 * @param sAnotherOrWrongPartyIdResponder
 * @param aEbms3MessageProperties
 *        Default should be with _defaultProperties(), only if you do not want
 *        them change this
 * @return
 * @throws Exception
 */
@Nonnull
protected static final Document modifyUserMessage(@Nullable final String sAnotherOrWrongPModeID, @Nullable final String sAnotherOrWrongPartyIdInitiator, @Nullable final String sAnotherOrWrongPartyIdResponder, @Nullable final Ebms3MessageProperties aEbms3MessageProperties, @Nullable final ICommonsList<WSS4JAttachment> aAttachments, @Nullable final String sReferenceToMessageID, @Nullable final Consumer<String> aMessagingIDConsumer) throws Exception {
    // If argument is set replace the default one
    final String sSetPartyIDInitiator = sAnotherOrWrongPartyIdInitiator == null ? DEFAULT_PARTY_ID : sAnotherOrWrongPartyIdInitiator;
    final String sSetPartyIDResponder = sAnotherOrWrongPartyIdResponder == null ? DEFAULT_PARTY_ID : sAnotherOrWrongPartyIdResponder;
    Ebms3PayloadInfo aEbms3PayloadInfo;
    Node aPayload = null;
    if (aAttachments == null) {
        aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
        aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, null);
    } else {
        aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(false, aAttachments);
    }
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo(sReferenceToMessageID);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sAnotherOrWrongPModeID, DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, AS4TestConstants.TEST_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, sSetPartyIDInitiator, CAS4.DEFAULT_RESPONDER_URL, sSetPartyIDResponder);
    final AS4UserMessage aMsg = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, ESoapVersion.AS4_DEFAULT).setMustUnderstand(true);
    if (aMessagingIDConsumer != null)
        aMessagingIDConsumer.accept(aMsg.getMessagingID());
    return aAttachments != null ? aMsg.getAsSoapDocument(null) : aMsg.getAsSoapDocument(aPayload);
}
Also used : Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Node(org.w3c.dom.Node) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Nonnull(javax.annotation.Nonnull)

Example 45 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.

the class PModeCheckTest method testPModeLegNullReject.

@Test
public void testPModeLegNullReject() throws Exception {
    final PMode aPMode = MockPModeGenerator.getTestPMode(SOAP_VERSION);
    aPMode.setLeg1(null);
    final IPModeManager aPModeMgr = MetaAS4Manager.getPModeMgr();
    // Needed since different ids set in message and pmode otherwise
    m_aEbms3UserMessage.setCollaborationInfo(MessageHelperMethods.createEbms3CollaborationInfo(aPMode.getInitiatorID() + "-" + aPMode.getResponderID(), DEFAULT_AGREEMENT, null, CAS4.DEFAULT_SERVICE_URL, CAS4.DEFAULT_ACTION_URL, AS4TestConstants.TEST_CONVERSATION_ID));
    try {
        for (final String sPModeID : aPModeMgr.getAllIDs()) {
            aPModeMgr.deletePMode(sPModeID);
        }
        assertTrue(aPModeMgr.getAllIDs().isEmpty());
        aPModeMgr.createOrUpdatePMode(aPMode);
        final AS4UserMessage aMsg = AS4UserMessage.create(SOAP_VERSION, m_aEbms3UserMessage).setMustUnderstand(true);
        final Document aSignedDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(m_aPayload), SOAP_VERSION, aMsg.getMessagingID(), null, s_aResMgr, false, AS4SigningParams.createDefault());
        sendPlainMessageAndWait(new HttpXMLEntity(aSignedDoc, SOAP_VERSION.getMimeType()), false, EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getErrorCode());
    } finally {
        // The MockPModeGenerator generates automatically a PMode, we need
        // too delete it after we are done with the test
        aPModeMgr.deletePMode(aPMode.getID());
    }
}
Also used : IPModeManager(com.helger.phase4.model.pmode.IPModeManager) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) PMode(com.helger.phase4.model.pmode.PMode) Test(org.junit.Test)

Aggregations

AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)46 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)20 Document (org.w3c.dom.Document)20 Test (org.junit.Test)19 IAS4ClientBuildMessageCallback (com.helger.phase4.client.IAS4ClientBuildMessageCallback)17 AbstractAS4Message (com.helger.phase4.messaging.domain.AbstractAS4Message)17 AS4MimeMessage (com.helger.phase4.messaging.mime.AS4MimeMessage)17 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)16 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)16 AS4IncomingDumperFileBased (com.helger.phase4.dump.AS4IncomingDumperFileBased)16 AS4OutgoingDumperFileBased (com.helger.phase4.dump.AS4OutgoingDumperFileBased)16 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)16 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)16 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)16 Ebms3PayloadInfo (com.helger.phase4.ebms3header.Ebms3PayloadInfo)16 HttpMimeMessageEntity (com.helger.phase4.http.HttpMimeMessageEntity)16 ESimpleUserMessageSendResult (com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult)16 File (java.io.File)16 Nonnull (javax.annotation.Nonnull)16 Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)15