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);
}
}
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();
}
}
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);
}
}
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);
}
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();
}
}
Aggregations