use of com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult in project phase4 by phax.
the class MainPhase4PeppolSenderMinimumPersistent method main.
public static void main(final String[] args) {
// Enable persistent managers
SystemProperties.setPropertyValue(AS4Configuration.PROPERTY_PHASE4_MANAGER_INMEMORY, false);
WebScopeManager.onGlobalBegin(MockServletContext.create());
// Set data IO base directory
final File aSCPath = new File(AS4Configuration.getDataPath()).getAbsoluteFile();
WebFileIO.initPaths(aSCPath, aSCPath.getAbsolutePath(), false);
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("9915:test");
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)).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 AbstractAS4UserMessageBuilder method sendMessageAndCheckForReceipt.
/**
* This is a sanity method that encapsulates all the sending checks that are
* necessary to determine overall sending success or error.<br>
* Note: this method is not thread-safe, because it changes the signal message
* consumer internally.
*
* @param aExceptionConsumer
* An optional Consumer that takes an eventually thrown
* {@link Phase4Exception}. May be <code>null</code>.
* @return {@link ESimpleUserMessageSendResult#SUCCESS} only if all parameters
* are correct, HTTP transmission was successful and if a positive AS4
* Receipt was returned. Never <code>null</code>.
* @since 1.0.0-rc1
*/
@Nonnull
public final ESimpleUserMessageSendResult sendMessageAndCheckForReceipt(@Nullable final Consumer<? super Phase4Exception> aExceptionConsumer) {
final IAS4SignalMessageConsumer aOld = m_aSignalMsgConsumer;
try {
// Store the received signal message
final Wrapper<Ebms3SignalMessage> aSignalMsgKeeper = new Wrapper<>();
m_aSignalMsgConsumer = aOld == null ? aSignalMsgKeeper::set : x -> {
aSignalMsgKeeper.set(x);
aOld.handleSignalMessage(x);
};
// Main sending
if (sendMessage().isFailure()) {
// Parameters are missing/incorrect
return ESimpleUserMessageSendResult.INVALID_PARAMETERS;
}
final Ebms3SignalMessage aSignalMsg = aSignalMsgKeeper.get();
if (aSignalMsg == null) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Failed to get a SignalMessage as the response");
// Unexpected response - invalid XML or at least no Ebms3 signal message
return ESimpleUserMessageSendResult.NO_SIGNAL_MESSAGE_RECEIVED;
}
if (aSignalMsg.hasErrorEntries()) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("The received SignalMessage contains at lease one error");
// Errors have precedence over receipts
return ESimpleUserMessageSendResult.AS4_ERROR_MESSAGE_RECEIVED;
}
if (aSignalMsg.getReceipt() != null) {
// A receipt was returned - this is deemed success
return ESimpleUserMessageSendResult.SUCCESS;
}
if (LOGGER.isDebugEnabled())
LOGGER.debug("The SignalMessage contains neither Errors nor a Receipt - unexpected SignalMessage layout.");
// Neither an error nor a receipt was returned - this is weird
return ESimpleUserMessageSendResult.INVALID_SIGNAL_MESSAGE_RECEIVED;
} catch (final Phase4Exception ex) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("An exception occurred sending out the AS4 message", ex);
if (aExceptionConsumer != null)
aExceptionConsumer.accept(ex);
// Something went wrong - see the logs
return ESimpleUserMessageSendResult.TRANSPORT_ERROR;
} finally {
// Restore the original value
m_aSignalMsgConsumer = aOld;
}
}
use of com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult in project phase4 by phax.
the class MainPhase4PeppolSenderInMemoryKeyStore method main.
public static void main(final String[] args) {
WebScopeManager.onGlobalBegin(MockServletContext.create());
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("9914:atu68241501");
final KeyStore aKS = KeyStoreHelper.loadKeyStoreDirect(EKeyStoreType.PKCS12, "test-ap.p12", "peppol");
if (aKS == null)
throw new IllegalStateException();
final KeyStore aTS = KeyStoreHelper.loadKeyStoreDirect(EKeyStoreType.JKS, "complete-truststore.jks", "peppol");
if (aTS == null)
throw new IllegalStateException();
final IAS4CryptoFactory aInMemoryCryptoFactory = new AS4CryptoFactoryInMemoryKeyStore(aKS, "openpeppol aisbl id von pop000306", "peppol", aTS);
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()).cryptoFactory(aInMemoryCryptoFactory).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 MainPhase4PeppolSenderIntunor 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("9914:intunor-test");
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 phase4 by phax.
the class MainPhase4PeppolSenderLocalHost8080 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("9915:helger");
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" + "MIIF2DCCA8CgAwIBAgIQBcAefsdQIk7jCCLVCAicizANBgkqhkiG9w0BAQsFADBr MQswCQYDVQQGEwJCRTEZMBcGA1UEChMQT3BlblBFUFBPTCBBSVNCTDEWMBQGA1UE CxMNRk9SIFRFU1QgT05MWTEpMCcGA1UEAxMgUEVQUE9MIEFDQ0VTUyBQT0lOVCBU RVNUIENBIC0gRzIwHhcNMjEwNTI0MDAwMDAwWhcNMjMwNTE0MjM1OTU5WjBlMQsw CQYDVQQGEwJBVDEpMCcGA1UECgwgUGhpbGlwIEhlbGdlciBJVCBDb25zdWx0aW5n IGUuVS4xFzAVBgNVBAsMDlBFUFBPTCBURVNUIEFQMRIwEAYDVQQDDAlQT1AwMDAz MDYwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCZ5JhELH0Dt9BIViJM +G1KaXNkTJLXQnJk/iBRz1DamVDEFgO7TK68iJ61Uo3K5YyG+hry88Xuq+3ld5sA o/bHkPM+jXkxXSypa7xJooWtmPVNsTanMXWSwckOCuXN1g3+cSXucgJSCGlxJ7C6 48rsbb0w0Ax7/rc0L5oSMoG3D/PS+8JwMOzskp1h/obQ2inwUmHYQ8k3XnugjQGi dZk3Yg3F262bGtjDoBALJoscz6tQzYl5cSYvxG17U8a4d9la1tFFGO7nKJOYRoAj QlbHZmG0X9NJycL9GlCN8lc4kQdqy/0yWMdFD8VavS3hPJXYgnoB6+7tUXqwkwCM yPELAgMBAAGjggF8MIIBeDAMBgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIDqDAW BgNVHSUBAf8EDDAKBggr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4Hso vspud5kJ+cB9hYT1Xqbjq0RT9asvMz3g6HMyD/64ip9BXocAbe6zb4ueU8tKkDIP QN2iwe7sEx4qUZf3" + "-----END CERTIFICATE-----\r\n"), "http://localhost:8080/as4").rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).sendMessageAndCheckForReceipt();
LOGGER.info("Peppol send result: " + eResult);
} catch (final Exception ex) {
LOGGER.error("Error sending Peppol message via AS4", ex);
} finally {
WebScopeManager.onGlobalEnd();
}
}
Aggregations