Search in sources :

Example 6 with Ebms3MessageProperties

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

the class MockClientMessages method createEmptyUserMessage.

@Nonnull
@SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION")
public static Document createEmptyUserMessage(@Nonnull final ESoapVersion eSoapVersion, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aAttachments) {
    // Add properties
    final ICommonsList<Ebms3Property> aEbms3Properties = new CommonsArrayList<>();
    final Ebms3Property aEbms3PropertyProcess = new Ebms3Property();
    aEbms3Properties.add(aEbms3PropertyProcess);
    // Use an empty message info by purpose
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, aAttachments);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(null, null, null, "svc", "act", "conv");
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo("fid", "frole", "tid", "trole");
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final AS4UserMessage aDoc = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSoapVersion).setMustUnderstand(true);
    return aDoc.getAsSoapDocument(aPayload);
}
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) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Nonnull(javax.annotation.Nonnull) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 7 with Ebms3MessageProperties

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

the class MockClientMessages 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 = new CommonsArrayList<>();
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property("ProcessInst", "PurchaseOrder:123456"));
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property("ContextID", "987654321"));
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property(CAS4.ORIGINAL_SENDER, "C1 OS"));
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property(CAS4.FINAL_RECIPIENT, "C4 FR"));
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, aAttachments);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo("pmode-twoway", DEFAULT_AGREEMENT, "MyServiceTypes", "QuoteToCollect", "NewPurchaseOrder", "4321");
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, "1234", CAS4.DEFAULT_RESPONDER_URL, "5678");
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final AS4UserMessage aDoc = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSoapVersion).setMustUnderstand(true);
    return aDoc;
}
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) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Nonnull(javax.annotation.Nonnull)

Example 8 with Ebms3MessageProperties

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

the class AS4UserMessage method create.

@Nonnull
public static AS4UserMessage create(@Nonnull final Ebms3MessageInfo aEbms3MessageInfo, @Nullable final Ebms3PayloadInfo aEbms3PayloadInfo, @Nonnull final Ebms3CollaborationInfo aEbms3CollaborationInfo, @Nonnull final Ebms3PartyInfo aEbms3PartyInfo, @Nullable final Ebms3MessageProperties aEbms3MessageProperties, @Nonnull final ESoapVersion eSoapVersion) {
    final Ebms3UserMessage aUserMessage = new Ebms3UserMessage();
    // Party Information
    aUserMessage.setPartyInfo(aEbms3PartyInfo);
    // Collaboration Information
    aUserMessage.setCollaborationInfo(aEbms3CollaborationInfo);
    // Properties
    aUserMessage.setMessageProperties(aEbms3MessageProperties);
    // Payload Information
    aUserMessage.setPayloadInfo(aEbms3PayloadInfo);
    // Message Info
    aUserMessage.setMessageInfo(aEbms3MessageInfo);
    return new AS4UserMessage(eSoapVersion, aUserMessage);
}
Also used : Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) Nonnull(javax.annotation.Nonnull)

Example 9 with Ebms3MessageProperties

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

the class MessageHelperMethods method createEbms3MessageProperties.

@Nullable
public static Ebms3MessageProperties createEbms3MessageProperties(@Nullable final List<Ebms3Property> aEbms3Properties) {
    // MessageProperties may not be empty!
    if (aEbms3Properties == null || aEbms3Properties.isEmpty())
        return null;
    final Ebms3MessageProperties aEbms3MessageProperties = new Ebms3MessageProperties();
    aEbms3MessageProperties.setProperty(aEbms3Properties);
    return aEbms3MessageProperties;
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Nullable(javax.annotation.Nullable)

Example 10 with Ebms3MessageProperties

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

the class AS4ClientUserMessage method buildMessage.

@Override
@Nonnull
public AS4ClientBuiltMessage buildMessage(@Nonnull @Nonempty final String sMessageID, @Nullable final IAS4ClientBuildMessageCallback aCallback) throws WSSecurityException, MessagingException {
    final String sAgreementRefPMode = m_aPModeIDFactory.apply(this);
    // check mandatory attributes
    _checkMandatoryAttributes();
    final boolean bSign = signingParams().isSigningEnabled();
    final boolean bEncrypt = cryptParams().isCryptEnabled(LOGGER::warn);
    final boolean bAttachmentsPresent = m_aAttachments.isNotEmpty();
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo(sMessageID, getRefToMessageID(), getSendingDateTimeOrNow());
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(m_aPayload != null, m_aAttachments);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sAgreementRefPMode, m_sAgreementRefValue, m_sServiceType, m_sServiceValue, m_sAction, m_sConversationID);
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(m_sFromRole, m_sFromPartyIDType, m_sFromPartyIDValue, m_sToRole, m_sToPartyIDType, m_sToPartyIDValue);
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(m_aEbms3Properties);
    final AS4UserMessage aUserMsg = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, getSoapVersion()).setMustUnderstand(true);
    if (aCallback != null)
        aCallback.onAS4Message(aUserMsg);
    final Document aPureDoc = aUserMsg.getAsSoapDocument(m_aPayload);
    if (aCallback != null)
        aCallback.onSoapDocument(aPureDoc);
    // 1. compress
    // Is done when the attachments are added
    // 2. sign and/or encrpyt
    Document aDoc = aPureDoc;
    AS4MimeMessage aMimeMsg = null;
    if (bSign || bEncrypt) {
        AS4HttpDebug.debug(() -> "Unsigned/unencrypted UserMessage:\n" + XMLWriter.getNodeAsString(aPureDoc, AS4HttpDebug.getDebugXMLWriterSettings()));
        final IAS4CryptoFactory aCryptoFactory = internalCreateCryptoFactory();
        // 2a. sign
        if (bSign) {
            final boolean bMustUnderstand = true;
            final Document aSignedDoc = AS4Signer.createSignedMessage(aCryptoFactory, aDoc, getSoapVersion(), aUserMsg.getMessagingID(), m_aAttachments, getAS4ResourceHelper(), bMustUnderstand, signingParams().getClone());
            aDoc = aSignedDoc;
            if (aCallback != null)
                aCallback.onSignedSoapDocument(aSignedDoc);
            AS4HttpDebug.debug(() -> "Signed UserMessage:\n" + XMLWriter.getNodeAsString(aSignedDoc, AS4HttpDebug.getDebugXMLWriterSettings()));
        }
        // 2b. encrypt
        if (bEncrypt) {
            // MustUnderstand always set to true
            final boolean bMustUnderstand = true;
            if (bAttachmentsPresent) {
                aMimeMsg = AS4Encryptor.encryptMimeMessage(getSoapVersion(), aDoc, m_aAttachments, aCryptoFactory, bMustUnderstand, getAS4ResourceHelper(), cryptParams().getClone());
                if (aCallback != null)
                    aCallback.onEncryptedMimeMessage(aMimeMsg);
            } else {
                final Document aEncryptedDoc = AS4Encryptor.encryptSoapBodyPayload(aCryptoFactory, getSoapVersion(), aDoc, bMustUnderstand, cryptParams().getClone());
                if (aCallback != null)
                    aCallback.onEncryptedSoapDocument(aDoc);
                aDoc = aEncryptedDoc;
            }
        }
    }
    if (bAttachmentsPresent && aMimeMsg == null) {
        // * not encrypted, not signed
        // * not encrypted, signed
        aMimeMsg = MimeMessageCreator.generateMimeMessage(getSoapVersion(), aDoc, m_aAttachments);
    }
    if (aMimeMsg != null) {
        // Wrap MIME message
        return new AS4ClientBuiltMessage(sMessageID, new HttpMimeMessageEntity(aMimeMsg));
    }
    // Wrap SOAP XML
    return new AS4ClientBuiltMessage(sMessageID, new HttpXMLEntity(aDoc, getSoapVersion().getMimeType()));
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) 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) Nonnull(javax.annotation.Nonnull)

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