Calling webservice from plsql package (merged) [message #678721] |
Sun, 05 January 2020 00:59 |
|
Shiv93
Messages: 34 Registered: September 2019
|
Member |
|
|
Hi Everyone,
I have a requirement to call a webservice which actually returns a PDF file when I hit that webservice via swagger link with all the necessary inputs.Now when I try to hit that webservice link from my plsql package with the necessary inputs I'm not getting PDF file generated but I get the response as 200. Can someone guide me how to get the return response file stored in a PDF?.
|
|
|
|
|
Re: Calling webservice from plsql package (merged) [message #678745 is a reply to message #678723] |
Mon, 06 January 2020 07:54 |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
Unless the web site is programmed to return the binary object, it will never happen. The 200 indicates that the web service accepted your connection. Also how are you accepting back the binary response? Without the code for when you call the web page we can't help you in anyway. Are you using SOAP, REST, HTML. past the code fragment where you are actually asking for and retrieving the PDF.
|
|
|
Re: Calling webservice from plsql package (merged) [message #678985 is a reply to message #678745] |
Sat, 25 January 2020 03:14 |
|
Shiv93
Messages: 34 Registered: September 2019
|
Member |
|
|
Hi Bill / Michael,
Thanks for the reply .. Below is my code snippet used. Please let me know how should i handle the return response from the webservice to store it as a text in my table.
l_buffer VARCHAR2(32767);
req utl_http.req;
res utl_http.resp;
l_blob blob;
l_raw raw(32767);
l_content VARCHAR2(4000); -- input parameters to my webservice
url VARCHAR2(100); -- My webservice url
BEGIN
req := utl_http.begin_request(url,'POST',' HTTP/1.1');
utl_http.set_header(req,'content-type','application/json');
utl_http.set_header(req,'accept','application/pdf');
utl_http.set_header(req,'Content-Length',length(l_content) );
utl_http.write_text(req,l_content);
res := utl_http.get_response(req);
dbms_output.put_line('response' || res.status_code );
dbms_output.put_line('response_reason' || res.reason_phrase);
dbms_lob.createtemporary(l_blob, true);
begin
utl_http.read_raw(res, l_raw);
dbms_lob.writeappend (l_blob, utl_raw.length(l_raw), l_raw);
-- dbms_output.put_line('out_response.... ' || DBMS_LOB.SUBSTR(l_blob));
SELECT NVL(MAX(ID)+1,1) INTO v_id FROM Response_data;
insert into Response_data values(v_id,l_blob);
commit;
utl_http.end_response(res);
EXCEPTION
WHEN utl_http.end_of_body THEN
utl_http.end_response(res);
WHEN UTL_HTTP.TOO_MANY_REQUESTS THEN
utl_http.end_response(res);
END;
END;
[Updated on: Sat, 25 January 2020 03:15] Report message to a moderator
|
|
|
|