0

I am trying parse XML from invokeHTTP method that is returned in utf-16 encoding specified in the response. I have tried below but I am still cannot get past this error

select request.* from  (EXEC model.invokeHttp(action => 'POST', endpoint => 'url' ,contentType => 'application/x-www-form-urlencoded;charset=utf-8',headers => jsonObject('application/x-www-form-urlencoded;charset=utf-8' as "Content-Type",'utf-8' as "Accept-Charset",jsonArray('gzip', 'deflate') as "Accept-Encoding",'bearer token' as "App-Authorization"),request => 'payload')) AS ws,
            XMLTABLE(XMLNAMESPACES(DEFAULT 'url'),'/path' PASSING XMLPARSE(DOCUMENT TO_CHARS(ws.result,'utf-8') WELLFORMED)  columns
            Name string PATH 'FirstName'
       ) AS request

I have tried specifying the encoding in the VDB for the translator, still same

<translator name="rest" type="ws">
                <property name="DefaultBinding" value="HTTP"/>
                <property name="DefaultServiceMode" value="MESSAGE"/>
                <property name="encoding" value="UTF-16"/>
</translator>

Response:

<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
ASAFDAR
  • 19
  • 1
  • 7

2 Answers2

0

First make sure that you are getting the response you expect, either there is logging that you can turn up for request/response logging http://teiid.github.io/teiid-documents/master/content/admin/Web_Service_Data_Sources.html or just execute the equivalent of:

TO_CHARS(ws.result,'utf-8')

to see the response.

Steven Hawkins
  • 538
  • 1
  • 4
  • 7
  • I have tried ```TO_CHARS(ws.result,'utf-8')``` unfortunately I get the same result. The XML response is formatted with space, indents and line feed characters. Can that be the reason ? – ASAFDAR Feb 02 '21 at 23:21
  • I tested with a small response by converting to string and replacing UTF-16 to UTF-8 in XML declaration. This has worked. Is there a function in TEIID to update XML without going down the UDF route ? – ASAFDAR Feb 03 '21 at 05:20
  • It sounds like you are saying that you have an xml document that has an UTF-16 xml declaration, but the bytes are actual UTF-8 encoded. I think you should try to omit the TO_CHARS and instead just see if XMLPARSE can handle the bytes directly. – Steven Hawkins Feb 05 '21 at 18:07
0

I resolved it by putting "Accept" in http header as 'text/xml;charset=utf-16' and then convert TO_CHARS(ws.result,'UTF-16')

ASAFDAR
  • 19
  • 1
  • 7