Search in sources :

Example 1 with SMPClientReadOnly

use of com.helger.smpclient.peppol.SMPClientReadOnly in project phoss-directory by phax.

the class SMPBusinessCardProvider method getBusinessCard.

@Nullable
public PDExtendedBusinessCard getBusinessCard(@Nonnull final IParticipantIdentifier aParticipantID) {
    final HttpClientSettings aHCS = new HttpClientSettings().setProxyHost(_getHttpProxy()).setProxyCredentials(_getHttpProxyCredentials());
    PDExtendedBusinessCard aBC;
    if (m_aSMPURI != null) {
        // Use a preselected SMP URI
        switch(m_eSMPMode) {
            case PEPPOL:
                {
                    final SMPClientReadOnly aSMPClient = new SMPClientReadOnly(m_aSMPURI);
                    _configureSMPClient(aSMPClient);
                    aBC = getBusinessCardPeppolSMP(aParticipantID, aSMPClient, aHCS);
                    break;
                }
            case OASIS_BDXR_V1:
                {
                    final BDXRClientReadOnly aSMPClient = new BDXRClientReadOnly(m_aSMPURI);
                    _configureSMPClient(aSMPClient);
                    aBC = getBusinessCardBDXR1(aParticipantID, aSMPClient, aHCS);
                    break;
                }
            case OASIS_BDXR_V2:
                {
                    final BDXR2ClientReadOnly aSMPClient = new BDXR2ClientReadOnly(m_aSMPURI);
                    _configureSMPClient(aSMPClient);
                    aBC = getBusinessCardBDXR2(aParticipantID, aSMPClient, aHCS);
                    break;
                }
            default:
                throw new IllegalStateException("Unsupported SMP mode " + m_eSMPMode);
        }
    } else {
        // SML auto detect
        aBC = null;
        for (final ISMLInfo aSML : m_aSMLInfoProvider.get()) {
            // Create SMP client and query SMP
            switch(m_eSMPMode) {
                case PEPPOL:
                    {
                        try {
                            final SMPClientReadOnly aSMPClient = new SMPClientReadOnly(m_aURLProvider, aParticipantID, aSML);
                            _configureSMPClient(aSMPClient);
                            aBC = getBusinessCardPeppolSMP(aParticipantID, aSMPClient, aHCS);
                        } catch (final SMPDNSResolutionException ex) {
                        // Happens if a non-existing URL is queried
                        }
                        break;
                    }
                case OASIS_BDXR_V1:
                    {
                        try {
                            final BDXRClientReadOnly aSMPClient = new BDXRClientReadOnly(m_aURLProvider, aParticipantID, aSML);
                            _configureSMPClient(aSMPClient);
                            aBC = getBusinessCardBDXR1(aParticipantID, aSMPClient, aHCS);
                        } catch (final SMPDNSResolutionException ex) {
                        // Happens if a non-existing URL is queried
                        }
                        break;
                    }
                case OASIS_BDXR_V2:
                    {
                        try {
                            final BDXR2ClientReadOnly aSMPClient = new BDXR2ClientReadOnly(m_aURLProvider, aParticipantID, aSML);
                            _configureSMPClient(aSMPClient);
                            aBC = getBusinessCardBDXR2(aParticipantID, aSMPClient, aHCS);
                        } catch (final SMPDNSResolutionException ex) {
                        // Happens if a non-existing URL is queried
                        }
                        break;
                    }
                default:
                    throw new IllegalStateException("Unsupported SMP mode " + m_eSMPMode);
            }
            // Found one?
            if (aBC != null)
                break;
        }
    }
    if (aBC != null)
        LOGGER.info("Found BusinessCard for '" + aParticipantID.getURIEncoded() + "' with " + aBC.getBusinessCard().businessEntities().size() + " entities and " + aBC.getDocumentTypeCount() + " document types");
    return aBC;
}
Also used : BDXR2ClientReadOnly(com.helger.smpclient.bdxr2.BDXR2ClientReadOnly) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) ISMLInfo(com.helger.peppol.sml.ISMLInfo) HttpClientSettings(com.helger.httpclient.HttpClientSettings) SMPDNSResolutionException(com.helger.smpclient.url.SMPDNSResolutionException) BDXRClientReadOnly(com.helger.smpclient.bdxr1.BDXRClientReadOnly) Nullable(javax.annotation.Nullable)

Example 2 with SMPClientReadOnly

use of com.helger.smpclient.peppol.SMPClientReadOnly in project phase4 by phax.

the class Phase4PeppolWebAppListener method _initPeppolAS4.

private static void _initPeppolAS4() {
    // Check if crypto properties are okay
    final KeyStore aKS = AS4CryptoFactoryProperties.getDefaultInstance().getKeyStore();
    if (aKS == null)
        throw new InitializationException("Failed to load configured Keystore");
    LOGGER.info("Successfully loaded configured key store from the crypto factory");
    final PrivateKeyEntry aPKE = AS4CryptoFactoryProperties.getDefaultInstance().getPrivateKeyEntry();
    if (aPKE == null)
        throw new InitializationException("Failed to load configured private key");
    LOGGER.info("Successfully loaded configured private key from the crypto factory");
    // No OCSP check for performance
    final X509Certificate aAPCert = (X509Certificate) aPKE.getCertificate();
    final EPeppolCertificateCheckResult eCheckResult = PeppolCertificateChecker.checkPeppolAPCertificate(aAPCert, MetaAS4Manager.getTimestampMgr().getCurrentDateTime(), ETriState.FALSE, null);
    if (eCheckResult.isInvalid())
        throw new InitializationException("The provided certificate is not a valid Peppol certificate. Check result: " + eCheckResult);
    LOGGER.info("Successfully checked that the provided Peppol AP certificate is valid.");
    final String sSMPURL = AS4Configuration.getConfig().getAsString("smp.url");
    final String sAPURL = AS4Configuration.getThisEndpointAddress();
    if (StringHelper.hasText(sSMPURL) && StringHelper.hasText(sAPURL)) {
        Phase4PeppolServletConfiguration.setReceiverCheckEnabled(true);
        Phase4PeppolServletConfiguration.setSMPClient(new SMPClientReadOnly(URLHelper.getAsURI(sSMPURL)));
        Phase4PeppolServletConfiguration.setAS4EndpointURL(sAPURL);
        Phase4PeppolServletConfiguration.setAPCertificate(aAPCert);
        LOGGER.info(CAS4.LIB_NAME + " Peppol receiver checks are enabled");
    } else {
        Phase4PeppolServletConfiguration.setReceiverCheckEnabled(false);
        LOGGER.warn(CAS4.LIB_NAME + " Peppol receiver checks are disabled");
    }
}
Also used : EPeppolCertificateCheckResult(com.helger.peppol.utils.EPeppolCertificateCheckResult) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) InitializationException(com.helger.commons.exception.InitializationException) KeyStore(java.security.KeyStore) PrivateKeyEntry(java.security.KeyStore.PrivateKeyEntry) X509Certificate(java.security.cert.X509Certificate)

Example 3 with SMPClientReadOnly

use of com.helger.smpclient.peppol.SMPClientReadOnly in project phase4 by phax.

the class MainPhase4PeppolSenderQvaliaLargeFile 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/large-files/base-example-large-16m.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("0007:5567321707");
        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() + "'");
            }
        };
        // Invalid certificate is valid until 2029
        final IAS4CryptoFactory cf = AS4CryptoFactoryProperties.getDefaultInstance();
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().httpRetrySettings(new HttpRetrySettings().setMaxRetries(0)).cryptoFactory(cf).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)).validationConfiguration(PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, new Phase4PeppolValidatonResultHandler()).compressPayload(false).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();
    }
}
Also used : IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) HttpRetrySettings(com.helger.phase4.http.HttpRetrySettings) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 4 with SMPClientReadOnly

use of com.helger.smpclient.peppol.SMPClientReadOnly in project phase4 by phax.

the class MainPhase4PeppolSenderQvaliaOrder 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/test-order.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("0007:5567321707");
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Order-2::Order##urn:fdc:peppol.eu:poacc:trns:order:3::2.1")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:poacc:bis:ordering:3")).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_ORDER_V3, 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();
    }
}
Also used : SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) Element(org.w3c.dom.Element) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 5 with SMPClientReadOnly

use of com.helger.smpclient.peppol.SMPClientReadOnly in project phase4 by phax.

the class MainPhase4PeppolSenderQvaliaUBL 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/example-ubl-en-qvalia.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("0007:5567321707");
        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() + "'");
            }
        };
        // Add EN16931 rulesets
        final IValidationExecutorSetRegistry<IValidationSourceXML> aVESRegistry = Phase4PeppolValidation.createDefaultRegistry();
        EN16931Validation.initEN16931(aVESRegistry);
        // Invalid certificate is valid until 2029
        final IAS4CryptoFactory cf = AS4CryptoFactoryProperties.getDefaultInstance();
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().httpRetrySettings(new HttpRetrySettings().setMaxRetries(0)).cryptoFactory(cf).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()).validationRegistry(aVESRegistry).validationConfiguration(EN16931Validation.VID_UBL_INVOICE_137, 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();
    }
}
Also used : IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) HttpRetrySettings(com.helger.phase4.http.HttpRetrySettings) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Aggregations

SMPClientReadOnly (com.helger.smpclient.peppol.SMPClientReadOnly)45 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)40 ESimpleUserMessageSendResult (com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult)34 File (java.io.File)34 Element (org.w3c.dom.Element)33 AS4RawResponseConsumerWriteToFile (com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile)30 AS4IncomingDumperFileBased (com.helger.phase4.dump.AS4IncomingDumperFileBased)28 AS4OutgoingDumperFileBased (com.helger.phase4.dump.AS4OutgoingDumperFileBased)28 IAS4ClientBuildMessageCallback (com.helger.phase4.client.IAS4ClientBuildMessageCallback)13 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)13 AbstractAS4Message (com.helger.phase4.messaging.domain.AbstractAS4Message)13 IAS4CryptoFactory (com.helger.phase4.crypto.IAS4CryptoFactory)4 HttpRetrySettings (com.helger.phase4.http.HttpRetrySettings)4 IValidationSourceXML (com.helger.phive.engine.source.IValidationSourceXML)4 HttpClientSettings (com.helger.httpclient.HttpClientSettings)3 IAS4RawResponseConsumer (com.helger.phase4.client.IAS4RawResponseConsumer)3 X509Certificate (java.security.cert.X509Certificate)3 InitializationException (com.helger.commons.exception.InitializationException)2 StopWatch (com.helger.commons.timing.StopWatch)2 IJsonObject (com.helger.json.IJsonObject)2