📜  oracle utl_dbws https (1)

📅  最后修改于: 2023-12-03 15:18:09.084000             🧑  作者: Mango

Oracle UTL_DBWS HTTPS

UTL_DBWS HTTPS is a package provided by Oracle to enable interaction with web services over HTTPS protocol from within the database.

Features
  • Provides APIs to make SSL-encrypted HTTP requests to web services
  • Can be used to invoke web services that require authentication using SSL certificates
  • Supports SOAP and REST web services
  • Handles proxy server configuration
Usage

To use UTL_DBWS HTTPS, follow these steps:

  1. Load the package by running the following command:
DECLARE
  dbws_utl_loaded BOOLEAN;
BEGIN
  SELECT 'TRUE' INTO dbws_utl_loaded FROM dual WHERE EXISTS (
    SELECT * FROM all_objects WHERE object_type = 'PACKAGE BODY' AND object_name = 'UTL_DBWS'
  );
  IF dbws_utl_loaded THEN
    DBMS_OUTPUT.PUT_LINE('Package already loaded');
  ELSE
    EXECUTE IMMEDIATE 'BEGIN DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
      host => ''www.example.com'', 
      ace => xs\$ace_type(privilege_list => xs\$name_list('''|| user ||'''), 
      principal_name => '''' || user || '''', 
      is_grant => TRUE, 
      privilege => xs\$name_list('connect')
      ));
    END;';
    UTL_HTTP.ADD_CERTIFICATE(
      'file:/path/to/cert', 
      'password'
    );
    UTL_DBWS.LOAD_WSDL('https://www.example.com/Service.wsdl');
    DBMS_OUTPUT.PUT_LINE('Package loaded successfully');
  END IF;
END;
/

This code does the following:

  • Checks if the package is already loaded
  • Configures the network access control list to allow access to the web service host
  • Adds a SSL certificate to connect to the web service
  • Loads the WSDL of the web service
  1. Once the package is loaded, you can use the UTL_DBWS package to invoke web services. For example, to invoke a SOAP service, you can use the following code:
DECLARE
  req UTL_DBWS.REQUEST;
  res UTL_DBWS.RESPONSE;
BEGIN
  req := UTL_DBWS.NEW_REQUEST('https://www.example.com/Service');
  UTL_DBWS.SET_SOAP_VERSION(req, UTL_DBWS.SOAP_1_1);
  UTL_DBWS.SET_BODY_STYLE(req, 'BARE');
  UTL_DBWS.SET_HEADER(req, 'SOAPAction', 'http://www.example.com/Service#GetInfo');
  UTL_DBWS.ADD_PARAMETER(req, 'arg1', 'value1');
  UTL_DBWS.ADD_PARAMETER(req, 'arg2', 'value2');
  res := UTL_DBWS.INVOKE(req);
  UTL_DBWS.PRINT_RESPONSE(res);
END;

This code does the following:

  • Creates a new request object
  • Sets the SOAP version and body style to use
  • Sets a SOAPAction header
  • Adds parameters to the request
  • Invokes the web service
  • Prints the response
Conclusion

UTL_DBWS HTTPS provides a convenient way to interact with web services over HTTPS protocol from within the database. By following the usage steps outlined above, you can easily configure and use this package in your Oracle applications.