How to send HTTP response with media-type = application/pdf

Posted by thierryk on 25-Jun-2018 11:20

Hi,

I'd need to implement a REST service that generates a pdf file and send it back to the web browser.

Besides, I want the browser to show the pdf file in a viewer. So it's not a direct download.

I'm currently working on Developer Studio 11.7.1.

My attemps were unsuccesful. The browser show the pdf viewer but the file can not be read.

The pdf file generation is done. The file is valid and readable via pdf viewer. Then I tried to use the URI resource editor so that my GET service returns the pdf file with the following properties:

HTTP headers:

  • Content-Type: applicaiton/pdf
  • Content-Length: myFileLength

I also played with Content-Encoding and Content-Disposition.

HTTP body:

  • A longchar that represent the base64-encode result on the pdf file.

I did the base64 conversion because OpenEdge does not support blob objects as an output of a business entity method.

I'm afraid that base64 conversion is the culprit.

Is there a way to achieve it properly on progress server side or do I need to embed the result in a JSON and let the client decrypts the file ?

Thanks for your help.
Best regards

Posted by David Cleary on 25-Jun-2018 12:06

Our REST Adapter, or REST Transport in PASOE, only supports JSON. If you are on PASOE, then you want to use the WEB transport and create a web handler.
 
Dave
 

All Replies

Posted by David Cleary on 25-Jun-2018 12:06

Our REST Adapter, or REST Transport in PASOE, only supports JSON. If you are on PASOE, then you want to use the WEB transport and create a web handler.
 
Dave
 

Posted by thierryk on 26-Jun-2018 02:35

Thank you David for the quick reply !

I'll try to implement this solution today.

Thierry

Posted by jonathan.wilson on 26-Jun-2018 02:54

The "legacy" $DLC/servlet/rest with the OE AppServer can be hotwired to run XML, whether it can do PDF I don't know... but...

But once you have a WAR look for:

/TOMCAT/webapps/MyServiceName/WEB-INF/adapters/MyServiceName.paar  (that's just a ZIP)

inside you'll have a resourceModel.xml

<?xml version="1.0" encoding="UTF-8"?>

<prgs:model xmlns:prgs="www.progress.com/.../prgrs" id="resourceModel">

 <prgs:resource consumes="application/json" name="_OrderEnquiry" path="/OrderEnquiry" produces="application/json">

   <prgs:operation consumes="application/json" idls="MyServiceName.restoe::com.progress.openedge.pdt.bpmbindings" name="OrderEnquiry..pMain" produces="application/json" verb="POST"/>

 </prgs:resource>

</prgs:model>

By default it's JSON this can be changed to XML (100% know that works as we do it) but PDF might be worth testing.

 <prgs:resource consumes="application/XML" name="_OrderEnquiry" path="/OrderEnquiry" produces="application/XML">

Posted by thierryk on 19-Jul-2018 08:21

I manage to do it using a web handler. It works flawlessly.

This thread is closed