extract PDF document

lundi 23 mars 2015

Hi

I have the following case:

I send MTOM request and receive response with embedded PDF.

I built up the MTOM body in the template, and made the below settings for my Http sender:

Multipart: No

Response Content: XML Body

Parse Multipart: Yes



I got the PDF as xml element inside the response, following an example:

HttpResponse>

<Body boundary="MIMEBoundaryurn_uuid_EB763C07A95A62816A1 426668158042" multipart="yes">

<Part>

<Headers>

<Content-Type>application/xop+xml; charset=UTF-8; type="application/soap+xml"</Content-Type>

<Content-Transfer-Encoding>binary</Content-Transfer-Encoding>

<Content-ID>&lt;0.urn:uuid:EB763C07A95A62816A1426668158044@ apache.org&gt;</Content-ID>

</Headers>

<Content multipart="no">&lt;?xml version='1.0' encoding='UTF-8'?&gt;&lt;soapenv:Envelope &gt;&lt;soapenv:Header&gt;&lt;wsa:Action&gt;urn:ih e:iti:2007:RetrieveDocumentSetResponse&lt;/wsa:Action&gt;&lt;wsa:RelatesTo&gt;bb1906f1-5fff-4ea5-979e-55c3a2f20489&lt;/wsa:RelatesTo&gt;&lt;/soapenv:Header&gt;&lt;soapenv:Body&gt;&lt;xdsb:Ret rieveDocumentSetResponse &gt;&lt;rs:RegistryResponse status="urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Success" /&gt;&lt;xdsb:DocumentResponse&gt;&lt;xdsb:Reposito ryUniqueId&gt;1.19.6.24.109.42.1.5&lt;/xdsb:RepositoryUniqueId&gt;&lt;xdsb:DocumentUnique Id&gt;1.42.20141105202336.39&lt;/xdsb:DocumentUniqueId&gt;&lt;xdsb:mimeType&gt;text/plain&lt;/xdsb:mimeType&gt;&lt;xdsb:Document&gt;&lt;xop:Incl ude href="cid:1.urn:uuid:EB763C07A95A62816A14266681580 45@apache.org" /&gt;&lt;/xdsb:Document&gt;&lt;/xdsb:DocumentResponse&gt;&lt;/xdsb:RetrieveDocumentSetResponse&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt;</Content>

</Part>

<Part>

<Headers>

<Content-Type>text/plain</Content-Type>

<Content-Transfer-Encoding>binary</Content-Transfer-Encoding>

<Content-ID>&lt;1.urn:uuid:EB763C07A95A62816A1426668158045@ apache.org&gt;</Content-ID>

</Headers>

<Content multipart="no">........ PDF document is here ....



</Content>

</Part>

</Body>

</HttpResponse>



Now in my response channel I added the following transformer to extract the PDF into a string:

$gc('doc', msg['Body']['Part'][1]['Content'].toString());



I added a file writer destination set it into binary and put ${doc} in it's template.



I have the following error:

ERROR MESSAGE: Error evaluating transformer

com.mirth.connect.server.MirthJavascriptTransforme rException:

CHANNEL: XDSb Retrieve Document Filter

CONNECTOR: To Response 2

SCRIPT SOURCE:

SOURCE CODE:

LINE NUMBER: 262

DETAILS: TypeError: Character reference "" is an invalid XML character.



If I try to change the type of inbound/outbound connector to Raw I get:

246: $gc('doc', msg['Body']['Part'][1]['Content'].toString());

247: if ('xml' === typeof msg && msg.hasSimpleContent()) { msg = msg.toXMLString(); }if ('xml' === typeof tmp && tmp.hasSimpleContent()) { tmp = tmp.toXMLString(); }

248: }

249: if (doFilter() == true) { doTransform(); return true; } else { return false; }

250: }

LINE NUMBER: 246

DETAILS: TypeError: Cannot read property "Part" from undefined



if I try to change the connector to type to document writer I get:

Document Writer error

ERROR MESSAGE: Error writing document

org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 2; The content of elements must consist of well-formed character data or markup.



If I try to pre-process the message removing control characters such as "", I end up with "The content of elements must consist of well-formed character data or markup" error ...



Any help is mostly appreciated



Regards





extract PDF document

0 commentaires:

Enregistrer un commentaire