How to extract PDF response in Service Callout?

Hi Team,

I am using ServiceCallout policy and expecting pdf response in payload. I am trying to extract the calloutResponse.content into a variable but I am getting blank.

Please suggest how can I extract the pdf and can I make it visible in trace by setting to a context variable?

 

0 3 518
3 REPLIES 3

 

calloutResponse.content will try to give you a UTF-8 string. A PDF is not a utf-8 string. PDF is a binary format.  So that may be the problem you are experiencing: the byte stream in the response may not be decodable to  a UTF-8 string, so you get nothing. 

But maybe there is a way to get what you want. I have some further questions.

  1. What do you want to do with the PDF after you receive it? 
  2. Can you explain the content-type, and the other related headers in the response? 

 

Strange, I was able to work with PDF file and Service Callout, @dchiesa1 > it seems callout returns the actual binary >> converted to UTF-8. 

 

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="aaa">
    <DisplayName>aaa</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="myRequest">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    </Request>
    <Response>pdf</Response>
    <HTTPTargetConnection>
        <Properties/>
      <URL>https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf</URL>
    </HTTPTargetConnection>
</ServiceCallout>

 

 

 

 

 

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="ret">
    <DisplayName>ret</DisplayName>
    <Properties/>
    <Set>
        <Headers>
            <Header name="content-type">application/pdf</Header>
        </Headers>
        <Payload>{pdf.content}</Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

 

 

 

 

The above will return the actual PDF file in response. And in  the trace we can see the PDF as utf-8: 

 

 

 

 

%PDF-1.3
%����

1 0 obj

>>

 

Of course the backend needs to comply with content-type response header to let Apigee know that's PDF or other content-type file

 

nice!  I was not aware.