java.lang.ClassCastException: class org.apache.xerces.dom.DeferredDocumentImpl cannot be cast to class com.wm.lang.xml.Document

webMethods ver 10.15

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
db = dbf.newDocumentBuilder();
Document doc = (Document) db.parse( new FileInputStream(new File(“D:\flow.xml”)));

error logs

java.lang.ClassCastException: class org.apache.xerces.dom.DeferredDocumentImpl cannot be cast to class com.wm.lang.xml.Document (org.apache.xerces.dom.DeferredDocumentImpl and com.wm.lang.xml.Document are in unnamed module of loader java.net.URLClassLoader @63f8709c)

Hi Sandeep,

why do you want to read the file like this?

Why not using the Build-In-Services from pub.file-Folder and pub.xml-Folder?
I.e.:
pub.file:getFile (as String)
pub.xml:xmlStringToXMLNode
pub.xml:xmlNodeToDocument

Regards,
Holger

After reading/parsing xml file written some complex logic in java.

Hi Sandeep,

as the error message indicates, the classes used here are not meant for public use.
This is related to the new class loading philosophy in Java.

This was recently discussed here in the community in another thread where some wanted to deploy package which was working on IS 10.5 to IS 10.15 where it was not working any longer.
Unfortunately I cannot find this thread currently.

Regards,
Holger

1 Like

Why are you casting to document then if all you need to do is parse the XML file in a Java service? Why not threat it as POJO and do everything in java service and push whatever you need back to the pipeline?

I also recommend against making things over complicated. You can still get your document as Holger told and parse however you want to parse it using Java or flow services. I don’t see the benefit off parsing the file manually.

Sandeep,

Its not recommended to use that approach as you wont be able to use the created Document to visually manage any mappings. But if you are sure of your use case and really want this you have to make sure you use org.w3c.dom.Document and not com.wm.lang.xml.Document. You can do that by fixing you import statements in the code or specifically fixing the class name as such:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
db = dbf.newDocumentBuilder();
org.w3c.dom.Document doc = db.parse( new FileInputStream(new File(“D:\flow.xml”)));

Rupinder Singh

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.