Search in sources :

Example 1 with AS4IncomingDumperFileBased

use of com.helger.phase4.dump.AS4IncomingDumperFileBased in project phase4 by phax.

the class MainPhase4CEFSenderToop 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 WebScoped w = new WebScoped()) {
        final byte[] aPayloadBytes = SimpleFileIO.getAllFileBytes(new File("src/test/resources/examples/base-example.xml"));
        if (aPayloadBytes == null)
            throw new IllegalStateException();
        // Start configuring here
        final IParticipantIdentifier aReceiverID = Phase4CEFSender.IF.createParticipantIdentifier("iso6523-actorid-upis", "9915:tooptest");
        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() + "'");
            }
        };
        if (Phase4CEFSender.builder().documentTypeID(Phase4CEFSender.IF.createDocumentTypeIdentifier("toop-doctypeid-qns", "urn:eu:toop:ns:dataexchange-1p40::Response##urn:eu.toop.response.registeredorganization::1.40")).processID(Phase4CEFSender.IF.createProcessIdentifier("toop-procid-agreement", "urn:eu.toop.process.datarequestresponse")).senderParticipantID(Phase4CEFSender.IF.createParticipantIdentifier("iso6523-actorid-upis", "9914:phase4-test-sender")).receiverParticipantID(aReceiverID).fromPartyID(new SimpleParticipantIdentifier("type", "POP000306")).fromRole("http://www.toop.eu/edelivery/gateway").toPartyID(new SimpleParticipantIdentifier("type", "POP000306")).toRole("http://www.toop.eu/edelivery/gateway").payload(Phase4OutgoingAttachment.builder().data(aPayloadBytes).mimeTypeXML()).smpClient(new BDXRClientReadOnly(Phase4CEFSender.URL_PROVIDER, aReceiverID, SML_TOOP)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).buildMessageCallback(aBuildMessageCallback).sendMessage().isSuccess()) {
            LOGGER.info("Successfully sent CEF message via AS4");
        } else {
            LOGGER.error("Failed to send CEF message via AS4");
        }
    } catch (final Exception ex) {
        LOGGER.error("Error sending CEF message via AS4", ex);
    } finally {
        WebScopeManager.onGlobalEnd();
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) BDXRClientReadOnly(com.helger.smpclient.bdxr1.BDXRClientReadOnly) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) 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 2 with AS4IncomingDumperFileBased

use of com.helger.phase4.dump.AS4IncomingDumperFileBased in project phase4 by phax.

the class Phase4PeppolWebAppListener method _initAS4.

private static void _initAS4() {
    AS4ServerInitializer.initAS4Server();
    // Store the incoming file as is
    AS4DumpManager.setIncomingDumper(new AS4IncomingDumperFileBased((aMessageMetadata, aHttpHeaderMap) -> StorageHelper.getStorageFile(aMessageMetadata, ".as4in")) {

        @Override
        public void onEndRequest(@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata) {
            // Save the metadata also to a file
            final File aFile = StorageHelper.getStorageFile(aMessageMetadata, ".metadata");
            if (SimpleFileIO.writeFile(aFile, AS4MessagingHelper.getIncomingMetadataAsJson(aMessageMetadata).getAsJsonString(JsonWriterSettings.DEFAULT_SETTINGS_FORMATTED), StandardCharsets.UTF_8).isFailure())
                LOGGER.error("Failed to write metadata to '" + aFile.getAbsolutePath() + "'");
            else
                LOGGER.info("Wrote metadata to '" + aFile.getAbsolutePath() + "'");
        }
    });
    // Store the outgoings file as well
    AS4DumpManager.setOutgoingDumper(new AS4OutgoingDumperFileBased((eMsgMode, sMessageID, nTry) -> StorageHelper.getStorageFile(sMessageID, nTry, ".as4out")));
}
Also used : X509Certificate(java.security.cert.X509Certificate) ServletRegistration(javax.servlet.ServletRegistration) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) ETriState(com.helger.commons.state.ETriState) LoggerFactory(org.slf4j.LoggerFactory) MetaAS4Manager(com.helger.phase4.mgr.MetaAS4Manager) AS4ProfileSelector(com.helger.phase4.servlet.mgr.AS4ProfileSelector) AS4Configuration(com.helger.phase4.config.AS4Configuration) StorageHelper(com.helger.phase4.peppol.server.storage.StorageHelper) IUserManager(com.helger.photon.security.user.IUserManager) SLF4JBridgeHandler(org.slf4j.bridge.SLF4JBridgeHandler) JsonWriterSettings(com.helger.json.serialize.JsonWriterSettings) CommandMap(javax.activation.CommandMap) CSecurity(com.helger.photon.security.CSecurity) PrivateKeyEntry(java.security.KeyStore.PrivateKeyEntry) CMimeType(com.helger.commons.mime.CMimeType) Locale(java.util.Locale) Map(java.util.Map) IAS4IncomingMessageMetadata(com.helger.phase4.messaging.IAS4IncomingMessageMetadata) GlobalDebug(com.helger.commons.debug.GlobalDebug) Nonnull(javax.annotation.Nonnull) AS4CryptoFactoryProperties(com.helger.phase4.crypto.AS4CryptoFactoryProperties) Nullable(javax.annotation.Nullable) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) EPeppolCertificateCheckResult(com.helger.peppol.utils.EPeppolCertificateCheckResult) Logger(org.slf4j.Logger) StringHelper(com.helger.commons.string.StringHelper) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) KeyStore(java.security.KeyStore) WebAppListener(com.helger.photon.core.servlet.WebAppListener) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) WebListener(javax.servlet.annotation.WebListener) AS4DumpManager(com.helger.phase4.dump.AS4DumpManager) AS4ServerInitializer(com.helger.phase4.servlet.AS4ServerInitializer) HttpDebugger(com.helger.httpclient.HttpDebugger) SimpleFileIO(com.helger.commons.io.file.SimpleFileIO) AS4MessagingHelper(com.helger.phase4.messaging.AS4MessagingHelper) URLHelper(com.helger.commons.url.URLHelper) InitializationException(com.helger.commons.exception.InitializationException) PeppolCertificateChecker(com.helger.peppol.utils.PeppolCertificateChecker) CAS4(com.helger.phase4.CAS4) ServletContext(javax.servlet.ServletContext) RequestTrackerSettings(com.helger.xservlet.requesttrack.RequestTrackerSettings) Phase4PeppolServletConfiguration(com.helger.phase4.peppol.servlet.Phase4PeppolServletConfiguration) AS4PeppolProfileRegistarSPI(com.helger.phase4.profile.peppol.AS4PeppolProfileRegistarSPI) PhotonSecurityManager(com.helger.photon.security.mgr.PhotonSecurityManager) IAS4IncomingMessageMetadata(com.helger.phase4.messaging.IAS4IncomingMessageMetadata) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased)

Example 3 with AS4IncomingDumperFileBased

use of com.helger.phase4.dump.AS4IncomingDumperFileBased in project phase4 by phax.

the class MainPhase4PeppolSenderQvaliaLargeFile 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/large-files/base-example-large-16m.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:5567321707");
        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() + "'");
            }
        };
        // Invalid certificate is valid until 2029
        final IAS4CryptoFactory cf = AS4CryptoFactoryProperties.getDefaultInstance();
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().httpRetrySettings(new HttpRetrySettings().setMaxRetries(0)).cryptoFactory(cf).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)).validationConfiguration(PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, new Phase4PeppolValidatonResultHandler()).compressPayload(false).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) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) HttpRetrySettings(com.helger.phase4.http.HttpRetrySettings) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 4 with AS4IncomingDumperFileBased

use of com.helger.phase4.dump.AS4IncomingDumperFileBased in project phase4 by phax.

the class MainPhase4PeppolSenderQvaliaOrder 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/test-order.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:5567321707");
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Order-2::Order##urn:fdc:peppol.eu:poacc:trns:order:3::2.1")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:poacc:bis:ordering:3")).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_ORDER_V3, new Phase4PeppolValidatonResultHandler()).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 : SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) Element(org.w3c.dom.Element) 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 5 with AS4IncomingDumperFileBased

use of com.helger.phase4.dump.AS4IncomingDumperFileBased in project phase4 by phax.

the class MainPhase4PeppolSenderQvaliaUBL 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/example-ubl-en-qvalia.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:5567321707");
        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() + "'");
            }
        };
        // Add EN16931 rulesets
        final IValidationExecutorSetRegistry<IValidationSourceXML> aVESRegistry = Phase4PeppolValidation.createDefaultRegistry();
        EN16931Validation.initEN16931(aVESRegistry);
        // Invalid certificate is valid until 2029
        final IAS4CryptoFactory cf = AS4CryptoFactoryProperties.getDefaultInstance();
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().httpRetrySettings(new HttpRetrySettings().setMaxRetries(0)).cryptoFactory(cf).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()).validationRegistry(aVESRegistry).validationConfiguration(EN16931Validation.VID_UBL_INVOICE_137, 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) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) HttpRetrySettings(com.helger.phase4.http.HttpRetrySettings) 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)

Aggregations

AS4IncomingDumperFileBased (com.helger.phase4.dump.AS4IncomingDumperFileBased)42 AS4OutgoingDumperFileBased (com.helger.phase4.dump.AS4OutgoingDumperFileBased)42 File (java.io.File)36 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)33 ESimpleUserMessageSendResult (com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult)33 Element (org.w3c.dom.Element)32 AS4RawResponseConsumerWriteToFile (com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile)31 SMPClientReadOnly (com.helger.smpclient.peppol.SMPClientReadOnly)27 IAS4ClientBuildMessageCallback (com.helger.phase4.client.IAS4ClientBuildMessageCallback)14 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)14 AbstractAS4Message (com.helger.phase4.messaging.domain.AbstractAS4Message)14 HttpRetrySettings (com.helger.phase4.http.HttpRetrySettings)6 IAS4CryptoFactory (com.helger.phase4.crypto.IAS4CryptoFactory)4 IValidationSourceXML (com.helger.phive.engine.source.IValidationSourceXML)3 GlobalDebug (com.helger.commons.debug.GlobalDebug)2 SimpleFileIO (com.helger.commons.io.file.SimpleFileIO)2 CMimeType (com.helger.commons.mime.CMimeType)2 HttpDebugger (com.helger.httpclient.HttpDebugger)2 JsonWriterSettings (com.helger.json.serialize.JsonWriterSettings)2 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)2