0% found this document useful (0 votes)
246 views11 pages

Calling Demantra Workflow Using HTTP POST

The procedure posts an HTTP URL and parameters and returns the response. It initializes logging, checks configuration parameters, builds and sends the HTTP request, reads and returns the response, and handles exceptions. Logging messages are generated at each step.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
246 views11 pages

Calling Demantra Workflow Using HTTP POST

The procedure posts an HTTP URL and parameters and returns the response. It initializes logging, checks configuration parameters, builds and sends the HTTP request, reads and returns the response, and handles exceptions. Logging messages are generated at each step.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

CREATE OR REPLACE PROCEDURE -- $Revision: 1.

2 $

post_url_http ( is_http_url IN VARCHAR2,

is_http_url_params IN VARCHAR2,

os_http_resp OUT NOCOPY VARCHAR2)

AS

vs_proc_name VARCHAR2(30) := 'POST_URL_HTTP';

vi_exists INTEGER := 0;

vs_msg VARCHAR2(4000);

req UTL_HTTP.req;

resp UTL_HTTP.resp;

vs_buffer VARCHAR2(32767);

vi_length_in_bytes NUMBER := LENGTHB( is_http_url_params );

vi_JSPGetAllow VARCHAR2(300);

vs_p_server VARCHAR2(2000);

vi_timeout_now INTEGER := 0;

vi_error_code NUMBER;

vs_error_text VARCHAR2(200);

vi_logging_level INTEGER;

vs_log_table VARCHAR2(30);

vs_proc_source VARCHAR2(60);

vs_log_msg VARCHAR2(4000);

e_config_error EXCEPTION;

BEGIN

/************************************************************************************************************
******/

/* General Errors are written to the DB_EXCEPTION_LOG table. /*

/* Additional logging is written to the table LOG_URL_HTTP. /*

/* 1. Enable logging on POST_URL_HTTP /*

/* exec SET_LOG_IT_LOGGING('POST_URL_HTTP',10); /*

/* 2. Disable logging on POST_URL_HTTP /*


/* exec SET_LOG_IT_LOGGING('POST_URL_HTTP',0); /*

/************************************************************************************************************
******/

/************************************************************************************************************
******/

/* Initialize LOG_IT logging

/************************************************************************************************************
******/

vs_proc_source := vs_proc_name;

get_param_log_it(vs_proc_source, vs_log_table, vi_logging_level );

vs_log_msg := 'Procedure Started';

LOG_IT ( vs_log_table, vi_logging_level, 1, vs_proc_source, 'SP', vs_log_msg, 'T' , 'C' );

vs_log_msg := RPAD('vi_logging_level' , 31) ||': '|| vi_logging_level;

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

vs_log_msg := RPAD('is_http_url' , 31) ||': '|| NVL( is_http_url , 'NULL' );

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

vs_log_msg := RPAD('is_http_url_params', 31) ||': '|| NVL( is_http_url_params, 'NULL' );

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

/************************************************************************************************************
******/

/* Check the timeout setting

/************************************************************************************************************
******/

UTL_HTTP.get_transfer_timeout ( vi_timeout_now ) ;

vs_log_msg := RPAD('vi_timeout_now', 31) ||': '|| NVL( TO_CHAR(vi_timeout_now), '0' );


LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

/************************************************************************************************************
******/

/* Check that GET has been enabled

/************************************************************************************************************
******/

SELECT COUNT(*)

INTO vi_exists

FROM APS_PARAMS

WHERE pname = 'JSPGetAllow';

vs_log_msg := RPAD('vi_exists', 31) ||': '|| NVL( TO_CHAR(vi_exists), 'NULL' );

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

IF vi_exists <> 1 THEN

vs_msg := 'The APS_PARAM parameter ''JSPGetAllow'' cannot not be found. This feature cannot be enabled until the parameter
is added and set to TRUE.';

RAISE e_config_error;

END IF;

--get_param ('APS_PARAMS', 'JSPGetAllow', vs_JSPGetAllow, null);

SELECT value_number

INTO vi_JSPGetAllow

FROM APS_PARAMS

WHERE pname = 'JSPGetAllow';

vs_log_msg := RPAD('vi_JSPGetAllow', 31) ||': '|| NVL( TO_CHAR(vi_JSPGetAllow), 'NULL' );

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );


IF vi_JSPGetAllow <> 1 THEN

vs_msg := 'This feature has not been enabled, Please set the APS_PARAMS parameter ''JSPGetAllow''';

RAISE e_config_error;

END IF;

get_param('sys_params', 'AppServerURL', vs_p_server);

vs_log_msg := RPAD('vs_p_server', 31) ||': '|| NVL( vs_p_server, 'NULL' );

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

IF is_http_url IS NOT NULL THEN

IF vs_p_server IS NOT NULL THEN

IF INSTR(is_http_url, vs_p_server) = 0 THEN

vs_msg := 'WARNING : The AppServerURL setting : '|| vs_p_server ||' is not found in the URL passed';

DBEX ( vs_msg, vs_proc_name, 'E');

vs_log_msg := vs_msg;

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

END IF;

END IF;

/************************************************************************************************************
***/

vs_log_msg := 'Build the full URL';

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

/************************************************************************************************************
***/

req := UTL_HTTP.begin_request( is_http_url, 'POST');

UTL_HTTP.set_header ( req, 'Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8' );


UTL_HTTP.set_header ( req, 'Content-Length', vi_length_in_bytes );

vs_log_msg := RPAD('vi_length_in_bytes',31) ||': '|| vi_length_in_bytes;

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

UTL_HTTP.write_text ( req, is_http_url_params );

/************************************************************************************************************
***/

vs_log_msg := 'Get Response';

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

/************************************************************************************************************
***/

resp := UTL_HTTP.get_response( req );

/************************************************************************************************************
***/

vs_log_msg := 'Read Response';

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

/************************************************************************************************************
***/

--utl_http.read_line ( resp, os_http_resp, true );

BEGIN

LOOP

UTL_HTTP.read_text ( resp, vs_buffer, 32766 );

IF vs_buffer IS NOT NULL THEN

os_http_resp := os_http_resp || vs_buffer;

END IF;
vs_log_msg := RPAD('LEN vs_buffer', 31) ||': '|| LENGTH( vs_buffer );

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

vs_log_msg := RPAD('vs_buffer' , 31) ||': '|| NVL(vs_buffer , NULL );

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

END LOOP;

EXCEPTION

WHEN UTL_HTTP.end_of_body THEN

/*********************************************************************************************************/

vs_log_msg := 'LOOP EXCEPTION : UTL_HTTP.end_of_body';

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

/*********************************************************************************************************/

vs_log_msg := RPAD('vs_buffer' ,31) ||': '|| NVL( vs_buffer, 'NULL');

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

NULL;

END;

vs_log_msg := RPAD('os_http_resp',31) ||': '|| NVL( os_http_resp, 'NULL');

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

/************************************************************************************************************
***/

vs_log_msg := 'End Response';

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

/************************************************************************************************************
***/

UTL_HTTP.end_response ( resp );

ELSE
vs_msg := 'The passed in HTTP URL cannot be NULL';

DBEX ( vs_msg, vs_proc_name, 'E');

vs_log_msg := vs_msg;

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

END IF;

vs_log_msg := 'Procedure Completed';

LOG_IT ( vs_log_table, vi_logging_level ,1 , vs_proc_source,'EP', vs_log_msg, NULL , NULL);

EXCEPTION

WHEN e_config_error THEN

/************************************************************************************************************
***/

vs_log_msg := 'EXCEPTION : Config error';

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

/************************************************************************************************************
***/

vs_msg := NVL( vs_msg, 'EXCEPTION : Config error' );

DBEX ( vs_msg, vs_proc_name, 'E');

vs_log_msg := vs_msg;

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

vs_log_msg := 'Procedure Completed - With an error';

LOG_IT ( vs_log_table, vi_logging_level ,1 , vs_proc_source,'EP', vs_log_msg, NULL , NULL);

RAISE_APPLICATION_ERROR(-20000, vs_msg);
WHEN UTL_HTTP.end_of_body THEN

/************************************************************************************************************
***/

vs_log_msg := 'EXCEPTION : UTL_HTTP.end_of_body'

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

/************************************************************************************************************
***/

vs_log_msg := RPAD('LEN vs_buffer', 31) ||': '|| LENGTH( vs_buffer );

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

vs_log_msg := RPAD('vs_buffer' , 31) ||': '|| NVL(vs_buffer , NULL );

LOG_IT ( vs_log_table, vi_logging_level, 3, vs_proc_source, 'D', vs_log_msg, NULL , NULL );

os_http_resp := vs_buffer;

/************************************************************************************************************
***/

vs_log_msg := 'EXCEPTION : utl_http.end_of_body';

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

vs_log_msg := 'End Response';

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

/************************************************************************************************************
***/

utl_http.end_response ( resp );

vs_log_msg := 'Procedure Completed - With an error';

LOG_IT ( vs_log_table, vi_logging_level ,1 , vs_proc_source,'EP', vs_log_msg, NULL , NULL);

WHEN OTHERS THEN


vi_error_code := SQLCODE;

vs_error_text := SQLERRM;

/************************************************************************************************************
***/

vs_log_msg := 'EXCEPTION : WHEN OTHERS';

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

/************************************************************************************************************
***/

vs_msg := SUBSTR( vs_error_text, 1, 4000);

DBEX ( vs_msg, vs_proc_name, 'E');

vs_log_msg := RPAD('vi_error_code',31) ||': '|| vi_error_code;

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

vs_log_msg := vs_msg;

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

/************************************************************************************************************
***/

/* ORA-29273: HTTP request failed

/* ORA-06512: at "SYS.UTL_HTTP", line 1130

/* ORA-24247: network access denied by access control list (ACL)

/************************************************************************************************************
***/

IF INSTR( vs_error_text, 'ORA-24247' ) > 0 THEN

vs_msg := 'ORA-24247: Please add Demantra schema owner to the Oracle ACL by running sys_grants.sql';

DBEX ( vs_msg, vs_proc_name, 'E');

vs_log_msg := vs_msg;

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);


END IF;

/************************************************************************************************************
***/

/* ORA-29273: HTTP request failed

/* ORA-06512: at "SYS.UTL_HTTP", line 1367

/* ORA-29276: transfer timeout"

/************************************************************************************************************
***/

IF INSTR( vs_error_text, 'ORA-29276' ) > 0 THEN

vs_msg := 'The URL reached the Apps Server but the response timed out';

DBEX ( vs_msg, vs_proc_name, 'E');

vs_log_msg := vs_msg;\

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

END IF;

/************************************************************************************************************
***/

/* ORA-29273: HTTP request failed

/* ORA-06512: at "SYS.UTL_HTTP", line 1130

/* ORA-12541: TNS:no listener

/************************************************************************************************************
***/

IF INSTR( vs_error_text, 'ORA-12541' ) > 0 THEN

vs_msg := 'Could not reach the host. Check the host name, port and path and that the Applications Server is up.';

DBEX ( vs_msg, vs_proc_name, 'E');


vs_log_msg := vs_msg;

LOG_IT ( vs_log_table, vi_logging_level ,2 , vs_proc_source,'M', vs_log_msg, NULL , NULL);

END IF;

vs_log_msg := 'Procedure Completed - With an error '|| TO_CHAR( vi_error_code );

LOG_IT ( vs_log_table, vi_logging_level ,1 , vs_proc_source,'EP', vs_log_msg, NULL , NULL);

RAISE_APPLICATION_ERROR(-20000, vs_msg);

END post_url_http;

You might also like