Search in sources :

Example 26 with CAS4

use of com.helger.phase4.CAS4 in project phase4 by phax.

the class AS4_NETFuncTest method testSendToAS4_NET.

@Test
public void testSendToAS4_NET() 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(m_aESENSOneWayPMode.getID(), 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 27 with CAS4

use of com.helger.phase4.CAS4 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 28 with CAS4

use of com.helger.phase4.CAS4 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 29 with CAS4

use of com.helger.phase4.CAS4 in project phase4 by phax.

the class CEFProfileTest method testUserMessageFinalRecipientButNoOriginalSender.

@Test
public void testUserMessageFinalRecipientButNoOriginalSender() throws Exception {
    final Ebms3MessageProperties aEbms3MessageProperties = new Ebms3MessageProperties();
    final ICommonsList<Ebms3Property> aEbms3Properties = AS4TestConstants.getEBMSProperties();
    aEbms3Properties.removeIf(x -> x.getName().equals(CAS4.ORIGINAL_SENDER));
    assertEquals(1, aEbms3Properties.size());
    aEbms3Properties.add(_createRandomProperty());
    aEbms3MessageProperties.setProperty(aEbms3Properties);
    m_aEbms3UserMessage.setMessageProperties(aEbms3MessageProperties);
    final Document aDoc = AS4UserMessage.create(m_eSoapVersion, m_aEbms3UserMessage).setMustUnderstand(true).getAsSoapDocument(m_aPayload);
    sendPlainMessageAndWait(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), false, "'originalSender' property is empty or not existant but mandatory");
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Test(org.junit.Test)

Example 30 with CAS4

use of com.helger.phase4.CAS4 in project phase4 by phax.

the class CEFProfileTest method before.

@Before
public void before() {
    m_eSoapVersion = ESoapVersion.AS4_DEFAULT;
    m_aEbms3UserMessage = new Ebms3UserMessage();
    // Default Payload for testing
    m_aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
    if (m_aPayload == null)
        LOGGER.warn("SOAPBodyPayload.xml could not be found no payload attached in PModeCheckTest setup");
    m_aEbms3UserMessage.setPayloadInfo(MessageHelperMethods.createEbms3PayloadInfo(m_aPayload != null, null));
    // Default MessageInfo for testing
    m_aEbms3UserMessage.setMessageInfo(MessageHelperMethods.createEbms3MessageInfo());
    // Default CollaborationInfo for testing
    m_aEbms3UserMessage.setCollaborationInfo(MessageHelperMethods.createEbms3CollaborationInfo(DEFAULT_PARTY_ID + "12-" + DEFAULT_PARTY_ID + "12", DEFAULT_AGREEMENT, null, CAS4.DEFAULT_SERVICE_URL, CAS4.DEFAULT_ACTION_URL, AS4TestConstants.TEST_CONVERSATION_ID));
    // Default PartyInfo for testing
    m_aEbms3UserMessage.setPartyInfo(MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, DEFAULT_PARTY_ID, CAS4.DEFAULT_RESPONDER_URL, DEFAULT_PARTY_ID));
    // Default MessageProperties for testing
    m_aEbms3UserMessage.setMessageProperties(createDefaultProperties());
    AS4ProfileSelector.setCustomAS4ProfileID(AS4CEFProfileRegistarSPI.AS4_PROFILE_ID);
}
Also used : Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Before(org.junit.Before)

Aggregations

Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)20 Ebms3Property (com.helger.phase4.ebms3header.Ebms3Property)20 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)18 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)18 Ebms3PayloadInfo (com.helger.phase4.ebms3header.Ebms3PayloadInfo)18 Nonnull (javax.annotation.Nonnull)16 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)15 Test (org.junit.Test)14 Document (org.w3c.dom.Document)14 HttpXMLEntity (com.helger.phase4.http.HttpXMLEntity)12 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)12 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)11 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)10 PMode (com.helger.phase4.model.pmode.PMode)9 Node (org.w3c.dom.Node)8 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)5 PModeLeg (com.helger.phase4.model.pmode.leg.PModeLeg)5 Before (org.junit.Before)5 Ebms3From (com.helger.phase4.ebms3header.Ebms3From)4 Ebms3To (com.helger.phase4.ebms3header.Ebms3To)4