I am consuming a SOAP base service which is returning a pdf file in response, i want to parse response into a blob type. I have below code to consume soap service , however i am getting pdf file but its failed open or download as its invalid file.
declare
p_ref_no varchar2(100) := '290313008810';
l_key varchar2(100) := post_shipments_shipper.getKey('LIVE');
l_envelope CLOB;
l_xml XMLTYPE;
l_result varchar2(2000);
l_pdf clob;
l_pdf_file blob;
pragma autonomous_transaction;
begin
l_envelope := '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sms="http://track.smsaexpress.com/secom/SMSAWebserviceIntl">
<soapenv:Body>
<sms:getPDF>
<sms:awbNo>'||p_ref_no||'</sms:awbNo>
<sms:passKey>'||l_key||'</sms:passKey>
</sms:getPDF>
</soapenv:Body>
</soapenv:Envelope>';
-- Get the XML response from the web service.
l_xml := APEX_WEB_SERVICE.make_request(
p_url => 'http://track.smsaexpress.com/SECOM/SMSAwebServiceIntl.asmx',
p_action => 'http://track.smsaexpress.com/secom/SMSAWebserviceIntl/getPDF',
p_envelope => l_envelope
);
-- Display the whole SOAP document returned.
-- DBMS_OUTPUT.put_line('l_xml= ' || l_xml.getClobVal());
-- RETURN l_xml.getClobVal();
l_pdf := APEX_WEB_SERVICE.parse_xml_clob(
p_xml => l_xml,
p_xpath => '//getPDFResult',
p_ns => 'xmlns="http://track.smsaexpress.com/secom/SMSAWebserviceIntl"'
);
l_pdf_file := APEX_WEB_SERVICE.CLOBBASE642BLOB(l_pdf);
delete from shipment_labels;
insert into shipment_labels values (l_pdf_file,'abc.pdf','application/pdf',l_pdf);
commit;
end;
I am trying to to parse pdf file and inserting into a table with column type blob , however file contents are invalid and unable to open as media.
CodePudding user response:
I think the issue is in your parse_xml_clob
call. If you look at your l_pdf values which are getting saved in the table, I think they will look like this:
<getPDFResult xmlns="http://track.smsaexpress.com/secom/SMSAWebserviceIntl">...your base64Binary...</getPDFResult>
But you only want the inside text. Based on the example in the documentation, you want the XPath to return the text node(s) inside the <getPDFResult>
node, not the node itself.
l_pdf := APEX_WEB_SERVICE.parse_xml_clob(
p_xml => l_xml,
p_xpath => '//getPDFResult/text()',
p_ns => 'xmlns="http://track.smsaexpress.com/secom/SMSAWebserviceIntl"'
);