Search in sources :

Example 11 with Ebms3MessageProperties

use of com.helger.phase4.ebms3header.Ebms3MessageProperties in project phase4 by phax.

the class Ebms3MessagingTest method testSendReceipt.

@Test
public void testSendReceipt() throws Exception {
    // Fake an incoming message
    final ICommonsList<Ebms3Property> aEbms3Properties = AS4TestConstants.getEBMSProperties();
    final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, null);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo;
    final String sPModeID = SOAP_12_PARTY_ID + "-" + SOAP_12_PARTY_ID;
    aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sPModeID, 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, SOAP_12_PARTY_ID, CAS4.DEFAULT_RESPONDER_URL, SOAP_12_PARTY_ID);
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final Ebms3UserMessage aEbms3UserMessage = new Ebms3UserMessage();
    aEbms3UserMessage.setPartyInfo(aEbms3PartyInfo);
    aEbms3UserMessage.setPayloadInfo(aEbms3PayloadInfo);
    aEbms3UserMessage.setCollaborationInfo(aEbms3CollaborationInfo);
    aEbms3UserMessage.setMessageProperties(aEbms3MessageProperties);
    aEbms3UserMessage.setMessageInfo(MessageHelperMethods.createEbms3MessageInfo());
    // Now send receipt
    final Document aDoc = MockMessages.createReceiptMessage(ESoapVersion.AS4_DEFAULT, aEbms3UserMessage, null).getAsSoapDocument();
    // We've got our response
    sendPlainMessage(new HttpXMLEntity(aDoc, SOAP_VERSION.getMimeType()), true, null);
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Node(org.w3c.dom.Node) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Test(org.junit.Test)

Example 12 with Ebms3MessageProperties

use of com.helger.phase4.ebms3header.Ebms3MessageProperties in project phase4 by phax.

the class Ebms3MessagingTest method testUserMessageWithTooManyPartyIds.

@Test
public void testUserMessageWithTooManyPartyIds() throws Exception {
    final Ebms3Messaging aEbms3Messaging = new Ebms3Messaging();
    final Ebms3UserMessage aEbms3UserMessage = new Ebms3UserMessage();
    // Message Info
    // Add properties
    final ICommonsList<Ebms3Property> aEbms3Properties = AS4TestConstants.getEBMSProperties();
    final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
    final String sPModeID = SOAP_12_PARTY_ID + "-" + SOAP_12_PARTY_ID;
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, null);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo;
    aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sPModeID, DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, AS4TestConstants.TEST_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
    final Ebms3PartyInfo aEbms3PartyInfo = new Ebms3PartyInfo();
    // From => Sender
    final Ebms3From aEbms3From = new Ebms3From();
    aEbms3From.setRole(CAS4.DEFAULT_INITIATOR_URL);
    aEbms3From.addPartyId(MessageHelperMethods.createEbms3PartyId(SOAP_12_PARTY_ID));
    aEbms3From.addPartyId(MessageHelperMethods.createEbms3PartyId(SOAP_12_PARTY_ID));
    aEbms3PartyInfo.setFrom(aEbms3From);
    // To => Receiver
    final Ebms3To aEbms3To = new Ebms3To();
    aEbms3To.setRole(CAS4.DEFAULT_RESPONDER_URL);
    aEbms3To.addPartyId(MessageHelperMethods.createEbms3PartyId(SOAP_12_PARTY_ID));
    aEbms3PartyInfo.setTo(aEbms3To);
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    aEbms3UserMessage.setPartyInfo(aEbms3PartyInfo);
    aEbms3UserMessage.setPayloadInfo(aEbms3PayloadInfo);
    aEbms3UserMessage.setCollaborationInfo(aEbms3CollaborationInfo);
    aEbms3UserMessage.setMessageProperties(aEbms3MessageProperties);
    aEbms3UserMessage.setMessageInfo(MessageHelperMethods.createEbms3MessageInfo());
    aEbms3Messaging.addUserMessage(aEbms3UserMessage);
    final HttpEntity aEntity = new HttpXMLEntity(_getMessagingAsSoapDocument(aEbms3Messaging), SOAP_VERSION.getMimeType());
    sendPlainMessage(aEntity, false, EEbmsError.EBMS_VALUE_INCONSISTENT.getErrorCode());
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3From(com.helger.phase4.ebms3header.Ebms3From) HttpEntity(org.apache.http.HttpEntity) Node(org.w3c.dom.Node) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Ebms3To(com.helger.phase4.ebms3header.Ebms3To) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) Ebms3Messaging(com.helger.phase4.ebms3header.Ebms3Messaging) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Test(org.junit.Test)

Example 13 with Ebms3MessageProperties

use of com.helger.phase4.ebms3header.Ebms3MessageProperties in project phase4 by phax.

the class MockMessages method createUserMessageNotSigned.

@Nonnull
public static AS4UserMessage createUserMessageNotSigned(@Nonnull final ESoapVersion eSOAPVersion, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aAttachments) {
    // Add properties
    final ICommonsList<Ebms3Property> aEbms3Properties = AS4TestConstants.getEBMSProperties();
    final String sPModeID;
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, aAttachments);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo;
    final Ebms3PartyInfo aEbms3PartyInfo;
    if (eSOAPVersion.equals(ESoapVersion.SOAP_11)) {
        sPModeID = SOAP_11_PARTY_ID + "-" + SOAP_11_PARTY_ID;
        aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sPModeID, DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, MockPModeGenerator.SOAP11_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
        aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, SOAP_11_PARTY_ID, CAS4.DEFAULT_RESPONDER_URL, SOAP_11_PARTY_ID);
    } else {
        sPModeID = SOAP_12_PARTY_ID + "-" + SOAP_12_PARTY_ID;
        aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sPModeID, DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, AS4TestConstants.TEST_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
        aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, SOAP_12_PARTY_ID, CAS4.DEFAULT_RESPONDER_URL, SOAP_12_PARTY_ID);
    }
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    return AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSOAPVersion).setMustUnderstand(true);
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Nonnull(javax.annotation.Nonnull)

Example 14 with Ebms3MessageProperties

use of com.helger.phase4.ebms3header.Ebms3MessageProperties in project phase4 by phax.

the class AS4RequestHandler method _createReversedUserMessage.

/**
 * Takes an UserMessage and switches properties to reverse the direction. So
 * previously it was C1 => C4, now its C4 => C1 Also adds attachments if there
 * are some that should be added.
 *
 * @param eSoapVersion
 *        of the message
 * @param sResponseMessageID
 *        The AS4 message ID of the response
 * @param aUserMessage
 *        the message that should be reversed
 * @param aResponseAttachments
 *        attachment that should be added
 * @return the reversed usermessage in document form
 */
@Nonnull
private static AS4UserMessage _createReversedUserMessage(@Nonnull final ESoapVersion eSoapVersion, @Nonnull @Nonempty final String sResponseMessageID, @Nonnull final Ebms3UserMessage aUserMessage, @Nonnull final ICommonsList<WSS4JAttachment> aResponseAttachments) {
    // Use current time
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo(sResponseMessageID, aUserMessage.getMessageInfo().getMessageId());
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(false, aResponseAttachments);
    // Invert from and to role from original user message
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3ReversePartyInfo(aUserMessage.getPartyInfo());
    // Should be exactly the same as incoming message
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = aUserMessage.getCollaborationInfo();
    // Need to switch C1 and C4 around from the original usermessage
    // TODO make customizable via profile
    final Ebms3MessageProperties aEbms3MessageProperties = new Ebms3MessageProperties();
    {
        Ebms3Property aFinalRecipient = null;
        Ebms3Property aOriginalSender = null;
        for (final Ebms3Property aProp : aUserMessage.getMessageProperties().getProperty()) {
            if (aProp.getName().equals(CAS4.ORIGINAL_SENDER))
                aOriginalSender = aProp;
            else if (aProp.getName().equals(CAS4.FINAL_RECIPIENT))
                aFinalRecipient = aProp;
        }
        if (aOriginalSender == null)
            throw new IllegalStateException("Failed to determine new OriginalSender");
        if (aFinalRecipient == null)
            throw new IllegalStateException("Failed to determine new FinalRecipient");
        aFinalRecipient.setName(CAS4.ORIGINAL_SENDER);
        aOriginalSender.setName(CAS4.FINAL_RECIPIENT);
        aEbms3MessageProperties.addProperty(aFinalRecipient);
        aEbms3MessageProperties.addProperty(aOriginalSender);
    }
    return AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSoapVersion);
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Nonnull(javax.annotation.Nonnull)

Example 15 with Ebms3MessageProperties

use of com.helger.phase4.ebms3header.Ebms3MessageProperties in project phase4 by phax.

the class PeppolCompatibilityValidator method validateUserMessage.

@Override
public void validateUserMessage(@Nonnull final Ebms3UserMessage aUserMsg, @Nonnull final ErrorList aErrorList) {
    ValueEnforcer.notNull(aUserMsg, "UserMsg");
    if (aUserMsg.getMessageInfo() == null) {
        aErrorList.add(_createError("MessageInfo is missing"));
    } else {
        if (StringHelper.hasNoText(aUserMsg.getMessageInfo().getMessageId()))
            aErrorList.add(_createError("MessageInfo/MessageId is missing"));
        {
            // Check if originalSender and finalRecipient are present
            // Since these two properties are mandatory
            final Ebms3MessageProperties aMessageProperties = aUserMsg.getMessageProperties();
            if (aMessageProperties == null)
                aErrorList.add(_createError("MessageProperties is missing but 'originalSender' and 'finalRecipient' properties are required"));
            else {
                final List<Ebms3Property> aProps = aMessageProperties.getProperty();
                if (aProps.isEmpty())
                    aErrorList.add(_createError("MessageProperties/Property must not be empty"));
                else {
                    String sOriginalSenderC1 = null;
                    String sFinalRecipientC4 = null;
                    for (final Ebms3Property sProperty : aProps) {
                        if (sProperty.getName().equals(CAS4.ORIGINAL_SENDER))
                            sOriginalSenderC1 = sProperty.getValue();
                        else if (sProperty.getName().equals(CAS4.FINAL_RECIPIENT))
                            sFinalRecipientC4 = sProperty.getValue();
                    }
                    if (StringHelper.hasNoText(sOriginalSenderC1))
                        aErrorList.add(_createError("MessageProperties/Property '" + CAS4.ORIGINAL_SENDER + "' property is empty or not existant but mandatory"));
                    if (StringHelper.hasNoText(sFinalRecipientC4))
                        aErrorList.add(_createError("MessageProperties/Property '" + CAS4.FINAL_RECIPIENT + "' property is empty or not existant but mandatory"));
                }
            }
        }
    }
    if (aUserMsg.getPartyInfo() == null) {
        aErrorList.add(_createError("PartyInfo is missing"));
    } else {
        final Ebms3From aFrom = aUserMsg.getPartyInfo().getFrom();
        if (aFrom != null) {
            if (aFrom.getPartyIdCount() > 1)
                aErrorList.add(_createError("PartyInfo/From must contain no more than one PartyID"));
            else if (aFrom.getPartyIdCount() == 1) {
                if (!PeppolPMode.DEFAULT_PARTY_TYPE_ID.equals(aFrom.getPartyIdAtIndex(0).getType())) {
                    aErrorList.add(_createError("PartyInfo/From[0]/@type must be '" + PeppolPMode.DEFAULT_PARTY_TYPE_ID + "' instead of '" + aFrom.getPartyIdAtIndex(0).getType() + "'"));
                }
            }
        }
        final Ebms3To aTo = aUserMsg.getPartyInfo().getTo();
        if (aTo != null) {
            if (aTo.getPartyIdCount() > 1)
                aErrorList.add(_createError("PartyInfo/To must contain no more than one PartyID"));
            else if (aTo.getPartyIdCount() == 1) {
                if (!PeppolPMode.DEFAULT_PARTY_TYPE_ID.equals(aTo.getPartyIdAtIndex(0).getType())) {
                    aErrorList.add(_createError("PartyInfo/To[0]/@type must be '" + PeppolPMode.DEFAULT_PARTY_TYPE_ID + "' instead of '" + aTo.getPartyIdAtIndex(0).getType() + "'"));
                }
            }
        }
    }
    if (aUserMsg.getCollaborationInfo() == null) {
        aErrorList.add(_createError("CollaborationInfo is missing"));
    } else {
        final Ebms3AgreementRef aAgreementRef = aUserMsg.getCollaborationInfo().getAgreementRef();
        if (aAgreementRef == null) {
            aErrorList.add(_createError("CollaborationInfo/AgreementRef is missing"));
        } else {
            if (!PeppolPMode.DEFAULT_AGREEMENT_ID.equals(aAgreementRef.getValue()))
                aErrorList.add(_createError("CollaborationInfo/AgreementRef must be '" + PeppolPMode.DEFAULT_AGREEMENT_ID + "' instead of '" + aAgreementRef.getValue() + "'"));
            if (StringHelper.hasText(aAgreementRef.getType()))
                aErrorList.add(_createError("CollaborationInfo/AgreementRef/@type must not be set"));
        }
    }
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3From(com.helger.phase4.ebms3header.Ebms3From) Ebms3To(com.helger.phase4.ebms3header.Ebms3To) ErrorList(com.helger.commons.error.list.ErrorList) List(java.util.List) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Ebms3AgreementRef(com.helger.phase4.ebms3header.Ebms3AgreementRef)

Aggregations

Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)25 Ebms3Property (com.helger.phase4.ebms3header.Ebms3Property)23 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)20 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)20 Ebms3PayloadInfo (com.helger.phase4.ebms3header.Ebms3PayloadInfo)20 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)18 Nonnull (javax.annotation.Nonnull)14 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)12 Test (org.junit.Test)10 Document (org.w3c.dom.Document)10 HttpXMLEntity (com.helger.phase4.http.HttpXMLEntity)9 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)7 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)6 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)5 Node (org.w3c.dom.Node)5 Ebms3From (com.helger.phase4.ebms3header.Ebms3From)3 Ebms3To (com.helger.phase4.ebms3header.Ebms3To)3 HttpMimeMessageEntity (com.helger.phase4.http.HttpMimeMessageEntity)3 AS4MimeMessage (com.helger.phase4.messaging.mime.AS4MimeMessage)3 ErrorList (com.helger.commons.error.list.ErrorList)2