Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPIN/DOM-XML-01004 Parsing input into DOM document. #12

Open
prasenjithaty opened this issue Apr 27, 2017 · 0 comments
Open

SPIN/DOM-XML-01004 Parsing input into DOM document. #12

prasenjithaty opened this issue Apr 27, 2017 · 0 comments

Comments

@prasenjithaty
Copy link

Hi,

I am unable to parse the below XML. To be precise, I've implemented my own DataFormatConfigurator and set NamespaceAware to false to ignore namespaces. It works fine without <a:WorkflowTemplateId i:nil="true" />. From the debug logs, I can confirm that the DocumentBuilderFactory is using the custom configuration to ignore namespace.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <JobResponse xmlns="http://schemas.example.com/digital/v5.00">
         <JobResult xmlns:a="http://schemas.datacontract.org/DataContracts.BackwardsCompatibility.v500" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:CostCode>1724</a:CostCode>
            <a:ID>8115548</a:ID>
            <a:State>Completed</a:State>
            <a:Tasks>
               <a:Task>
                  <a:ID>73235022</a:ID>
                  <a:ItemID>1281863</a:ItemID>
                  <a:TypeID>31</a:TypeID>
                  <a:WorkflowTemplateId i:nil="true" />
               </a:Task>
               <a:Task>
                  <a:ID>73235023</a:ID>
                  <a:ItemID>1281864</a:ItemID>
                  <a:TypeID>4</a:TypeID>
                  <a:WorkflowTemplateId i:nil="true" />
               </a:Task>
               <a:Task>
                  <a:ID>73235024</a:ID>
                  <a:ItemID>1281865</a:ItemID>
                  <a:TypeID>4</a:TypeID>
                  <a:WorkflowTemplateId i:nil="true" />
               </a:Task>
            </a:Tasks>
         </JobResult>
      </JobResponse>
   </s:Body>
</s:Envelope>

Attaching sample code to test:

public class SampleClass {
    private static final Logger LOGGER = LoggerFactory.getLogger(SampleClass.class);

    public static void main(String[] args) {
        String str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                + "   <s:Body>\n"
                + "      <JobResponse xmlns=\"http://schemas.example.com/digital/v5.00\">\n"
                + "         <JobResult xmlns:a=\"http://schemas.datacontract.org/DataContracts.BackwardsCompatibility.v500\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
                + "            <a:CostCode>0000</a:CostCode>\n"
                + "            <a:ID>8115548</a:ID>\n"
                + "            <a:Notes i:nil=\"true\" />\n"
                + "            <a:State>Completed</a:State>\n"
                + "            <a:Tasks>\n"
                + "               <a:Task>\n"
                + "                  <a:ID>73235022</a:ID>\n"
                + "                  <a:ItemID>1281863</a:ItemID>\n"
                + "                  <a:TypeID>31</a:TypeID>\n"
                + "               <a:WorkflowTemplateId i:nil=\"true\" />\n"
                + "               </a:Task>\n"
                + "               <a:Task>\n"
                + "                  <a:ID>73235023</a:ID>\n"
                + "                  <a:ItemID>1281864</a:ItemID>\n"
                + "                  <a:TypeID>4</a:TypeID>\n"
                + "                  <a:WorkflowTemplateId i:nil=\"true\" />\n"
                + "               </a:Task>\n"
                + "               <a:Task>\n"
                + "                  <a:ID>73235024</a:ID>\n"
                + "                  <a:ItemID>1281865</a:ItemID>\n"
                + "                  <a:TypeID>4</a:TypeID>\n"
                + "                  <a:WorkflowTemplateId i:nil=\"true\" />\n"
                + "               </a:Task>\n"
                + "            </a:Tasks>\n"
                + "         </JobResult>\n"
                + "      </JobResponse>\n"
                + "   </s:Body>\n"
                + "</s:Envelope>";

        SpinXmlElement spinXmlElement = Spin.XML(str).xPath("//JobResponse/JobResult/ID").element();
        LOGGER.info("ID = {}", spinXmlElement.textContent()); // works as expected

        SpinList<SpinXmlElement> spinXmlElementSpinList = Spin.XML(str).xPath("//JobResponse/JobResult/Tasks/Task[TypeID=4]").elementList(); // throws exception. pasting logs below
        LOGGER.info("spinXmlElementSpinList = {}", spinXmlElementSpinList);
    }
}

Logs:

16:27:45.661 [main] INFO org.camunda.spin - SPIN-01010 Discovered Spin data format provider: org.camunda.spin.impl.json.jackson.format.JacksonJsonDataFormatProvider[name = application/json]
16:27:46.053 [main] INFO org.camunda.spin - SPIN-01010 Discovered Spin data format provider: org.camunda.spin.impl.xml.dom.format.DomXmlDataFormatProvider[name = application/xml]
16:27:46.060 [main] DEBUG org.camunda.spin.xml - SPIN/DOM-XML-01003 DocumentBuilderFactory configuration 'namespaceAware' 'true'
16:27:46.060 [main] DEBUG org.camunda.spin.xml - SPIN/DOM-XML-01003 DocumentBuilderFactory configuration 'validating' 'false'
16:27:46.060 [main] DEBUG org.camunda.spin.xml - SPIN/DOM-XML-01003 DocumentBuilderFactory configuration 'ignoringComments' 'true'
16:27:46.060 [main] DEBUG org.camunda.spin.xml - SPIN/DOM-XML-01003 DocumentBuilderFactory configuration 'ignoringElementContentWhitespace' 'false'
16:27:46.066 [main] DEBUG org.camunda.spin.xml - SPIN/DOM-XML-01001 Using document builder factory 'com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl'
16:27:46.072 [main] INFO org.camunda.spin - SPIN-01011 Discovered Spin data format configurator: class com.sample.myworkflow.config.CustomXmlDataFormatter[dataformat = org.camunda.spin.impl.xml.dom.format.DomXmlDataFormat]
16:27:46.073 [main] DEBUG org.camunda.spin.xml - SPIN/DOM-XML-01003 DocumentBuilderFactory configuration 'namespaceAware' 'false'
16:27:46.074 [main] INFO org.camunda.spin - SPIN-01009 Discovered Spin data format: org.camunda.spin.impl.xml.dom.format.DomXmlDataFormat[name = application/xml]
16:27:46.074 [main] INFO org.camunda.spin - SPIN-01009 Discovered Spin data format: org.camunda.spin.impl.json.jackson.format.JacksonJsonDataFormat[name = application/json]
16:27:46.117 [main] DEBUG org.camunda.spin.xml - SPIN/DOM-XML-01002 Successfully created new document builder
16:27:46.117 [main] DEBUG org.camunda.spin.xml - SPIN/DOM-XML-01004 Parsing input into DOM document.
16:27:46.165 [main] INFO com.sample.myworkflow.utils.SampleClass - ID = 8115548
16:27:46.166 [main] DEBUG org.camunda.spin.xml - SPIN/DOM-XML-01002 Successfully created new document builder
16:27:46.166 [main] DEBUG org.camunda.spin.xml - SPIN/DOM-XML-01004 Parsing input into DOM document.
ERROR:  'Namespace for prefix 'i' has not been declared.'
SLF4J: Failed toString() invocation on an object of type [org.camunda.spin.impl.SpinListImpl]
Reported exception:
org.camunda.spin.xml.SpinXmlElementException: SPIN/DOM-XML-01022 Unable to transform element 'null:a:Task'
	at org.camunda.spin.impl.xml.dom.DomXmlLogger.unableToTransformElement(DomXmlLogger.java:127)
	at org.camunda.spin.impl.xml.dom.format.DomXmlDataFormatWriter.writeResult(DomXmlDataFormatWriter.java:56)
	at org.camunda.spin.impl.xml.dom.format.DomXmlDataFormatWriter.writeToWriter(DomXmlDataFormatWriter.java:47)
	at org.camunda.spin.impl.xml.dom.DomXmlElement.writeToWriter(DomXmlElement.java:373)
	at org.camunda.spin.impl.xml.dom.DomXmlElement.toString(DomXmlElement.java:368)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at java.util.AbstractCollection.toString(AbstractCollection.java:462)
	at org.slf4j.helpers.MessageFormatter.safeObjectAppend(MessageFormatter.java:299)
	at org.slf4j.helpers.MessageFormatter.deeplyAppendParameter(MessageFormatter.java:271)
	at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:233)
	at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:173)
	at ch.qos.logback.classic.spi.LoggingEvent.getFormattedMessage(LoggingEvent.java:293)
	at ch.qos.logback.classic.spi.LoggingEvent.prepareForDeferredProcessing(LoggingEvent.java:206)
	at ch.qos.logback.core.OutputStreamAppender.subAppend(OutputStreamAppender.java:205)
	at ch.qos.logback.core.OutputStreamAppender.append(OutputStreamAppender.java:100)
	at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:84)
	at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
	at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:270)
	at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
	at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)
	at ch.qos.logback.classic.Logger.filterAndLog_1(Logger.java:398)
	at ch.qos.logback.classic.Logger.info(Logger.java:583)
	at com.sample.myworkflow.utils.SampleClass.main(SampleClass.java:54)
Caused by: javax.xml.transform.TransformerException: java.lang.RuntimeException: Namespace for prefix 'i' has not been declared.
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:746)
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:351)
	at org.camunda.spin.impl.xml.dom.format.DomXmlDataFormatWriter.writeResult(DomXmlDataFormatWriter.java:54)
	... 22 more
Caused by: java.lang.RuntimeException: Namespace for prefix 'i' has not been declared.
	at com.sun.org.apache.xml.internal.serializer.SerializerBase.getNamespaceURI(SerializerBase.java:915)
	at com.sun.org.apache.xml.internal.serializer.SerializerBase.addAttribute(SerializerBase.java:431)
	at com.sun.org.apache.xml.internal.serializer.ToUnknownStream.addAttribute(ToUnknownStream.java:316)
	at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:201)
	at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:230)
	at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:94)
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:693)
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:737)
	... 24 more
16:27:46.178 [main] INFO com.sample.myworkflow.utils.SampleClass - spinXmlElementSpinList = [FAILED toString()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant