Search in sources :

Example 6 with IValidationSourceXML

use of com.helger.phive.engine.source.IValidationSourceXML in project phive by phax.

the class VOM1ConverterTest method testReadGoodExamples.

@Test
public void testReadGoodExamples() {
    final VOM1Marshaller m = new VOM1Marshaller();
    for (final File f : new FileSystemIterator(new File("src/test/resources/vom/good")).withFilter(IFileFilter.filenameEndsWith(".xml"))) {
        LOGGER.info("Reading " + f.getName());
        final VOMType aVOM = m.read(f);
        assertNotNull(aVOM);
        final IReadableResource aFakeXSD = new ReadableResourceByteArray("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"urn:1\" targetNamespace=\"urn:a\" version=\"1.0\"><xs:element name=\"a\" type=\"xs:string\" /></xs:schema>".getBytes(StandardCharsets.ISO_8859_1));
        final Schema aFakeSchema = XMLSchemaCache.getInstance().getSchema(aFakeXSD);
        final IVOMXmlSchemaResolver aXmlSchemaResolver = new MapBasedVOMXmlSchemaResolver().addMapping("ubl21-invoice", aFakeSchema);
        final IVOMNamespaceContextResolver aNamespaceContextResolver = new MapBasedVOMNamespaceContextResolver().addMapping("ubl21", new MapBasedNamespaceContext().addMapping("a", "urn:a"));
        final IVOMResourceResolver aResourceResolver = new MapBasedVOMResourceResolver().addMapping("cius-pt-200", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("cius-pt-201", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("atnat-invoice-6", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("xrechnung-ublinv-200", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("en16931-ublinv-132", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY));
        final IVOMArtifactResolver aAR = aVESID -> {
            switch(aVESID.getAsSingleID()) {
                case "com.helger:test-special:1.5.678":
                    return new ReadableResourceByteArray("crap".getBytes(StandardCharsets.ISO_8859_1));
            }
            return null;
        };
        final IEdifactValidationExecutorProviderXML aEdifactProvider = (sDirectory, sMessage, aOptions) -> {
            if (sDirectory.equals("d01b") && sMessage.equals("DESADV"))
                return ValidationExecutorXSD.create(aFakeXSD);
            return null;
        };
        final VOM1ComplianceSettings aSettings = VOM1ComplianceSettings.builder().allowEdifact(true).edifactValidationExecutorProviderXML(aEdifactProvider).build();
        final ErrorList aErrorList = new ErrorList();
        final VOM1Converter aConverter1 = new VOM1Converter().xmlSchemaResolver(aXmlSchemaResolver).namespaceContextResolver(aNamespaceContextResolver).resourceResolver(aResourceResolver).complianceSettings(aSettings).artifactResolver(aAR).validationEnabled(true);
        final ValidationExecutorSet<IValidationSourceXML> aVES = aConverter1.convertToVES_XML(aVOM, aErrorList);
        assertNotNull(aErrorList.toString(), aVES);
    }
}
Also used : IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) Logger(org.slf4j.Logger) ValidationExecutorSet(com.helger.phive.api.executorset.ValidationExecutorSet) Assert.assertNotNull(org.junit.Assert.assertNotNull) ErrorList(com.helger.commons.error.list.ErrorList) MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) LoggerFactory(org.slf4j.LoggerFactory) IReadableResource(com.helger.commons.io.resource.IReadableResource) Test(org.junit.Test) FileSystemIterator(com.helger.commons.io.file.FileSystemIterator) ValidationExecutorXSD(com.helger.phive.engine.xsd.ValidationExecutorXSD) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Schema(javax.xml.validation.Schema) IFileFilter(com.helger.commons.io.file.IFileFilter) ReadableResourceByteArray(com.helger.commons.io.resource.inmemory.ReadableResourceByteArray) XMLSchemaCache(com.helger.xml.schema.XMLSchemaCache) VOMType(com.helger.phive.engine.vom.v10.VOMType) ArrayHelper(com.helger.commons.collection.ArrayHelper) VOMType(com.helger.phive.engine.vom.v10.VOMType) Schema(javax.xml.validation.Schema) IReadableResource(com.helger.commons.io.resource.IReadableResource) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) ReadableResourceByteArray(com.helger.commons.io.resource.inmemory.ReadableResourceByteArray) IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) ErrorList(com.helger.commons.error.list.ErrorList) FileSystemIterator(com.helger.commons.io.file.FileSystemIterator) File(java.io.File) Test(org.junit.Test)

Example 7 with IValidationSourceXML

use of com.helger.phive.engine.source.IValidationSourceXML in project phase4 by phax.

the class MainPhase4PeppolSenderQvaliaCII 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/cii/cii-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");
        // Add EN16931 rulesets
        final IValidationExecutorSetRegistry<IValidationSourceXML> aVESRegistry = Phase4PeppolValidation.createDefaultRegistry();
        EN16931Validation.initEN16931(aVESRegistry);
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().httpRetrySettings(new HttpRetrySettings().setMaxRetries(0)).documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100::CrossIndustryInvoice##urn:cen.eu:en16931:2017::D16B")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:poacc:en16931:any")).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_CII_137, 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) Element(org.w3c.dom.Element) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) HttpRetrySettings(com.helger.phase4.http.HttpRetrySettings) 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)

Example 8 with IValidationSourceXML

use of com.helger.phive.engine.source.IValidationSourceXML in project phase4 by phax.

the class MainPhase4PeppolSenderHelgerXRechnung12CII method send.

@SuppressWarnings("deprecation")
public static void send() {
    try {
        final Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/examples/xrechnung-1.2-cii-example1.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 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 Wrapper<Ebms3SignalMessage> aSignalMsgWrapper = new Wrapper<>();
        final IAS4RawResponseConsumer aRRC = new AS4RawResponseConsumerWriteToFile().setHandleStatusLine(true).setHandleHttpHeaders(true);
        // Add XRechnung rulesets
        final IValidationExecutorSetRegistry<IValidationSourceXML> aVESRegistry = Phase4PeppolValidation.createDefaultRegistry();
        EN16931Validation.initEN16931(aVESRegistry);
        XRechnungValidation.initXRechnung(aVESRegistry);
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100::CrossIndustryInvoice##urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_1.2::D16B")).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)).validationRegistry(aVESRegistry).validationConfiguration(XRechnungValidation.VID_XRECHNUNG_CII_122, new Phase4PeppolValidatonResultHandler()).buildMessageCallback(aBuildMessageCallback).rawResponseConsumer(aRRC).signalMsgConsumer(aSignalMsgWrapper::set).sendMessageAndCheckForReceipt();
        LOGGER.info("Peppol send result: " + eResult);
    } catch (final Exception ex) {
        LOGGER.error("Error sending Peppol message via AS4", ex);
    }
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) Wrapper(com.helger.commons.wrapper.Wrapper) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) IAS4RawResponseConsumer(com.helger.phase4.client.IAS4RawResponseConsumer) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 9 with IValidationSourceXML

use of com.helger.phive.engine.source.IValidationSourceXML in project phase4 by phax.

the class Phase4PeppolValidation method validateOutgoingBusinessDocument.

/**
 * Validate the passed DOM element using the provided VESID using the provided
 * registry.
 *
 * @param aXML
 *        The XML element to be validated. May not be <code>null</code>.
 * @param aVESRegistry
 *        The VES registry the VESID is looked up in.
 * @param aVESID
 *        The {@link VESID} to be used. Must be contained in the provided
 *        registry. May not be <code>null</code>.
 * @param aValidationResultHandler
 *        The validation result handler to be used. May not be
 *        <code>null</code>.
 * @throws Phase4PeppolException
 *         In case e.g. the validation failed. This usually implies, that the
 *         document will NOT be send out.
 * @since 0.10.1
 */
public static void validateOutgoingBusinessDocument(@Nonnull final Element aXML, @Nonnull final IValidationExecutorSetRegistry<IValidationSourceXML> aVESRegistry, @Nonnull final VESID aVESID, @Nonnull final IPhase4PeppolValidationResultHandler aValidationResultHandler) throws Phase4PeppolException {
    ValueEnforcer.notNull(aXML, "XMLElement");
    ValueEnforcer.notNull(aVESRegistry, "VESRegistry");
    ValueEnforcer.notNull(aVESID, "VESID");
    ValueEnforcer.notNull(aValidationResultHandler, "ValidationResultHandler");
    final IValidationExecutorSet<IValidationSourceXML> aVES = aVESRegistry.getOfID(aVESID);
    if (aVES == null)
        throw new Phase4PeppolException("The validation executor set ID " + aVESID.getAsSingleID() + " is unknown!");
    final ValidationResultList aValidationResult = ValidationExecutionManager.executeValidation(aVES, ValidationSourceXML.create(null, aXML));
    if (aValidationResult.containsAtLeastOneError()) {
        aValidationResultHandler.onValidationErrors(aValidationResult);
        LOGGER.warn("Continue to send AS4 message, although validation errors are contained!");
    } else
        aValidationResultHandler.onValidationSuccess(aValidationResult);
}
Also used : ValidationResultList(com.helger.phive.api.result.ValidationResultList) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML)

Example 10 with IValidationSourceXML

use of com.helger.phive.engine.source.IValidationSourceXML in project phase4 by phax.

the class MainPhase4PeppolSenderCisboxXRechnung 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/xrechnung-2.0.0-ubl-inv.xml")).getDocumentElement();
        if (aPayloadElement == null)
            throw new IllegalStateException("Failed to read XML file to be send");
        // Add XRechnung rulesets
        final IValidationExecutorSetRegistry<IValidationSourceXML> aVESRegistry = Phase4PeppolValidation.createDefaultRegistry();
        EN16931Validation.initEN16931(aVESRegistry);
        XRechnungValidation.initXRechnung(aVESRegistry);
        // Start configuring here
        final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:cisbox1");
        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:xoev-de:kosit:standard:xrechnung_2.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(XRechnungValidation.VID_XRECHNUNG_UBL_INVOICE_200, 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) Element(org.w3c.dom.Element) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) 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

IValidationSourceXML (com.helger.phive.engine.source.IValidationSourceXML)10 File (java.io.File)5 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)4 AS4RawResponseConsumerWriteToFile (com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile)4 ESimpleUserMessageSendResult (com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult)4 SMPClientReadOnly (com.helger.smpclient.peppol.SMPClientReadOnly)4 Element (org.w3c.dom.Element)4 AS4IncomingDumperFileBased (com.helger.phase4.dump.AS4IncomingDumperFileBased)3 AS4OutgoingDumperFileBased (com.helger.phase4.dump.AS4OutgoingDumperFileBased)3 ValidationExecutorSet (com.helger.phive.api.executorset.ValidationExecutorSet)3 ErrorList (com.helger.commons.error.list.ErrorList)2 IAS4ClientBuildMessageCallback (com.helger.phase4.client.IAS4ClientBuildMessageCallback)2 HttpRetrySettings (com.helger.phase4.http.HttpRetrySettings)2 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)2 AbstractAS4Message (com.helger.phase4.messaging.domain.AbstractAS4Message)2 ValidationResultList (com.helger.phive.api.result.ValidationResultList)2 IEdifactValidationExecutorProviderXML (com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML)2 Nonnull (javax.annotation.Nonnull)2 Schema (javax.xml.validation.Schema)2 Test (org.junit.Test)2