punc1
punc1

Reputation: 11

Is it possible to get the error text that is outside the StackTrace?

Logs:

2024-10-25 09:53:02,293 [INFO][VPNM-INSIDE-CONTROL] Started downloading file from MinIO: ON_RISKSDNALMON_1_430_00_05_03_01.xsd
2024-10-25 09:53:04,144 [INFO][VPNM-INSIDE-CONTROL] File successfully downloaded from MinIO: ON_RISKSDNALMON_1_430_00_05_03_01.xsd
2024-10-25 09:53:04,764 [INFO][VPNM-INSIDE-CONTROL] Started downloading file from MinIO: ON_RISKSDNALMON_1_430_00_05_03_01.xslt
2024-10-25 09:53:04,794 [INFO][VPNM-INSIDE-CONTROL] File successfully loaded from MinIO: ON_RISKSDNALMON_1_430_00_05_03_01.xslt

The condition for the presence (absence) of the File/Document/Signatory/SvPred element was not met when the PrSubd element value was equal to "2".

Error at xsl:message on line 45 column 42 XTMM9000 Processing terminated by xsl:message at line 45 in In template rule with match="Signer" on line 40 of invoked by built-in template rule (text-only) In template rule with match="File" on line 30 of invoked by xsl:apply-templates (tail calls omitted) at #36 2024-10-25 09:53:42,086 [ERROR][VPNM-INSIDE-CONTROL] Error generating XML for RISKSDNALMON with parameters: idPeriod=2, idSignature=1, idDocument=ON_RISKSDNALMON_7700_7700_7710016640770701001_20241025_a4fc4f02-c330-4782-a625-f77a7989c290, idCompany=2 java.lang.RuntimeException: Errors when validating XML terminated by XSD: Processing d by xsl:message at line 45 in at 

Validation method:

    private void validateXmlBySchematronRules(String xml, InputStream xsltInputStream, CustomErrorHandler errorHandler, String xmlName) throws SaxonApiException, IOException {

            Processor processor = new Processor(false);
            XsltCompiler compiler = processor.newXsltCompiler();
            XsltExecutable xslt = compiler.compile(new StreamSource(xsltInputStream));
            XsltTransformer transformer = xslt.load();

            ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
            xmlOutputStream.write(xml.getBytes(StandardCharsets.UTF_8));

            transformer.setParameter(new QName("fileName"), new XdmAtomicValue(xmlName));

            ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
            transformer.setSource(new StreamSource(xmlInputStream));
            XdmDestination chainResult = new XdmDestination();
            transformer.setDestination(chainResult);
            transformer.transform();


            List<String> errorList = new ArrayList<>();
            XdmNode rootNode = chainResult.getXdmNode();
            Iterator<XdmNode> childrenIterator = rootNode.children().iterator();
            if (childrenIterator.hasNext()) {
                XdmNode firstChild = childrenIterator.next();
                for (XdmNode node : firstChild.children()) {
                    if (!"failed-assert".equals(node.getNodeName().getLocalName())) continue;
                    String res = node.children().iterator().next().getStringValue();
                    errorList.add(formatString(res));
                }
            }

            if (!errorList.isEmpty()) {
                errorHandler.getErrors().addAll(errorList);
            }
    }

In debug mode I see only the main stack trace:

2024-10-25 09:53:42,086 [ERROR][VPNM-INSIDE-CONTROL] Error generating XML for RISKSDNALMON with parameters: idPeriod=2, idSignature=1, idDocument=ON_RISKSDNALMON_7700_7700_7710016640770701001_20241025_a4fc4f02-c330-4782-a625-f77a7989c290, idCompany=2 java.lang.RuntimeException: Errors while validating XML against XSD: Processing terminated by xsl:message at line 45 in etc.

But I need to take the error that is above this StackTrace:

The condition of presence (absence) of the File/Document/Signatory/SvPred element is not met with the value of the PrSubp element equal to "2". Is there any way to do this?

Upvotes: 0

Views: 43

Answers (0)

Related Questions