I am trying to access to a Rest Service who exposes a pdf file, but I get this response when invoking the procedure:
{
"errors": [
"Failed to parse the payload from backend (procedure: HttpRequest)"
],
"info": [
],
"isSuccessful": false,
"responseHeaders": {
"Content-Type": "application\/octet-stream; type=\"application\/xop+xml\"; boundary=\"uuid:****************\"; start=\"<pdf>\"; start-info=\"application\/pdf\"",
"Date": "Thu, 07 Nov 2013 14:44:54 GMT",
"Server": "Apache-Coyote\/1.1",
"Transfer-Encoding": "chunked",
"X-Powered-By": "Servlet 2.5; **********",
"content-disposition": "attachment; filename = ********.PDF"
},
"responseTime": 5329,
"statusCode": 200,
"statusReason": "OK",
"totalTime": 9923,
"warnings": [
]
}
Can I get a pdf file using a worklight adapter? is there any alternative way?
You need to change the 'returnedContentType' parameter in your adapter implementation. My guess is right now you have it set to 'xml'. Since the pdf that is being retrieved from your backend is not in XML, you are receiving that error message.
Example:
I was able to do this with calling a Java routine from the adapter to call the back-end service that returns the PDF as a
byte[]
. Once thebyte[]
is retrieved Ibase64
encode it in the Java routine, URI encode it in the adapter, then do the reverse in the client js code. The Java code uses the ApacheHttpClient
. I tried the plain return type as well as others with no luck.Java example here
Adapter code:
Client code:
Java code: