Search in sources :

Example 1 with PeppolValidation3_13_0

use of com.helger.phive.peppol.PeppolValidation3_13_0 in project phase4 by phax.

the class MainPhase4PeppolSenderHelger method send.

public static void send() {
    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("9915:helger");
        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 IAS4RawResponseConsumer aRRC = new AS4RawResponseConsumerWriteToFile().setHandleStatusLine(true).setHandleHttpHeaders(true).and(x -> {
            LOGGER.info("Response status line: " + x.getResponseStatusLine());
            LOGGER.info("Response headers:");
            x.getResponseHeaders().forEachSingleHeader((k, v) -> LOGGER.info("  " + k + "=" + v), false);
        });
        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)).sbdDocumentConsumer(x -> {
            if (false)
                LOGGER.info(SBDHWriter.standardBusinessDocument().setFormattedOutput(true).getAsString(x));
        }).validationConfiguration(PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, new Phase4PeppolValidatonResultHandler()).buildMessageCallback(aBuildMessageCallback).rawResponseConsumer(aRRC).sendMessageAndCheckForReceipt();
        LOGGER.info("Peppol send result: " + eResult);
    } catch (final Exception ex) {
        LOGGER.error("Error sending Peppol message via AS4", ex);
    }
}
Also used : AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) Logger(org.slf4j.Logger) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) IAS4RawResponseConsumer(com.helger.phase4.client.IAS4RawResponseConsumer) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) LoggerFactory(org.slf4j.LoggerFactory) File(java.io.File) AS4DumpManager(com.helger.phase4.dump.AS4DumpManager) PeppolValidation3_13_0(com.helger.phive.peppol.PeppolValidation3_13_0) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) DOMReader(com.helger.xml.serialize.read.DOMReader) Element(org.w3c.dom.Element) MockServletContext(com.helger.servlet.mock.MockServletContext) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) WebScopeManager(com.helger.web.scope.mgr.WebScopeManager) SBDHWriter(com.helger.sbdh.builder.SBDHWriter) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) ESML(com.helger.peppol.sml.ESML) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) IAS4RawResponseConsumer(com.helger.phase4.client.IAS4RawResponseConsumer) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Aggregations

ESML (com.helger.peppol.sml.ESML)1 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)1 IAS4ClientBuildMessageCallback (com.helger.phase4.client.IAS4ClientBuildMessageCallback)1 IAS4RawResponseConsumer (com.helger.phase4.client.IAS4RawResponseConsumer)1 AS4DumpManager (com.helger.phase4.dump.AS4DumpManager)1 AS4IncomingDumperFileBased (com.helger.phase4.dump.AS4IncomingDumperFileBased)1 AS4OutgoingDumperFileBased (com.helger.phase4.dump.AS4OutgoingDumperFileBased)1 AS4RawResponseConsumerWriteToFile (com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile)1 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)1 AbstractAS4Message (com.helger.phase4.messaging.domain.AbstractAS4Message)1 ESimpleUserMessageSendResult (com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult)1 PeppolValidation3_13_0 (com.helger.phive.peppol.PeppolValidation3_13_0)1 SBDHWriter (com.helger.sbdh.builder.SBDHWriter)1 MockServletContext (com.helger.servlet.mock.MockServletContext)1 SMPClientReadOnly (com.helger.smpclient.peppol.SMPClientReadOnly)1 WebScopeManager (com.helger.web.scope.mgr.WebScopeManager)1 DOMReader (com.helger.xml.serialize.read.DOMReader)1 File (java.io.File)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1