Skip to content

Commit fe35bf3

Browse files
committed
Added another test; #350
1 parent 8311ce6 commit fe35bf3

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (C) 2015-2025 Philip Helger (www.helger.com)
3+
* philip[at]helger[dot]com
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.helger.phase4.peppol.receivers;
18+
19+
import java.io.File;
20+
21+
import org.slf4j.Logger;
22+
import org.w3c.dom.Element;
23+
24+
import com.helger.peppol.security.PeppolTrustedCA;
25+
import com.helger.peppol.sml.ESML;
26+
import com.helger.peppolid.IParticipantIdentifier;
27+
import com.helger.phase4.client.IAS4ClientBuildMessageCallback;
28+
import com.helger.phase4.dump.AS4DumpManager;
29+
import com.helger.phase4.dump.AS4IncomingDumperFileBased;
30+
import com.helger.phase4.dump.AS4OutgoingDumperFileBased;
31+
import com.helger.phase4.logging.Phase4LoggerFactory;
32+
import com.helger.phase4.model.message.AS4UserMessage;
33+
import com.helger.phase4.model.message.AbstractAS4Message;
34+
import com.helger.phase4.peppol.Phase4PeppolSender;
35+
import com.helger.phase4.sender.EAS4UserMessageSendResult;
36+
import com.helger.servlet.mock.MockServletContext;
37+
import com.helger.smpclient.peppol.SMPClientReadOnly;
38+
import com.helger.web.scope.mgr.WebScopeManager;
39+
import com.helger.xml.serialize.read.DOMReader;
40+
41+
/**
42+
* Example for sending something to the BTC [DE] test endpoint.
43+
*
44+
* @author Philip Helger
45+
*/
46+
public final class MainPhase4PeppolSenderClayDesk
47+
{
48+
private static final Logger LOGGER = Phase4LoggerFactory.getLogger (MainPhase4PeppolSenderClayDesk.class);
49+
50+
public static void main (final String [] args)
51+
{
52+
WebScopeManager.onGlobalBegin (MockServletContext.create ());
53+
54+
// Dump (for debugging purpose only)
55+
AS4DumpManager.setIncomingDumper (new AS4IncomingDumperFileBased ());
56+
AS4DumpManager.setOutgoingDumper (new AS4OutgoingDumperFileBased ());
57+
58+
try
59+
{
60+
final Element aPayloadElement = DOMReader.readXMLDOM (new File ("src/test/resources/external/examples/base-example.xml"))
61+
.getDocumentElement ();
62+
if (aPayloadElement == null)
63+
throw new IllegalStateException ("Failed to read XML file to be send");
64+
65+
// Start configuring here
66+
final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme ("0242:000991");
67+
final IAS4ClientBuildMessageCallback aBuildMessageCallback = new IAS4ClientBuildMessageCallback ()
68+
{
69+
public void onAS4Message (final AbstractAS4Message <?> aMsg)
70+
{
71+
final AS4UserMessage aUserMsg = (AS4UserMessage) aMsg;
72+
LOGGER.info ("Sending out AS4 message with message ID '" +
73+
aUserMsg.getEbms3UserMessage ().getMessageInfo ().getMessageId () +
74+
"'");
75+
}
76+
};
77+
78+
final EAS4UserMessageSendResult eResult = Phase4PeppolSender.builder ()
79+
.peppolAP_CAChecker (PeppolTrustedCA.peppolTestAP ())
80+
.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"))
81+
.processID (Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme ("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"))
82+
.senderParticipantID (Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme ("9915:helger"))
83+
.receiverParticipantID (aReceiverID)
84+
.senderPartyID ("POP000306")
85+
.countryC1 ("AT")
86+
.payload (aPayloadElement)
87+
.smpClient (new SMPClientReadOnly (Phase4PeppolSender.URL_PROVIDER,
88+
aReceiverID,
89+
ESML.DIGIT_TEST))
90+
.buildMessageCallback (aBuildMessageCallback)
91+
.sendMessageAndCheckForReceipt ();
92+
LOGGER.info ("Peppol send result: " + eResult);
93+
}
94+
catch (final Exception ex)
95+
{
96+
LOGGER.error ("Error sending Peppol message via AS4", ex);
97+
}
98+
finally
99+
{
100+
WebScopeManager.onGlobalEnd ();
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)