What is the best way to extend org.teiid.translator.ws to connect to a webservice that returns JSONP (whose mediatype is usually application/javascript)? The existing ws translator can read only JSON or XML. In general, was the translator designed to facilitate the injection of transformation logic to handle any webpage structure/format (e.g., JSONP, plaintext, html, etc.)?
For JSONP, I am leaning towards creating my own implementation of org.teiid.core.types.InputStreamFactory, say com.acme.JsonpToJsonInputStreamFactory, in which I define my own JsonpToJsonReaderInputStream (extending ReaderInputStream) that skips the leading
randomFunctionName(
and trailing
)
of a JSONP payload, and modify ClobInputStreamFactory.getInputStream to return that, instead of ReaderInputStream. Then I replace both instances of
ds = new InputStreamFactory.ClobInputStreamFactory(...);
in translator-ws-jsonp.BinaryWSProcedureExecution (where translator-ws-jsonp is based on translator-ws) with
ds = new JsonpToJsonInputStreamFactory.ClobInputStreamFactory(...);
WS translator returns the results in Blob form, how you unpack the results is up to you. IMO, you do not really need to build another translator.
Currently, the typical use case in JDV is to read blob and use JSONTOXML function to convert into XML such that the results can be then parsed into a tabular structure using constructs like XMLTABLE. So, you can write a UDF like JSONPTOJSON which does above like you mention then use JSONTOXML(JSONPTOJSON(blob)) as input to XMLTABLE.