UTL_HTTP

Well, we all know about simple web application architecture.  It will have a servlet/jsp calling an backend procedure or function.  Is it possible to reverse it? i.e. can you call a servlet from a database procedure/function.  Yes!  It is possible with UTL_HTTP package in oracle.  Here is a sample :

DECLARE
 REQ_1 UTL_HTTP.REQ_1;
 RESP_1 UTL_HTTP.RESP_1;
 VALUE VARCHAR2(1024);
BEGIN
  REQ_1 := UTL_HTTP.BEGIN_REQUEST('HTTP://www.yoursite.com:8988/servletpath/servlet');
  UTL_HTTP.SET_HEADER(REQ_1, 'USER-AGENT', 'MOZILLA/4.0');
  RESP_1 := UTL_HTTP.GET_RESPONSE(REQ_1);
  LOOP
  UTL_HTTP.READ_LINE(RESP_1, VALUE, TRUE);
  DBMS_OUTPUT.PUT_LINE(VALUE);
  END LOOP;
  UTL_HTTP.END_RESPONSE(RESP_1);
EXCEPTION
  WHEN UTL_HTTP.END_OF_BODY THEN
  UTL_HTTP.END_RESPONSE(RESP_1);
END;
 

One of my developer colleague wanted to test this functionality, so we tested this on 10g.  And it really worked nicely.

2 Responses to UTL_HTTP

  1. LinZ says:

    hi…just want to know how to get the parameter passed to servlet, for example.TQ in advance…

  2. Ray says:

    Hi,

    Is it possible to call a specific oracle form from a database?

    Thanks,
    Ray

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.