Skip to content

Commit fce547e

Browse files
committed
Added test case
1 parent 47bd582 commit fce547e

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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.messaging.http.HttpRetrySettings;
33+
import com.helger.phase4.model.message.AS4UserMessage;
34+
import com.helger.phase4.model.message.AbstractAS4Message;
35+
import com.helger.phase4.peppol.Phase4PeppolSender;
36+
import com.helger.phase4.sender.EAS4UserMessageSendResult;
37+
import com.helger.servlet.mock.MockServletContext;
38+
import com.helger.smpclient.peppol.SMPClientReadOnly;
39+
import com.helger.web.scope.mgr.WebScopeManager;
40+
import com.helger.xml.serialize.read.DOMReader;
41+
42+
/**
43+
* Example for sending something to the Qvalia [SE] test endpoint.
44+
*
45+
* @author Philip Helger
46+
*/
47+
public final class MainPhase4PeppolSenderPagero
48+
{
49+
private static final Logger LOGGER = Phase4LoggerFactory.getLogger (MainPhase4PeppolSenderPagero.class);
50+
51+
public static void send ()
52+
{
53+
try
54+
{
55+
final Element aPayloadElement = DOMReader.readXMLDOM (new File ("src/test/resources/external/examples/base-example.xml"))
56+
.getDocumentElement ();
57+
if (aPayloadElement == null)
58+
throw new IllegalStateException ("Failed to read XML file to be send");
59+
60+
// Start configuring here
61+
final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme ("0009:11000201100044");
62+
final IAS4ClientBuildMessageCallback aBuildMessageCallback = new IAS4ClientBuildMessageCallback ()
63+
{
64+
public void onAS4Message (final AbstractAS4Message <?> aMsg)
65+
{
66+
final AS4UserMessage aUserMsg = (AS4UserMessage) aMsg;
67+
LOGGER.info ("Sending out AS4 message with message ID '" +
68+
aUserMsg.getEbms3UserMessage ().getMessageInfo ().getMessageId () +
69+
"'");
70+
}
71+
};
72+
73+
final EAS4UserMessageSendResult eResult = Phase4PeppolSender.builder ()
74+
.httpRetrySettings (new HttpRetrySettings ().setMaxRetries (0))
75+
.peppolAP_CAChecker (PeppolTrustedCA.peppolTestAP ())
76+
.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"))
77+
.processID (Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme ("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"))
78+
.senderParticipantID (Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme ("9915:phase4-test-sender"))
79+
.receiverParticipantID (aReceiverID)
80+
.senderPartyID ("POP000306")
81+
.countryC1 ("AT")
82+
.payload (aPayloadElement)
83+
.smpClient (new SMPClientReadOnly (Phase4PeppolSender.URL_PROVIDER,
84+
aReceiverID,
85+
ESML.DIGIT_TEST))
86+
.buildMessageCallback (aBuildMessageCallback)
87+
.sendMessageAndCheckForReceipt ();
88+
LOGGER.info ("Peppol send result: " + eResult);
89+
}
90+
catch (final Exception ex)
91+
{
92+
LOGGER.error ("Error sending Peppol message via AS4", ex);
93+
}
94+
}
95+
96+
public static void main (final String [] args)
97+
{
98+
WebScopeManager.onGlobalBegin (MockServletContext.create ());
99+
100+
// Dump (for debugging purpose only)
101+
AS4DumpManager.setIncomingDumper (new AS4IncomingDumperFileBased ());
102+
AS4DumpManager.setOutgoingDumper (new AS4OutgoingDumperFileBased ());
103+
104+
try
105+
{
106+
send ();
107+
}
108+
catch (final Exception ex)
109+
{
110+
LOGGER.error ("Error sending Peppol message via AS4", ex);
111+
}
112+
finally
113+
{
114+
WebScopeManager.onGlobalEnd ();
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)