Can the Oracle database send requests to a Servlet? Can the Oracle database send requests to a Servlet? oracle oracle

Can the Oracle database send requests to a Servlet?


Using UTL_HTTP

Yes, you can send HTTP requests from the Oracle database. Here's a nice blog post that summarises how you can do it using the UTL_HTTP package:https://oracle-base.com/articles/misc/utl_http-and-ssl

An example from the Oracle manual:

SET SERVEROUTPUT ON SIZE 40000DECLARE  req   UTL_HTTP.REQ;  resp  UTL_HTTP.RESP;  value VARCHAR2(1024);BEGIN  UTL_HTTP.SET_PROXY('proxy.my-company.com', 'corp.my-company.com');  req := UTL_HTTP.BEGIN_REQUEST('http://www-hr.corp.my-company.com');  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);EXCEPTION  WHEN UTL_HTTP.END_OF_BODY THEN    UTL_HTTP.END_RESPONSE(resp);END;

Alternative using Oracle AQ

If you want some intermediary layer, you might also use Oracle AQ, which I personally find more powerful:https://docs.oracle.com/database/121/ADQUE/aq_intro.htm

Using Oracle AQ, you could for instance bypass the HTTP layer and access whatever the Servlet is calling internally, directly.