use of com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult in project phase4 by phax.
the class MainPhase4PeppolSenderConstantReceiverSG2 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/Singapore invoice valid 1.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("0192:810418052");
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#conformant#urn:fdc:peppol.eu:2017:poacc:billing:international:sg: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).receiverEndpointDetails(CertificateHelper.convertStringToCertficate("-----BEGIN CERTIFICATE-----\n" + "MIIF2zCCA8OgAwIBAgIQDyXLqdKdJNF+okAUGXN3izANBgkqhkiG9w0BAQsFADBr\n" + "MQswCQYDVQQGEwJCRTEZMBcGA1UEChMQT3BlblBFUFBPTCBBSVNCTDEWMBQGA1UE\n" + "CxMNRk9SIFRFU1QgT05MWTEpMCcGA1UEAxMgUEVQUE9MIEFDQ0VTUyBQT0lOVCBU\n" + "RVNUIENBIC0gRzIwHhcNMjAwMjE3MDAwMDAwWhcNMjIwMjA2MjM1OT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GCmCGSAGG+EUBEAUEKzApAgEAFiRhSFIwY0hNNkx5OXdhMmt0Y21FdWMzbHRZ\n" + "WFYwYUM1amIyMD0wDQYJKoZIhvcNAQELBQADggIBAE4naY2C13P4CYR+R3sDwBDU\n" + "JNG6TnFMojGvRXIXSdMFbUotGnED8nhA8q8fS3HIRlXDBnBODODuQBmTPj+zjR2U\n" + "6NFa+ji0mH5obimY/DhB3XeGI3wwxZEr/gi2dDjpdIRpAfwvoIo2E/JczXacNk9C\n" + "Koa5LRpSGLXAwtuPvrDkvcdGYZG5IxldnTcVpan8jU92OjEg8QNWYvtuYTygVYBU\n" + "itFt0vTNxs5+TivDFtOf+SjGmNzKtlFhb5ITM0QWARuTHmBYy5fUZfbKWvTWcOZl\n" + "ieuYT+s1o7tIkLJ62Y7/Qn3xWfVfDEBD40bYVCBQWHv8IGHQUDC/ZdMoeM1Yx3tm\n" + "POveFZodbbI8SjTrpJuGO8nZ/f6dXG4JUXOSs9lR1B17T5FnprQn+B9xiFuVU6mb\n" + "rxoXT7hlt1s+ntFXB8MecZk+a4lprjBumZRqwkQmFjMDZaATZs9hKANstda1qPrz\n" + "RxtRrgzU1dZfUkDNxfEauLug9VPl64UvNgWIhsSfLbPj+AkFn9rXXg2PmeKx7AEL\n" + "gXFSqahkh+96DcKlIc49Os2ew16iJEC+X+kMsMxjZXjkQoMxI1LF7IhGABQctof2\n" + "QsSm4/2kuGIsWKRy+kf7s7xJT7olo1hBQQzNf1J1GN4WbXVWtkxD1jyXML+HnYfh\n" + "47A9zzduKT3CycRoqxaB\n" + "-----END CERTIFICATE-----"), "https://dev.einvoicing.i-portal.biz/msh").rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).validationConfiguration(PeppolValidationSG.VID_OPENPEPPOL_BIS3_SG_UBL_INVOICE_103, 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();
}
}
use of com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult in project phase4 by phax.
the class MainCEFeInvoicingConnectivityTest 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()) {
// Read a UBL Invoice
final byte[] aPayloadBytes = SimpleFileIO.getAllFileBytes(new File("src/test/resources/examples/base-example.xml"));
if (aPayloadBytes == null)
throw new IllegalStateException();
final IAS4ClientBuildMessageCallback x1 = 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() + "'");
}
public void onSoapDocument(@Nonnull final Document aDoc) {
if (false)
LOGGER.info("SOAP Document:\n" + XMLWriter.getNodeAsString(aDoc, new XMLWriterSettings().setIndent(EXMLSerializeIndent.INDENT_AND_ALIGN)));
}
};
// TODO The message ID to use in the UI
final String sAS4MessageID = "36999089-662a-441f-95fd-470bec2b538e-100@phase4";
final ESimpleUserMessageSendResult eRes = Phase4CEFSender.builder().cryptoFactory(CF).httpRetrySettings(new HttpRetrySettings().setMaxRetries(0)).action("TC1Leg1").service("tc1", "bdx:noprocess").senderParticipantID(new SimpleParticipantIdentifier("connectivity-partid-qns", YOUR_ID)).receiverParticipantID(new SimpleParticipantIdentifier("connectivity-partid-qns", "domibus-gitb")).fromPartyIDType("urn:oasis:names:tc:ebcore:partyid-type:unregistered").fromPartyID(YOUR_ID).fromRole(CAS4.DEFAULT_INITIATOR_URL).toPartyIDType("urn:oasis:names:tc:ebcore:partyid-type:unregistered").toPartyID("domibus-gitb").toRole(CAS4.DEFAULT_RESPONDER_URL).messageID(sAS4MessageID).payload(Phase4OutgoingAttachment.builder().data(aPayloadBytes).filename("businessContentPayload").compressionGZIP().mimeType(CMimeType.TEXT_XML).contentID("message").build()).buildMessageCallback(x1).endpointDetailProvider(new AS4EndpointDetailProviderConstant(CertificateHelper.convertStringToCertficateOrNull("-----BEGIN CERTIFICATE-----\r\n" + "MIIDOzCCAiOgAwIBAgIJAKbwaKpEwNTKMA0GCSqGSIb3DQEBCwUAMDQxDTALBgNV\r\n" + "BAoMBEdJVEIxDTALBgNVBAsMBEdJVEIxFDASBgNVBAMMC2dpdGItZW5naW5lMB4X\r\n" + "DTE0MTIyNDEzMjIzNFoXDTI0MTIyMTEzMjIzNFowNDENMAsGA1UECgwER0lUQjEN\r\n" + "MAsGA1UECwwER0lUQjEUMBIGA1UEAwwLZ2l0Yi1lbmdpbmUwggEiMA0GCSqGSIb3\r\n" + "DQEBAQUAA4IBDwAwggEKAoIBAQCpNuRRMhpd2SvNKsZe/WTxm4zuX2Zc5by3zGcm\r\n" + "uzwePdMCnCXk2FAUH67qS9r5VBa4USfiB7l1piyLrNwYWGRDo5OeWIz6Q821/1v7\r\n" + "UHq7FfB0LFPcJ+mOwrDqS+VL0MjcSW4pocJHrpFwObWHTY/R4WmW2xwGOKVh0OUL\r\n" + "UhqQsHDnDhCzFaEWhS8n1lUw3GRipwKLyYvXK8XgLceEmh+j0+cdmIj4a1L4oza/\r\n" + "UgBnCqSob+vowgClyZnGVihE9K8eLLwCSLlIiD+bXWf0VJPLXBNLdNIkRRC0QO0j\r\n" + "T9TuE5TF3SknkA5D0NFp023Alz7jieI0D6JE78QyNQN6y6QRAgMBAAGjUDBOMB0G\r\n" + "A1UdDgQWBBQpAkry20hAcvlw+4poxQC8TI+EgTAfBgNVHSMEGDAWgBQpAkry20hA\r\n" + "cvlw+4poxQC8TI+EgTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBS\r\n" + "dfmT3E9uvhiEgVefdwXkkxqlXLQQxfjaqVRVzPTHLqdVs/nBK+iQNhqg+6eLcaGQ\r\n" + "yyDy88vwQ85rqwOFbZd05esIFXYl0pgl1pVsb7HmMNmKT3UPay3HDlHX45ZoexDU\r\n" + "pza4OcrauEM8Yg/5i9dCIPC1GiHebJpYusMVfP78b+5DAyARrHtcb0EJ8rOLxHh6\r\n" + "K2S4EHI6sqQkGHEt1z4m66LyK+vnkLGaq3y6MWEufh78eICDyyVz0DhdIhr18ZHX\r\n" + "dpcsH2VOkE36KnWSo0spEXa6ZtP8MqQ60kJgBt4XcuArKfjIGC6vB6dE0NzXngBD\r\n" + "PHgMfmHJW018/6eN/f0q\r\n" + "-----END CERTIFICATE-----"), "https://www.itb.ec.europa.eu/cef/domibus/services/msh")).sendMessageAndCheckForReceipt();
LOGGER.info("Sending AS4 message to CEF with result " + eRes);
} finally {
WebScopeManager.onGlobalEnd();
}
}
use of com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult in project phase4 by phax.
the class MainPhase4PeppolSenderStorecoveConstantReceiver 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("0106:sc998899889");
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).receiverEndpointDetails(CertificateHelper.convertStringToCertficate("-----BEGIN CERTIFICATE-----\r\n" + "MIIF0TCCA7mgAwIBAgIQbXAEkESKryKJazdxZUo39zANBgkqhkiG9w0BAQsFADBr\r\n" + "MQswCQYDVQQGEwJCRTEZMBcGA1UEChMQT3BlblBFUFBPTCBBSVNCTDEWMBQGA1UE\r\n" + "CxMNRk9SIFRFU1QgT05MWTEpMCcGA1UEAxMgUEVQUE9MIEFDQ0VTUyBQT0lOVCBU\r\n" + "RVNUIENBIC0gRzIwHhcNMTgxMDE3MDAwMDAwWhcNMjAxMDA2MjM1OTU5WjBeMRIw\r\n" + "EAYDVQQDDAlQTkwwMDAxNTExFzAVBgNVBAsMDlBFUFBPTCBURVNUIEFQMSIwIAYD\r\n" + "VQQKDBlTdG9yZWNvdmUgKERhdGFqdXN0IEIuVi4pMQswCQYDVQQGEwJOTDCCASIw\r\n" + "DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKj00j0ybln4DoN2dyDaLFzKztmr\r\n" + "f772Oq1DuPuk/D590Duci1eQZYAGvm58s19aNS+lVwombpEA7luxjiX+UfAQ0EN7\r\n" + "Ih3qaAZ5eZOPQh+1zr1dWArFYK/0yn0PwhGVXCLuyWTFxQrmitwSjuHIjUKDxuC8\r\n" + "4vzvNyxZzADUqGQMoafDE9IZsRUMY7DAlqaFE3NLa8riCmWIalmwhDDmlxu09nqc\r\n" + "ot1uk3n1sCF/vpvzkdjuVUn4oiHG1rkBpJVr7UjQx6nbIuVVENGrJ+HT0CG1exMS\r\n" + "Yo+onqrRjWyad+S6HYcO6tIRx1pl7wyk8a9z2um/G9ipwNlxGXFf7KlSh58CAwEA\r\n" + "AaOCAXwwggF4MAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgOoMBYGA1UdJQEB\r\n" + "/wQ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F06BGHGQa9IMF4GNHX94BRgee8jmIbHmusxP3ynXi0zr7lmk3tyWXUIp581\r\n" + "NP9BV7SyeG0ToBRiSoBUUUDP2Tqesqgj84+qRGC7uNMUOkU3gRNrJcBDaNr+cQMA\r\n" + "GXjzBQuF1wdECMQAHNTrwzHziw4S/ZMf5KELc1ezYF61NAfCb8voMzFCJn4n1XK+\r\n" + "hBQpCt8=\r\n" + "-----END CERTIFICATE-----\r\n"), false ? "https://o96st7ob6h.execute-api.eu-west-1.amazonaws.com/prod/as4" : "https://accap.mypeppol.app/as4").rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).sendMessageAndCheckForReceipt();
LOGGER.info("Peppol send result: " + eResult);
} catch (final Exception ex) {
LOGGER.error("Error sending Peppol message via AS4", ex);
}
}
use of com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult in project phase4 by phax.
the class MainPhase4PeppolSenderTradeshift 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/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("9902:DK35391282");
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 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)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).validationConfiguration(PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, 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();
}
}
use of com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult in project peppol-practical by phax.
the class PageSecurePeppolSendAS4 method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final IIdentifierFactory aIF = Phase4PeppolSender.IF;
final FormErrorList aFormErrors = new FormErrorList();
if (aWPEC.params().hasStringValue(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM)) {
final String sSenderID = aWPEC.params().getAsStringTrimmed(FIELD_SENDER_ID);
final IParticipantIdentifier aSenderID = aIF.parseParticipantIdentifier(sSenderID);
final String sReceiverID = aWPEC.params().getAsStringTrimmed(FIELD_RECEIVER_ID);
final IParticipantIdentifier aReceiverID = aIF.parseParticipantIdentifier(sReceiverID);
final String sDocTypeID = aWPEC.params().getAsStringTrimmed(FIELD_DOCTYPE_ID);
final IDocumentTypeIdentifier aDocTypeID = aIF.parseDocumentTypeIdentifier(sDocTypeID);
final String sProcessID = aWPEC.params().getAsStringTrimmed(FIELD_PROCESS_ID);
final IProcessIdentifier aProcessID = aIF.parseProcessIdentifier(sProcessID);
final String sPayload = aWPEC.params().getAsStringTrimmed(FIELD_PAYLOAD);
final Document aPayloadDoc = DOMReader.readXMLDOM(sPayload);
if (StringHelper.hasNoText(sSenderID))
aFormErrors.addFieldError(FIELD_SENDER_ID, "A sending participant ID must be provided.");
else if (aSenderID == null)
aFormErrors.addFieldError(FIELD_SENDER_ID, "The sending participant ID could not be parsed.");
if (StringHelper.hasNoText(sReceiverID))
aFormErrors.addFieldError(FIELD_RECEIVER_ID, "A receiving participant ID must be provided.");
else if (aReceiverID == null)
aFormErrors.addFieldError(FIELD_RECEIVER_ID, "The receiving participant ID could not be parsed.");
if (StringHelper.hasNoText(sDocTypeID))
aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "A document type ID must be provided.");
else if (aDocTypeID == null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "The document type ID could not be parsed.");
if (StringHelper.hasNoText(sProcessID))
aFormErrors.addFieldError(FIELD_PROCESS_ID, "A process ID must be provided.");
else if (aProcessID == null)
aFormErrors.addFieldError(FIELD_PROCESS_ID, "The process ID could not be parsed.");
if (StringHelper.hasNoText(sPayload))
aFormErrors.addFieldError(FIELD_PAYLOAD, "A payload must be provided.");
else if (aPayloadDoc == null)
aFormErrors.addFieldError(FIELD_PAYLOAD, "The payload is not wellformed XML.");
if (aFormErrors.isEmpty()) {
final HCDiv aNL = new HCDiv().addStyle(CCSSProperties.MAX_WIDTH.newValue("80vw"));
final String sAS4PayloadDoc = XMLWriter.getNodeAsString(aPayloadDoc);
final byte[] aAS4PayloadBytes = XMLWriter.getNodeAsBytes(aPayloadDoc);
aNL.addChild(h3("Sending document"));
// Show payload
aNL.addChild(new BootstrapPrismJS(EPrismLanguage.MARKUP).addPlugin(new PrismPluginLineNumbers()).addChild(sAS4PayloadDoc));
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() + "'");
}
};
try {
final SMPClientReadOnly aSMPClient = new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST);
// What to remember
final Wrapper<String> aEndpointURL = new Wrapper<>();
final Wrapper<X509Certificate> aEndpointCert = new Wrapper<>();
final Wrapper<EPeppolCertificateCheckResult> aEndpointCertCheck = new Wrapper<>();
final Wrapper<Phase4Exception> aSendEx = new Wrapper<>();
final Wrapper<byte[]> aResponseBytes = new Wrapper<>();
final Wrapper<Ebms3SignalMessage> aResponseMsg = new Wrapper<>();
LOGGER.info("Sending Peppol AS4 message from '" + aSenderID.getURIEncoded() + "' to '" + aReceiverID.getURIEncoded() + "' using document type '" + aDocTypeID.getURIEncoded() + "' and process ID '" + aProcessID.getURIEncoded() + "'");
// Try to send message
final ESimpleUserMessageSendResult eResult = Phase4PeppolSender.builder().cryptoFactory(AS4_CF).documentTypeID(aDocTypeID).processID(aProcessID).senderParticipantID(aSenderID).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aAS4PayloadBytes).smpClient(aSMPClient).endpointURLConsumer(aEndpointURL::set).certificateConsumer((cert, dt, res) -> {
aEndpointCert.set(cert);
aEndpointCertCheck.set(res);
}).validationConfiguration(null).buildMessageCallback(aBuildMessageCallback).outgoingDumper(new AS4OutgoingDumperFileBased()).incomingDumper(new AS4IncomingDumperFileBased()).rawResponseConsumer(r -> aResponseBytes.set(r.getResponse())).signalMsgConsumer(aResponseMsg::set).sendMessageAndCheckForReceipt(aSendEx::set);
LOGGER.info("Sending Peppol AS4 message resulted in " + eResult);
if (aEndpointURL.isSet())
aNL.addChild(div("Sending to this endpoint URL: ").addChild(code(aEndpointURL.get())));
if (aEndpointCert.isSet())
aNL.addChild(div("The message is encrypted for the following receiver: ").addChild(code(aEndpointCert.get().getSubjectX500Principal().getName())));
if (aEndpointCertCheck.isSet())
aNL.addChild(div("The certificate verification resulted in: ").addChild(code(aEndpointCertCheck.get().name())));
if (eResult.isSuccess())
aNL.addChild(success("Successfully send AS4 message to Peppol receiver ").addChild(code(aReceiverID.getURIEncoded())));
else
aNL.addChild(error().addChild(div("Failed to send AS4 message to Peppol receiver ").addChild(code(aReceiverID.getURIEncoded())).addChild(" with result ").addChild(code(eResult.name()))).addChild(AppCommonUI.getTechnicalDetailsUI(aSendEx.get(), true)));
boolean bShowRaw = true;
if (aResponseMsg.isSet()) {
// Don't do XSD validation here because there is no defined
// "SignalMessage" element
final String sSignalMessage = new GenericJAXBMarshaller<>(Ebms3SignalMessage.class, GenericJAXBMarshaller.createSimpleJAXBElement(new QName(com.helger.phase4.ebms3header.ObjectFactory._Messaging_QNAME.getNamespaceURI(), "SignalMessage"), Ebms3SignalMessage.class)).setFormattedOutput(true).getAsString(aResponseMsg.get());
if (StringHelper.hasText(sSignalMessage)) {
// Show payload
aNL.addChild(div("Response ebMS Signal Message"));
aNL.addChild(new BootstrapPrismJS(EPrismLanguage.MARKUP).addPlugin(new PrismPluginLineNumbers()).addChild(sSignalMessage));
bShowRaw = false;
}
}
if (aResponseBytes.isSet()) {
if (bShowRaw) {
aNL.addChild(div("Response message - NOT a valid response"));
aNL.addChild(new BootstrapPrismJS(EPrismLanguage.MARKUP).addPlugin(new PrismPluginLineNumbers()).addChild(new String(aResponseBytes.get(), StandardCharsets.UTF_8)));
}
// Else already shown above
} else {
if (eResult.isSuccess())
aNL.addChild(error("Received no response content :("));
}
} catch (final SMPDNSResolutionException ex) {
aNL.addChild(error(div("Error creating the SMP client.")).addChild(AppCommonUI.getTechnicalDetailsUI(ex, false)));
}
if (true)
aNodeList.addChild(aNL);
else
aWPEC.postRedirectGetInternal(aNL);
}
}
aNodeList.addChild(h3("Send new Peppol AS4 message (Test network only)"));
final BootstrapForm aForm = aNodeList.addAndReturnChild(new BootstrapForm(aWPEC));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Sending participant ID").setCtrl(new HCEdit(new RequestField(FIELD_SENDER_ID, DEFAULT_SENDER_ID))).setHelpText(span("The sending Peppol participant identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_SENDER_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Receiving participant ID").setCtrl(new HCEdit(new RequestField(FIELD_RECEIVER_ID, DEFAULT_RECEIVER_ID))).setHelpText(span("The receiving Peppol participant identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_RECEIVER_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Document type ID").setCtrl(new HCEdit(new RequestField(FIELD_DOCTYPE_ID, DEFAULT_DOCTYPE_ID))).setHelpText(span("The Peppol document type identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_DOCTYPE_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Process ID").setCtrl(new HCEdit(new RequestField(FIELD_PROCESS_ID, DEFAULT_PROCESS_ID))).setHelpText(span("The Peppol process identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_PROCESS_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("XML Payload to be send").setCtrl(new HCTextArea(new RequestField(FIELD_PAYLOAD, DEFAULT_PAYLOAD.get())).setRows(8)).setHelpText("This MUST be wellformed XML - e.g. a UBL Invoice or a CII Invoice. NO Schematron validation is performed. The SBDH is added automatically.").setErrorList(aFormErrors.getListOfField(FIELD_PAYLOAD)));
aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM));
aForm.addChild(new BootstrapSubmitButton().addChild("Send Peppol AS4 message"));
}
Aggregations