× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi there,
I'm having great difficulty in returning a PDF Document in a REST Service request.

Background:

I'm facilitating a Webservice between 2 External parties

I receive a JSON request from Client 1, parse the info, call an API (Via Scott's HTTPAPI) on Client 2's Systems, receive the response as a PDF Document which I store on the IFS.

Now I need to pass this PDF Document back to Client 1 as a response to their API call, and this is where I'm getting Garbage in the PDF Document.

Code Snippet:

yajl_genOpen(*on);
yajl_beginArray();
yajl_beginObj();
yajl_addChar('UploadStatus' : 'A');
yajl_addChar('UploadMessage' : %Trim(RspString));
yajl_addChar('HHSCore' : %Trim(w_HHSCore));
yajl_endObj();
yajl_beginObj();
yajl_addCharStmf('ResponseDocument' : DocPath: ErrMsg);
yajl_endObj();
yajl_endArray();
sts = 200;
// This is the response I log for error\troubleshoot\later investigations etc.
Response = '[{"UploadStatus":"A",' +
'"UploadMessage:"' +%Trim(RspString) + '",' +
'"HHSCore":"' + %Trim(w_HHSCore) + '"},{'+
'"ResponseDocument":"' + %Trim(Docpath) + '}]';
doLogging();
// the following code acts like yajl_writeStdout. I need content-type to be different
rc = yajl_getBuf( jsonBuf: jsonSize );
Headers = 'Status: ' + %editc(sts:'X') + CRLF +
'Content-type: application/pdf' + CRLF +
// 'Content-type: application/json charset=utf-8' + CRLF +
// 'Content-type: application/octet-stream' + CRLF +
// 'Transfer-Encoding: identity' + CRLF +
'Content-Encoding : gzip' + CRLF +
'Content-Disposition: attachment; filename=' + %Trim(w_File) + CRLF + CRLF;
QtmhWrStout ( %addr(Headers) + 2 : %len(Headers) : APIError );
offset = 0;
dow jsonSize > 0;
length = jsonSize;
if length > ChunkSize;
length = ChunkSize;
endif;
QtmhWrStout ( jsonBuf + offset : length : APIError );
jsonSize -= length;
offset += length;
enddo;
//yajl_writeStdout(sts: msg);
yajl_genClose();

This runs fine and returns the Document, but the PDF is all garbage. I'm not too sure if yajl_addCharStmf() is the correct procedure to use.

I'm using both Postman and SOAPUI for testing.

Kind Regards,

Toni Schaake.





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.