Search in sources :

Example 16 with AS4UserMessage

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

the class MainPhase4PeppolSenderBasware method main.

public static void main(final String[] args) {
    WebScopeManager.onGlobalBegin(MockServletContext.create());
    // Dump (for debugging purpose only)
    AS4DumpManager.setIncomingDumper(new AS4IncomingDumperFileBased());
    AS4DumpManager.setOutgoingDumper(new AS4OutgoingDumperFileBased());
    try {
        final Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/examples/base-example.xml")).getDocumentElement();
        if (aPayloadElement == null)
            throw new IllegalStateException("Failed to read XML file to be send");
        // Start configuring here
        final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("0007:AS4_TESTBASWARE_PEPPOLEP");
        final IAS4ClientBuildMessageCallback aBuildMessageCallback = new IAS4ClientBuildMessageCallback() {

            public void onAS4Message(final AbstractAS4Message<?> aMsg) {
                final AS4UserMessage aUserMsg = (AS4UserMessage) aMsg;
                LOGGER.info("Sending out AS4 message with message ID '" + aUserMsg.getEbms3UserMessage().getMessageInfo().getMessageId() + "'");
                LOGGER.info("Sending out AS4 message with conversation ID '" + aUserMsg.getEbms3UserMessage().getCollaborationInfo().getConversationId() + "'");
            }
        };
        final ESimpleUserMessageSendResult eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0")).senderParticipantID(Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:phase4-test-sender")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadElement).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).validationConfiguration(PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, new Phase4PeppolValidatonResultHandler()).buildMessageCallback(aBuildMessageCallback).sendMessageAndCheckForReceipt();
        LOGGER.info("Peppol send result: " + eResult);
    } catch (final Exception ex) {
        LOGGER.error("Error sending Peppol message via AS4", ex);
    } finally {
        WebScopeManager.onGlobalEnd();
    }
}
Also used : IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 17 with AS4UserMessage

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

the class MainPhase4PeppolSenderDataport method main.

public static void main(final String[] args) {
    WebScopeManager.onGlobalBegin(MockServletContext.create());
    // Dump (for debugging purpose only)
    AS4DumpManager.setIncomingDumper(new AS4IncomingDumperFileBased());
    AS4DumpManager.setOutgoingDumper(new AS4OutgoingDumperFileBased());
    try {
        final Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/examples/base-example.xml")).getDocumentElement();
        if (aPayloadElement == null)
            throw new IllegalStateException("Failed to read XML file to be send");
        // Start configuring here
        final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("0204:01-2004-73");
        final IAS4ClientBuildMessageCallback aBuildMessageCallback = new IAS4ClientBuildMessageCallback() {

            public void onAS4Message(final AbstractAS4Message<?> aMsg) {
                final AS4UserMessage aUserMsg = (AS4UserMessage) aMsg;
                LOGGER.info("Sending out AS4 message with message ID '" + aUserMsg.getEbms3UserMessage().getMessageInfo().getMessageId() + "'");
                LOGGER.info("Sending out AS4 message with conversation ID '" + aUserMsg.getEbms3UserMessage().getCollaborationInfo().getConversationId() + "'");
            }
        };
        final ESimpleUserMessageSendResult eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme(true ? "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1" : "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.0::2.1")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0")).senderParticipantID(Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:phase4-test-sender")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadElement).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).buildMessageCallback(aBuildMessageCallback).sendMessageAndCheckForReceipt();
        LOGGER.info("Peppol send result: " + eResult);
    } catch (final Exception ex) {
        LOGGER.error("Error sending Peppol message via AS4", ex);
    } finally {
        WebScopeManager.onGlobalEnd();
    }
}
Also used : IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 18 with AS4UserMessage

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

the class MainPhase4PeppolSenderIBM method main.

public static void main(final String[] args) {
    WebScopeManager.onGlobalBegin(MockServletContext.create());
    // Dump (for debugging purpose only)
    AS4DumpManager.setIncomingDumper(new AS4IncomingDumperFileBased());
    AS4DumpManager.setOutgoingDumper(new AS4OutgoingDumperFileBased());
    try {
        final Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/examples/base-example.xml")).getDocumentElement();
        if (aPayloadElement == null)
            throw new IllegalStateException("Failed to read XML file to be send");
        // Start configuring here
        final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("0088:5050689000018");
        final IAS4ClientBuildMessageCallback aBuildMessageCallback = new IAS4ClientBuildMessageCallback() {

            public void onAS4Message(final AbstractAS4Message<?> aMsg) {
                final AS4UserMessage aUserMsg = (AS4UserMessage) aMsg;
                LOGGER.info("Sending out AS4 message with message ID '" + aUserMsg.getEbms3UserMessage().getMessageInfo().getMessageId() + "'");
                LOGGER.info("Sending out AS4 message with conversation ID '" + aUserMsg.getEbms3UserMessage().getCollaborationInfo().getConversationId() + "'");
            }
        };
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0")).senderParticipantID(Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:phase4-test-sender")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadElement).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).validationConfiguration(PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, new Phase4PeppolValidatonResultHandler()).buildMessageCallback(aBuildMessageCallback).sendMessageAndCheckForReceipt();
        LOGGER.info("Peppol send result: " + eResult);
    } catch (final Exception ex) {
        LOGGER.error("Error sending Peppol message via AS4", ex);
    } finally {
        WebScopeManager.onGlobalEnd();
    }
}
Also used : IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 19 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage 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 20 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage 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

AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)45 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)20 Test (org.junit.Test)19 Document (org.w3c.dom.Document)19 AS4MimeMessage (com.helger.phase4.messaging.mime.AS4MimeMessage)17 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)16 IAS4ClientBuildMessageCallback (com.helger.phase4.client.IAS4ClientBuildMessageCallback)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 AbstractAS4Message (com.helger.phase4.messaging.domain.AbstractAS4Message)16 File (java.io.File)16 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)15 AS4IncomingDumperFileBased (com.helger.phase4.dump.AS4IncomingDumperFileBased)15 AS4OutgoingDumperFileBased (com.helger.phase4.dump.AS4OutgoingDumperFileBased)15 Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)15 ESimpleUserMessageSendResult (com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult)15 Nonnull (javax.annotation.Nonnull)15