From e39e180da17ab5e79471cd2f0bc9f937b31f26ca Mon Sep 17 00:00:00 2001 From: Philip Helger Date: Wed, 25 Oct 2023 15:47:59 +0200 Subject: [PATCH] Added example for sending via sbdhBuiler --- .../peppol/MainPhase4PeppolSenderSbdh.java | 89 +++++++ .../resources/external/examples/base-sbdh.xml | 238 ++++++++++++++++++ 2 files changed, 327 insertions(+) create mode 100644 phase4-peppol-client/src/test/java/com/helger/phase4/peppol/MainPhase4PeppolSenderSbdh.java create mode 100644 phase4-peppol-client/src/test/resources/external/examples/base-sbdh.xml diff --git a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/MainPhase4PeppolSenderSbdh.java b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/MainPhase4PeppolSenderSbdh.java new file mode 100644 index 000000000..43472ef14 --- /dev/null +++ b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/MainPhase4PeppolSenderSbdh.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2015-2023 Philip Helger (www.helger.com) + * philip[at]helger[dot]com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.helger.phase4.peppol; + +import java.io.File; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.helger.commons.io.resource.FileSystemResource; +import com.helger.peppol.sbdh.PeppolSBDHDocument; +import com.helger.peppol.sbdh.read.PeppolSBDHDocumentReader; +import com.helger.peppol.sml.ESML; +import com.helger.peppolid.factory.PeppolIdentifierFactory; +import com.helger.phase4.config.AS4Configuration; +import com.helger.phase4.dump.AS4DumpManager; +import com.helger.phase4.dump.AS4IncomingDumperFileBased; +import com.helger.phase4.dump.AS4OutgoingDumperFileBased; +import com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile; +import com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult; +import com.helger.photon.io.WebFileIO; +import com.helger.servlet.mock.MockServletContext; +import com.helger.smpclient.peppol.SMPClientReadOnly; +import com.helger.web.scope.mgr.WebScopeManager; + +/** + * The main class that requires manual configuration before it can be run. This + * is a dummy and needs to be adopted to your needs. + * + * @author Philip Helger + */ +public final class MainPhase4PeppolSenderSbdh +{ + private static final Logger LOGGER = LoggerFactory.getLogger (MainPhase4PeppolSenderSbdh.class); + + public static void main (final String [] args) + { + // Provide context + WebScopeManager.onGlobalBegin (MockServletContext.create ()); + + final File aSCPath = AS4Configuration.getDumpBasePathFile (); + WebFileIO.initPaths (aSCPath, aSCPath.getAbsolutePath (), false); + + // Dump (for debugging purpose only) + AS4DumpManager.setIncomingDumper (new AS4IncomingDumperFileBased ()); + AS4DumpManager.setOutgoingDumper (new AS4OutgoingDumperFileBased ()); + + try + { + final PeppolSBDHDocument aSbdh = new PeppolSBDHDocumentReader (PeppolIdentifierFactory.INSTANCE).extractData (new FileSystemResource ("src/test/resources/external/examples/base-sbdh.xml")); + if (aSbdh == null) + throw new IllegalStateException ("Failed to read SBDH file to be send"); + + // Start configuring here + final ESimpleUserMessageSendResult eResult; + eResult = Phase4PeppolSender.sbdhBuilder () + .payloadAndMetadata (aSbdh) + .senderPartyID ("POP000306") + .smpClient (new SMPClientReadOnly (Phase4PeppolSender.URL_PROVIDER, + aSbdh.getReceiverAsIdentifier (), + ESML.DIGIT_TEST)) + .rawResponseConsumer (new AS4RawResponseConsumerWriteToFile ()) + .sendMessageAndCheckForReceipt (); + LOGGER.info ("Peppol send result: " + eResult); + } + catch (final Exception ex) + { + LOGGER.error ("Error sending Peppol SBDH message via AS4", ex); + } + finally + { + WebScopeManager.onGlobalEnd (); + } + } +} diff --git a/phase4-peppol-client/src/test/resources/external/examples/base-sbdh.xml b/phase4-peppol-client/src/test/resources/external/examples/base-sbdh.xml new file mode 100644 index 000000000..0050252ec --- /dev/null +++ b/phase4-peppol-client/src/test/resources/external/examples/base-sbdh.xml @@ -0,0 +1,238 @@ + + + + + 1.0 + + 9915:phase4-test-sender + + + 9915:helger + + + urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 + 2.1 + 123456789 + Invoice + 2023-10-25T15:42:10Z + + + + DOCUMENTID + 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 + urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 + + + COUNTRY_C1 + GB + + + + + urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 + urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 + test-invoice-phase4 + 2021-10-13 + 2021-12-01 + 380 + EUR + 4025:123:4343 + 0150abc + + + phase4-test-sender + + SupplierTradingName Ltd. + + + Main street 1 + Postbox 123 + London + GB 123 EW + + GB + + + + GB1232434 + + VAT + + + + SupplierOfficialName Ltd + GB983294 + + + + + + helger + + BuyerTradingName AS + + + Hovedgatan 32 + Po box 878 + Stockholm + 456 34 + + SE + + + + SE4598375937 + + VAT + + + + Buyer Official Name + 39937423947 + + + Lisa Johnson + 23434234 + lj@buyer.se + + + + + 2021-10-01 + + 9483759475923478 + + Delivery street 2 + Building 56 + Stockholm + 21234 + + SE + + + + + + Delivery party Name + + + + + 30 + Snippet1 + + IBAN32423940 + AccountName + + BIC324098 + + + + + Payment within 10 days, 2% discount + + + true + Insurance + 25 + + S + 25.0 + + VAT + + + + + 331.25 + + 1325 + 331.25 + + S + 25.0 + + VAT + + + + + + 1300 + 1325 + 1656.25 + 25 + 1656.25 + + + + 1 + 7 + 2800 + Konteringsstreng + + 123 + + + Description of item + item name + + 21382183120983 + + + NO + + + 09348023 + + + S + 25.0 + + VAT + + + + + 400 + + + + 2 + -3 + -1500 + + 123 + + + Description 2 + item name 2 + + 21382183120983 + + + NO + + + 09348023 + + + S + 25.0 + + VAT + + + + + 500 + + + + \ No newline at end of file