I need help with this code, I am getting an error saying following.
ORA-29273: HTTP request failed
ORA-12541: TNS:no listener
ORA-06512: at "SYS.UTL_HTTP", line 368
ORA-06512: at "SYS.UTL_HTTP", line 1118
ORA-06512: at line 5
29273. 00000 - "HTTP request failed"
*Cause: The UTL_HTTP package failed to execute the HTTP request.
*Action: Use get_detailed_sqlerrm to check the detailed error message.
Fix the error and retry the HTTP request.
I contacted network team and they see bidirectional traffic on that port being done, so I am not sure what else is/could be wrong? any ideas?
create or replace
procedure Test_Rest_Call3
is
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'http://ipaddresshere:9099/api/batchProcess/1';
name varchar2(4000);
buffer varchar2(4000);
content varchar2(4000) := '';
begin
req := utl_http.begin_request(url, 'DELETE',' 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);
-- process the response from the HTTP call
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 Test_Rest_Call3;
Have you checked if DBA granted to execute utl_http?
Just try to run it to be sure:
select utl_http.request('http://ipaddresshere:9099/api/batchProcess/1') from dual;
If you get error then ask DBA to give the permission accordingly:
grant execute on utl_http to your_oracle_user_name
grant execute on dbms_lock to user_name
BEGIN
DBMS_NETWORK_ACL_ADMIN.create_acl (
acl => 'local_sx_acl_file.xml',
description => 'A test of the ACL functionality',
principal => 'put your user_name',
is_grant => TRUE,
privilege => 'connect',
start_date => SYSTIMESTAMP,
end_date => NULL);
end;
begin
DBMS_NETWORK_ACL_ADMIN.assign_acl (
acl => 'local_sx_acl_file.xml',
host => 'localhost',
lower_port => 9002,
upper_port => NULL);
end;
I hope it will help.
Cheers,
Morteza Fakoorrad
Related
I am working with a temporary Oracle Cloud account. What I thought was identical functionality works on the Apex Web Service, but not with UTL_HTTP. So this snippet works and returns the issue we are looking for.
DECLARE
L_json_response varchar2(32767);
BEGIN
apex_web_service.g_request_headers(1).name := 'Content-Type';
apex_web_service.g_request_headers(1).Value := 'application/json';
L_json_response := apex_web_service.make_rest_request ( p_url =>
'https://mycompany.atlassian.net/rest/api/3/issue/BLABLA-23862', p_http_method => 'GET',
p_username => 'My.Username#mycompany', p_password => 'osBJWHhPasdffNVOQ5AA11D5'); -- Password is my Jira API Token
EXCEPTION WHEN OTHERS THEN raise_application_error(-20001,'An error was encountered -
'||SQLCODE||' -ERROR- '||SQLERRM);
END;
I can't use the Apex web service in the end product, and we need to use UTL_HTTP. This snippet should from my understanding do the same:
DECLARE
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'https://mycompany.atlassian.net/rest/api/3/issue/BLABLA-23862';
buffer varchar2(4000);
BEGIN
req := utl_http.begin_request(url, 'GET');
utl_http.set_header(req, 'Content-Type', 'application/json');
utl_http.set_header(req, 'Authorization', 'Basic ' || utl_encode.base64_encode('my.msername#mycompany:osBJWHhPasdffNVOQ5AA11D5'));
res := utl_http.get_response(req);
utl_http.read_text(res, buffer);
END;
But returns:
ORA-29273: HTTP request failed
ORA-29024: Certificate validation failure
ORA-06512: at "SYS.UTL_HTTP", line 639
ORA-06512: at "SYS.UTL_HTTP", line 1415 ORA-06512...
The key is the UTL_HTTP.SET_WALLET('');. You need to set the wallet(with empty string parameter) before initial http request.
The following code snippet tested with in Oracle Cloud ATP (Autonomous Transition Processing) database:
Setup network ACL
BEGIN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL(acl => 'my_acl.xml',
description => 'ACL for http request.',
principal => 'MY_USER',
is_grant => true,
privilege => 'connect');
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(acl => 'my_acl.xml',
principal => 'MY_USER',
is_grant => true,
privilege => 'resolve');
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL(acl => 'my_acl.xml', host => 'www.oracle.com');
END;
Test https request
DECLARE
l_text VARCHAR2(32767);
BEGIN
UTL_HTTP.SET_WALLET('');
l_text := UTL_HTTP.REQUEST('https://www.oracle.com/index.html');
dbms_output.put_line(l_text);
END;
See official document and example (on the bottom of page):
In a way #OldProgrammer answered this the comment from 29-12-2020m but I don't know how to attribute the answer.
I needed to either couple the UTL_HTTP code to default wallet or create a new one. APEX_WEB_SERVICE probably does this implicitly while UTL_HTTP has to have it spelled out.
My question was for Oracle Cloud and I couldn't make the toolchain from OldProgrammers link work in Oracle Cloud. Rolled out a VM and it works.
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.
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;
I have the user name under ACl and acl has been assigned to host.
but I am getting error http_req filed on trying to connact
ACL has been assigned to host
SELECT * FROM dba_network_acls;
1 *.mer.com /sys/acls/fine_grain_access_http.xml 968743177C0D29D9E040A8C02F1C05F0
user has been added to ACL with connect and resolve prov
SELECT * FROM dba_network_acl_privileges where principal=’SCOTT’
ACL ACLID PRINCIPAL PRIVILEGE IS_GRANT INVERT
1 /sys/acls/fine_grain_access_http.xml 968743177C0D29D9E040A8C02F1C05F0 PRASHANT-MISHRA connect true false
2 /sys/acls/fine_grain_access_http.xml 968743177C0D29D9E040A8C02F1C05F0 PRASHANT-MISHRA resolve true false
below is the code section I am rying to execute
DECLARE
req UTL_HTTP.req;
resp UTL_HTTP.resp;
v_URL VARCHAR2(2000);
VALUE VARCHAR2(32767);
Rpt_id NUMBER:=38660;
part1 VARCHAR2(200);
part2 VARCHAR2(100);
part3 VARCHAR2(100);
username VARCHAR2(100):='PRASHANT-MISHRA';
pass VARCHAR2(100):='Summer#2015';
BEGIN
part1:='http://jira.mer.com/sr/jira.issueviews:searchrequest-xml/';
part2:='/SearchRequest-38660tempMax=3000&';
part3:='field=key';
v_URL:=part1||part2||Rpt_id||part3;
req := UTL_HTTP.begin_request(v_URL,'GET','HTTP/1.1');
UTL_HTTP.set_authentication(req, username, pass);
UTL_HTTP.set_header (req,'Content-Type','application/xml; charset=utf-8');
/*UTL_HTTP.set_header(req, ‘User-Agent’, ‘Mozilla/4.0′);*/
resp := UTL_HTTP.get_response(req);
LOOP
UTL_HTTP.read_line(resp, value, TRUE);
DBMS_OUTPUT.PUT_LINE(value);
END LOOP;
UTL_HTTP.end_response(resp);
END;
Error:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1130
ORA-24247: network access denied by access control list (ACL)
ORA-06512: at line 19
I forgot committing changes after running add_priv to add priv for user to ACL.
I am trying to call a page from PLSQL
declare
httprequest UTL_HTTP.req;
httpresp UTL_HTTP.resp;
v_http_url VARCHAR2 (200) := 'http://localhost:38801/BatchMvcDriver/Index?ID=161';
begin
httprequest := UTL_HTTP.begin_request (url => v_http_url,
method => 'POST');
UTL_HTTP.set_header (httprequest,
'Content-Type',
'text/xml; charset=utf-8'
);
UTL_HTTP.set_header (httprequest, 'Content-Length', 64);
UTL_HTTP.write_line (httprequest, 'some string');
httpresp := UTL_HTTP.get_response (httprequest);
UTL_HTTP.end_request (httprequest);
UTL_HTTP.end_response (httpresp);
end;
It said
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1130
ORA-24247: network access denied by access control list (ACL)
ORA-06512: at line 7
I tried to
begin
dbms_network_acl_admin.create_acl (
acl => 'utl_http.xml',
description => 'HTTP Access',
principal => 'SCOTT',
is_grant => TRUE,
privilege => 'connect',
start_date => null,
end_date => null
);
I am getting this error
ERROR at line 2:
ORA-06550: line 2, column 3:
PLS-00201: identifier 'DBMS_NETWORK_ACL_ADMIN' must be declared
ORA-06550: line 2, column 3:
PL/SQL: Statement ignored
How to get rid of this??