ORA-28759: failure to open file - oracle

I have a problem.
When I use UTL_HTTP.SET_WALLET Oracle says me next errors:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1130
ORA-28759: failure to open file
Previously, I use Oracle Wallet Manager for setup the Sertificate from website "https://focus-api.kontur.ru/api3/". Cannot understand, what am I doing wrong.
DECLARE
HTTP_REQ UTL_HTTP.REQ;
HTTP_RESP UTL_HTTP.RESP;
URL_TEXT VARCHAR2(32767);
BEGIN
DBMS_OUTPUT.ENABLE(1000000);
UTL_HTTP.SET_WALLET('file:d:\oracle\product\11.2.0\dbhome_1\NETWORK\wallet', 'password');
HTTP_REQ := UTL_HTTP.BEGIN_REQUEST('https://focus-api.kontur.ru/api3/req?inn=7714037390');
UTL_HTTP.SET_HEADER(HTTP_REQ, 'User-Agent', 'Mozilla/4.0');
HTTP_RESP := UTL_HTTP.GET_RESPONSE(HTTP_REQ);
LOOP
BEGIN
URL_TEXT := null;
UTL_HTTP.READ_LINE(HTTP_RESP, URL_TEXT, TRUE);
DBMS_OUTPUT.PUT_LINE(URL_TEXT);
EXCEPTION
WHEN OTHERS THEN EXIT;
END;
END LOOP;
UTL_HTTP.END_RESPONSE(HTTP_RESP);
END;
/

Related

"ORA-29024: Certificate validation failure"

I am trying to consume Rest API in oracle procedure. I have created ACL entry as well as Added the SSL certificate to my oracle wallet manager. but when i am trying to execute the procedure i am getting the error as "ORA-29024: Certificate validation failure". Following is the code for my oracle procedure.
create or replace procedure TABADUL_TAS_AUTHENTICATION
is
req utl_http.req;
res utl_http.resp;
value VARCHAR2(1024);
value1 VARCHAR2(1024);
url varchar2(4000) := 'https://tapis.fasah.sa/tabadul/fasahqa/authorization/token';
name varchar2(4000);
buffer varchar2(4000);
content varchar2(4000) := '{"username":"ijsnj001","password":"P#ssw0rd"}';
begin
UTL_HTTP.set_wallet('file:d:\tabadul', 'tas123456');
req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'content-type', 'application/json;charset=utf-8');
utl_http.set_header(req,'X-IBM-Client-Id','00a2f36e933e2bb9edc76faaf26659eb');
utl_http.set_header(req,'X-IBM-Client-Secret','7c2829bd6b287b072ee269c9ad8f5ead');
utl_http.set_header(req,'Accept-Language','en');
utl_http.set_header(req,'Accept','application/json');
utl_http.set_header(req, 'Content-Length', length(content));
utl_http.write_text(req, content);
res := utl_http.get_response(req);
-- process the response from the HTTP call
DBMS_OUTPUT.PUT_LINE('HTTP response status code: ' || res.status_code);
--DBMS_OUTPUT.PUT_LINE('HTTP response reason phrase: ' || res.reason_phrase);
FOR i IN 1..UTL_HTTP.GET_HEADER_COUNT(res) LOOP
UTL_HTTP.GET_HEADER(res, i, name, value1);
--DBMS_OUTPUT.PUT_LINE(name || ': ' || value1);
END LOOP;
--dbms_output.put_line(content);
--dbms_output.put_line(utl_http.resp);
begin
loop
--dbms_output.put_line('A');
utl_http.read_line(res, value, true);
--dbms_output.put_line(length(value));
dbms_output.put_line(value);
--INSERT INTO A VALUES (VALUE);
--COMMIT;
end loop;
utl_http.end_response(res);
exception
when utl_http.end_of_body
then
--dbms_output.put_line(SQLCODE||','||SQLERRM);
utl_http.end_response(res);
when others then
--dbms_output.put_line(SQLCODE||','||SQLERRM);
utl_http.end_response(res);
end;
end TABADUL_TAS_AUTHENTICATION;
This issue has been resolved.I am writing the solution here, it might be helpful for others.
So instead of creating wallet for the actual website certificate, need to create wallet only for chain of certificate.

Oracle Error ORA-28805: Cannot retrieve information from the data source When Calling UTL_HTTP.request

I am trying to call a web service using the Oracle UTL_HTTP.request API. The call requires a proxy & wallet/certificate. I am getting an ORA-28805: Cannot retrieve information from the data source error. I am using DBMS version 12.1.0.2.0, and Database PSU 12.1.0.2.160419.
The following https call throws the ORA-28805 error:
DECLARE
l_http_request utl_http.req;
l_http_response utl_http.resp;
l_text VARCHAR2(32767);
BEGIN
utl_http.set_proxy('myproxy.url.com');
utl_http.set_wallet('file:/my/wallet/location'
,'mypass');
-- HTTPS Request --
l_http_request := utl_http.begin_request('https://app.myurl.com/myservice/','GET','HTTP/1.1');
utl_http.set_header(l_http_request, 'Authorization', 'Token mytoken');
l_http_response := utl_http.get_response(l_http_request);
BEGIN
LOOP
utl_http.read_text(l_http_response, l_text, 32766);
dbms_output.put_line(l_text);
END LOOP;
EXCEPTION WHEN utl_http.end_of_body THEN
utl_http.end_response(l_http_response);
END;
END;
Runtime exception stack:
ORA-29273: HTTP request failed
ORA-28805: Cannot retrieve information from the data source.
ORA-06512: at "SYS.UTL_HTTP", line 368
ORA-06512: at "SYS.UTL_HTTP", line 1118
ORA-06512: at line 10
The following http call works perfectly & returns a JSON payload:
DECLARE
l_http_request utl_http.req;
l_http_response utl_http.resp;
l_text VARCHAR2(32767);
BEGIN
utl_http.set_proxy('myproxy.url.com');
utl_http.set_wallet('file:/my/wallet/location'
,'mypass');
-- HTTP request --
l_http_request := utl_http.begin_request('http://jsonplaceholder.typicode.com/todos/1','GET','HTTP/1.1');
utl_http.set_header(l_http_request, 'Authorization', 'Token mytoken');
l_http_response := utl_http.get_response(l_http_request);
BEGIN
LOOP
utl_http.read_text(l_http_response, l_text, 32766);
dbms_output.put_line(l_text);
END LOOP;
EXCEPTION WHEN utl_http.end_of_body THEN
utl_http.end_response(l_http_response);
END;
END;
Response:
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
I ran the following as system successfully, but it didn't resolve the problem:
BEGIN
DBMS_NETWORK_ACL_ADMIN.APPEND_WALLET_ACE
(
WALLET_PATH => 'file:/my/wallet/location',
ACE => XS$ACE_TYPE(
PRIVILEGE_LIST => XS$NAME_LIST('use_client_certificates','use_passwords'),
PRINCIPAL_NAME => 'myuser',
PRINCIPAL_TYPE => XS_ACL.PTYPE_DB
)
);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error while configuring ACL for wallet: '|| SQLERRM);
END;
Any ideas on what could be causing this error?
I think the problem is that you are using both privileges
https://docs.oracle.com/database/121/DBSEG/fine_grained_access.htm#DBSEG118
The docs says : Be aware that for wallets, you must specify either the use_client_certificates OR use_passwords privileges.

How to solve Oracle http request to rest service TNS: the time allowed for the operation has expired error when I try to call it using utl_http

I have try to call a REST service using utl_http in PL/SQL , this service worked fine before but now I get the following errors messages :
ORA-29273: HTTP request failure
ORA-06512: to "SYS.UTL_HTTP", line 1130
ORA-12535: TNS: The test time has elapsed
create or replace PROCEDURE PROCEDURE1() IS
soap_req_msg VARCHAR2(2000);
http_req UTL_HTTP.req;
http_resp UTL_HTTP.resp;
buffer varchar2(4000);
BEGIN
soap_req_msg := '{"emailReceiver": "example#mail.com"}'
http_req := UTL_HTTP.begin_request('<ip_port>/path','POST','HTTP/1.1');
UTL_HTTP.set_header(http_req, 'Accept-Encoding', 'gzip,deflate');
UTL_HTTP.set_header(http_req, 'Content-Type', 'application/json');
utl_http.set_header(http_req, 'SOAPAction', 'processEDIData');
UTL_HTTP.set_header(http_req, 'Content-Length', length(soap_req_msg));
UTL_HTTP.set_header(http_req, 'Host', '<ip_port>');
UTL_HTTP.write_text(http_req, soap_req_msg);
http_resp := UTL_HTTP.get_response(http_req);
begin
loop
utl_http.read_line(http_resp, buffer);
dbms_output.put_line(buffer);
end loop;
utl_http.end_response(http_resp);
exception
when utl_http.end_of_body then
utl_http.end_response(http_resp);
end;
END PROCEDURE1;

REST calls to a self-signed,not certified website using Oracle APEX

I'm trying to post some data to a website using APEX, by executing a PL/SQL code.
The problem is, the website's certificate is self-signed, so it's not properly certified, and I'm getting the below error:
ORA-29273: HTTP request failed ORA-06512: at "SYS.UTL_HTTP", line 1130
ORA-28860: Fatal SSL error
I'm using the below code:
procedure publish_error_tickets
is
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'https://some_url';
name varchar2(4000);
buffer varchar2(4000);
content varchar2(4000) :=
'{
"issue": {
"project_id": 1,
"subject": "Example",
"priority_id": 4
}
}'; begin
req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'content-type', 'application/json');
utl_http.set_header(req, 'Content-Length', length(content));
utl_http.write_text(req, content);
res := utl_http.get_response(req);
begin
loop
utl_http.read_line(res, buffer);
dbms_output.put_line(buffer);
end loop;
utl_http.end_response(res);
exception
when utl_http.end_of_body
then
utl_http.end_response(res);
end; end;
My question is, is it possible to somehow ignore the certificate validation process for the http message? There must be a way to reach a website without the need to buy a validated cert for the site.
Thanks in advance,
Tamas
For anyone having the same problem, I got it working with the solution Jeffrey Kemp posted( http://blog.rhjmartens.nl/2015/07/making-https-webservice-requests-from.html ), with a reverse proxy, it works like a charm!

ORA-12545: Connect failed because target host or object does not exist ORA-06512

I have the following error message when I try to establish a HTTP request connection:
ORA-29273: HTTP request failed ORA-06512: at "SYS.UTL_HTTP", line 1029 ORA-12545: Connect failed because target host or object does not exist ORA-06512: at line 10 .
Line 10 is the following:
req := UTL_HTTP.BEGIN_REQUEST('oracle.com');
Here is my pl/sql block:
DECLARE
req UTL_HTTP.REQ;
resp UTL_HTTP.RESP;
name_1 VARCHAR2(256);
value_1 VARCHAR2(1024);
v_msg VARCHAR2 (500);
BEGIN
req := UTL_HTTP.BEGIN_REQUEST('http://www.oracle.com');
UTL_HTTP.SET_HEADER(req, 'User-Agent', 'Mozilla/5.0');
UTL_HTTP.SET_FOLLOW_REDIRECT(req, 0);
resp := UTL_HTTP.GET_RESPONSE(req);
LOOP
Utl_Http.read_text (resp, v_msg);
DBMS_OUTPUT.put_line (v_msg);
END LOOP;
UTL_HTTP.END_RESPONSE(resp);
EXCEPTION
WHEN Utl_Http.end_of_body
THEN
NULL;
END;
the code seems fine to me...
the reason of this error is outside the code you show:
The system this code is run on (the DB server) must be able to resolve the domain name - which has nothing to do with Oracle...
To solve this you need to setup DNS / hosts correctly on the machine / in the OS!

Resources