× 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 Bradley,

Thank you for your prompt response.

The CCSID of the PDF is 819 on the IFS.

I'm building a JSON Object to return to the client. It looks like this:

[
{
"UploadStatus": "A",
"UploadMessage": "Biometric Info Captured",
"HHSCore": "RED"
},
{
"ResponseDocument": "%PDF-1.7\n%äã�Ò\n4......... ==> this data is corrupted.
}
]

I was hoping to load the PDF with yajl_addCharStmf('ResponseDocument' : DocPath: ErrMsg). Docpath is where the PDF Doc is stored on the IFS.

yajl_writeStdout(sts: msg); does not allow for content-type of application/pdf, and I need Content-Disposition in the header as well, hence the need to do QtmhWrStout.

Best Regards,

Toni


-----Original Message-----
From: WEB400 <web400-bounces@xxxxxxxxxxxx> On Behalf Of Bradley Stone
Sent: 30 October 2018 15:17
To: Web Enabling the AS400 / iSeries <web400@xxxxxxxxxxxx>
Subject: Re: [WEB400] Return PDF in Rest Service

What Code page is the PDF in your IFS?

What format is the PDF returned to client 2? It looks like a straight PDF
file... so why are there yajl functions in it and building arrays, etc?

Where are you loading the PDF in this code? Is it already in jsonBuf? How did it get there? From other code not in the sample source?

If you were to use something like eRPG SDK or CGIDEV2 to return the PDF document it would be a lot easier. Write out headers, load the PDF as the template, and write it out. eRPG example:

#startup();
#writeTemplate('stdPDFheader.erpg'); <--- this contains
headers like Content-type: application/pdf with 2 new lines
#setCCSIDStdOut(1208);
#writeTemplate(yourPDFFile);
#cleanup();

*INLR = *on;



Bradley V. Stone
www.bvstools.com
MAILTOOL Benefit #6 <https://www.bvstools.com/mailtool.html>: Easily send group emails with Distribution Lists

On Tue, Oct 30, 2018 at 8:01 AM Toni Schaake <Toni.Schaake@xxxxxxxxxxxxxx>
wrote:

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.




--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400)
mailing list To post a message email: WEB400@xxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/web400.


--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list To post a message email: WEB400@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://archive.midrange.com/web400.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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.