CMD
SQLPLUS /NOLOG
CONN SYS/TEKNISA@XE AS SYSDBA
/
GRANT EXECUTE ON SYS.UTL_HTTP TO PCA;
GRANT EXECUTE ON SYS.DBMS_LOCK TO PCA;
GRANT EXECUTE ANY PROGRAM TO PCA;
--SET SERVEROUTPUT ON;

/
/*
begin
dbms_network_acl_admin.create_acl (
acl => 'http_permissions2.xml', -- or any other name
description => 'HTTP Access',
principal => 'PCA', -- the user name trying to access the network resource
is_grant => TRUE,
privilege => 'connect',
start_date => null,
end_date => null
);
end;
/
begin
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(acl => 'http_permissions.xml',
principal => 'PCA',
is_grant => true,
privilege => 'connect');
end;
/
begin
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(acl => 'http_permissions.xml',
principal => 'PCA',
is_grant => true,
privilege => 'resolve');
end;
/
BEGIN
dbms_network_acl_admin.assign_acl (
acl => 'http_permissions.xml',
host => '192.168.120.187', --can be computer name or IP , wildcards are accepted as well for example - '*.us.oracle.com'
lower_port => 80,
upper_port => 80
);
END;
*/
Execute Dbms_Network_Acl_Admin.Create_Acl ( Acl => 'utl_http.xml',Description => 'HTTP Access', Principal => 'PCA', Is_Grant => True, Privilege => 'connect' );
Execute Dbms_network_acl_admin.add_privilege ( acl => 'utl_http.xml',principal => 'PCA', is_grant => TRUE, privilege => 'resolve');
Execute Dbms_Network_Acl_Admin.Assign_Acl (Acl => 'utl_http.xml',Host => '*', lower_port => 80, upper_port => 80);
/
commit;
/
select * from dba_network_acls;
/
SELECT *
FROM dba_network_acl_privileges
where principal='PCA';
/

--CRIAR TRIGGER QUE CRIA JOB PARA ATUALIZAR OS REGISTROS
create or replace trigger callWebserviceJob
  after insert on USR_APT_OPERFORN
  for each row
  declare
      JOB_N int;
begin
  IF INSERTING THEN
     dbms_job.submit (
      job => JOB_N, 
      what => 'BEGIN TESTAWEBSERVICE(); END;', 
      next_date =>sysdate + interval '10' second
     ); 
  END IF;
end callWebserviceJob;

/
CREATE OR REPLACE
PROCEDURE TESTAWEBSERVICE
IS
  REQ UTL_HTTP.REQ;
  RES UTL_HTTP.RESP;
  URL VARCHAR2(4000) := 'HTTP://RAFAELDIAS.ZEEDHI.COM/WORKFOLDER/PEBBIAN-ERP-SERVICES-APETITE/BACKEND/SERVICE/INDEX.PHP/EXPORTACADASTROS';
  NAME VARCHAR2(4000);
  BUFFER VARCHAR2(4000); 
  CONTENT VARCHAR2(4000) := '{"TESTE":"OI"}';
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);
  -- 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 TESTAWEBSERVICE;

/

BEGIN
   DBMS_NETWORK_ACL_ADMIN.DROP_ACL(
      acl => '/sys/acls/utl_http.xml');
END;