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);
}
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));
}
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()));
}
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);
}
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());
}
}
Aggregations