0

Dears, I have a oracle package where I request some http request from a tomcat server , I am using UTL_HTTP package to do so, now the request is working successfully the code to request is:

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,'CONENT-LENGT',LENGTH(V_BODY)
UTL_HTTP.SET_HEADER(REQ,'CONTENT-TYPE','APPLICATION/JSON')
UTL_HTTP.SET_HEADER(REQ,'SDATE','01/06/2021')
UTL_HTTP.WRITE_TEXT(REQ,BODY);
RES:= UTL_HTTP.GET_RESPONSE(REQ);
UTL_HTTP.SET_BODY_CHARSET(R => RES, CHARSET => 'UTF-8');
UTL_HTTP.READ_TEXT(RES,BUFFER);
UTL_HTTP.END_REQUEST(REQ);
UTL_HTTP.END_RESPONSE(RES);

the problem is that about 20% of request returning "http faild requesst" ORA-29273 any help to identify where the problem could be,I have done some researches but nothing so helpful...thanks in advance.

kikicoder
  • 383
  • 3
  • 16
  • 1
    Do you ever check what HTTP code is returned by the response? If you never check if the request failed at the remote server and if a response is returned that has a HTTP code that is not in the 200s (i.e. is not a success) then of course the HTTP request failed. You need to handle that remote failure gracefully. – MT0 Sep 10 '21 at 10:41
  • @MTO dear, you are right I should make that check, but the error seems happen before even I get a response and the exception raised before that I mean when I am trying to get the response the error appears – kikicoder Sep 10 '21 at 16:30

1 Answers1

0

I also faced problem like this one, in this case I suppose that you won't get status_code of the request, but you can read the detailed error of the request.

You should catch exception from

RES:= UTL_HTTP.GET_RESPONSE(REQ);

My version of code:

begin
       RES:= UTL_HTTP.GET_RESPONSE(REQ);
       v_Status_Code := RES.Status_Code;
     exception
       when others then
          o_Ora_Msg := sqlerrm;
  
           if RES.Reason_Phrase is not null then
             o_Ora_Msg := o_Ora_Msg || ',  http read error Reason_Phrase: ' || RES.Reason_Phrase;
           end if;
    
           if RES.Private_Hndl is not null then
             o_Ora_Msg := o_Ora_Msg || ',  Private_Hndl: ' || RES.Private_Hndl;
           end if;
    
           if Utl_Http.Get_Detailed_Sqlerrm is not null then
             o_Ora_Msg := o_Ora_Msg || ',  Get_Detailed_Sqlerrm: ' || Utl_Http.Get_Detailed_Sqlerrm;
           end if;
    
           if Utl_Http.Get_Detailed_Sqlcode is not null then
             o_Ora_Msg := o_Ora_Msg || ', Get_Detailed_Sqlcode: ' || Utl_Http.Get_Detailed_Sqlcode;
           end if;
    
           begin
             v_Status_Code := RES.Status_Code;
           exception
             when others then
               v_Status_Code := -1;
           end;
  
           if v_Status_Code is null then
             v_Status_Code := -5;
           end if;
 end;

The only way to define problem is to get detailed error, then you can analyse the rest.

You should check the logged outputs of o_Ora_Msg and v_Status_Code.

Will be glad if I could help.

Saidakmal
  • 36
  • 5