Highlighted

coercion error: com.adobe.idp.Document to type: interface org.w3c.dom.Document

Avatar

Avatar

Mark_Lindberg

Avatar

Mark_Lindberg

Mark_Lindberg

26-03-2009

Greetings All:<br />I hope you can help me overcome an issue I am having receiving XML file attachments in an e-Mail endpoint. The process should place each attachment in a folder as an XML file on the server.<br /><br />Just a note, this process was working fine - and as some content has been added to the XML file it broke the process.<br />An e-Mail is received with a file attachment.<br />The Attachment_Map is read, and the entry is selected.<br />The entry is mapped to a process variable of type XML.<br /><br />The process fails with this:<br />Caused by: ALC-DSC-119-000: com.adobe.idp.dsc.util.InvalidCoercionException: Cannot coerce object: <document state="passive" senderVersion="3" persistent="false" senderPersistent="true" passivated="true" senderPassivated="true" deserialized="true" senderHostId="127.0.0.1/192.168.50.97" callbackId="0" senderCallbackId="0" callbackRef="null" isLocalizable="true" isTransactionBound="false" defaultDisposalTimeout="600" disposalTimeout="600" maxInlineSize="65536" defaultMaxInlineSize="65536" inlineSize="17157" contentType="application/xml" length="-1"><cacheId/><localBackendId/><globalBackendId/><senderLocalBackendId/><senderGlobalBackendId/><inline>&#65279;<?xml version="1.0" encoding="UTF-8"?><NewJobOrderInfo xmlns="http://TPIWebPAS" xmlns:xsd="http:/...</inline><senderPullServantJndiName>adobe/idp/DocumentPullServant/adobejb_server1</senderPullServantJndiName><attributes wsfilename="JobOrders.xml" basename="JobOrders.xml" file="JobOrders.xml" JKFileOrder="2"/></document> of type: com.adobe.idp.Document to type: interface org.w3c.dom.Document<br /><br />If I amend the process to write a "Text" file to the server, that step works - but the next process that needs to use it as XML cannot coerce it.<br /><br />I do not understand what is causing this to fail. It seems isolated to the particular XML attachment - as previous files will still run thru the process fine. I have run the XML in various tools that say it is "well formatted", but I don't know what are the critical items for conversion to XML.<br /><br />I am looking for ideas on where to look.<br /><br />Thank You for you assistance<br />Best Regards<br />Mark

Replies

Highlighted

Avatar

Avatar

Steve_L_Walker

Total Posts

1.4K

Likes

197

Correct Answer

212

Avatar

Steve_L_Walker

Total Posts

1.4K

Likes

197

Correct Answer

212
Steve_L_Walker

26-03-2009

Mark,



If you send the XML instance to stwalker.adobe@gmail.com I can take a look.



Steve
Highlighted

Avatar

Avatar

Mark_Lindberg

Avatar

Mark_Lindberg

Mark_Lindberg

26-03-2009

Problem Solved - Question remains.
The issue was that some tags had a blank before the end:

instead of

This change allows the file to coerce to XML, but If something like this happens in the future, I don't know how to isolate the problem.
The files I am dealing with are quite large - so side-by-side comparisons are difficult, even with some of the tools that help.

Does anyone have any tricks they use for validating XML either in Workbench, or eslewhere?

Thanks!
Mark
Highlighted

Avatar

Avatar

Steve_L_Walker

Total Posts

1.4K

Likes

197

Correct Answer

212

Avatar

Steve_L_Walker

Total Posts

1.4K

Likes

197

Correct Answer

212
Steve_L_Walker

27-03-2009

Mark,



I created a process with an email endpoint that extracts the xml attachment and writes the xml out to the file system. I tested an xml document with a blank inserted before the end tag and there was no complaints from LiveCycle. In fact, in the xml written to the file system the blank has been removed.



Are you trying to map the input xml process variable to another xml process variable?



Steve
Highlighted

Avatar

Avatar

Mark_Lindberg

Avatar

Mark_Lindberg

Mark_Lindberg

27-03-2009

Hi Steve:
This has been a learning experience for me.
It appears that the XML editor I downloaded "Corrects" XML without telling you.
Once I noticed it was doing that, I found what it had changed.
The following is an example of the changes it made:
From:

To:


So the editor removed the trailing space, and added an end tag.
These changes made the XML valid to the LiveCycle service that tries to coerce data.

As far as the process goes, I have an E-Mail endpoint that is receiving data from another system. It reads the attachment map, expecting XML - and writes XML files to a watched folder.
The Watched Folder process parses each XML file, and acts on the data inside.

I have not found a way to test contents of a variable to determine if it is valid XML that does not blow up the process as a result of bad XML.

Thanks for your time.
Mark
Highlighted

Avatar

Avatar

Steve_L_Walker

Total Posts

1.4K

Likes

197

Correct Answer

212

Avatar

Steve_L_Walker

Total Posts

1.4K

Likes

197

Correct Answer

212
Steve_L_Walker

27-03-2009

Mark,



There are several possibilities. The first is less applicable to your process.



1) If you use the Read XML operation in the File Utilities, you can catch a FileUtilsException. I can catch the exception and react accordingly.



2) I put together the following script. It works quite nicely if the XML is represented by a string. The script gets the process variable 'xmlStr' of type string, runs the XML against the DOM parser, checks for well-formedness, and reports the results in a process variable called 'resultMsg'. This could (and should) be termed into a custom component quite easily. Give it a shot.



import java.io.InputStream;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.DocumentBuilder;

import org.w3c.dom.Document;

import org.xml.sax.SAXException;



String xmlStr = patExecContext.getProcessDataStringValue("/process_data/@xmlStr");

String resultMsg = "";



DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

InputStream inputStream = new ByteArrayInputStream(xmlStr.getBytes("UTF-8"));



try {

Document document = builder.parse(inputStream);

resultMsg = "Valid XML";

}

catch (SAXException saxException) {

resultMsg = "Invalid XML";

}



patExecContext.setProcessDataStringValue("/process_data/@resultMsg",resultMsg);
Highlighted

Avatar

Avatar

Mark_Lindberg

Avatar

Mark_Lindberg

Mark_Lindberg

27-03-2009

Wow Steve!

Very helpful!

I can definitely use the Read XML error path. I plan to use the script you provided to validate the e-mail attachment prior to trying the Write XML to the watched folder.



Thanks so much

Mark
Highlighted

Avatar

Avatar

Mark_Lindberg

Avatar

Mark_Lindberg

Mark_Lindberg

27-03-2009

Steve:

One other question.

What method should I look at to take a Attachment Map Entry of type application/xml and render it to a string variable?



Thanks

Mark
Highlighted

Avatar

Avatar

Steve_L_Walker

Total Posts

1.4K

Likes

197

Correct Answer

212

Avatar

Steve_L_Walker

Total Posts

1.4K

Likes

197

Correct Answer

212
Steve_L_Walker

27-03-2009

Are the attachments really in a map? Hmmm.



You will have to use the Collection functions 'get-collection-size', 'get-map-keys' and 'get-map-values'.



- initialize a process variable, say 'i', and set it to 1

- create another process variable, say 'j', and set it using 'get-collection-size' on the map variable

- create a loop using a Set Value operation and iterate over the map until 'i > j'

- get each map entry and coerce the XML to a string



See http://livedocs.adobe.com/livecycle/8.2/wb_help/000262.html



Steve
Highlighted

Avatar

Avatar

Mark_Lindberg

Avatar

Mark_Lindberg

Mark_Lindberg

27-03-2009

Yes, it's in a map.

It comes that way from the e-mail end-point.

I am already accessing the entry as a com.adobe.idp.Document.

When the XML is correct inside, it will coerce to org.w3c.dom.Document just fine.

I would like to take the com.adobe.idp.Document to string to pass into your script.

When I try to map com.adobe.idp.Document to string I am getting some kind of byte-array I believe.



Mark