5 Replies Latest reply: Oct 31, 2012 5:29 PM by J-Lig RSS

    apex_web_service.make_rest_request wrapper missing header parms

    J-Lig
      APEX 4.1.1.00.23/Oracle 11g

      When attempting to use apex_web_service.make_rest_request, I found that it doesnt work with one of my web services because the service requires header parameters. The wrapper apex_web_service.make_rest_request is missing the two header paramters (p_http_headers, p_http_hdr_values) that are in the internal package wwv_flow_web_services.make_rest_request. I have tried passing the values into the two available p_parm_name and p_parm_value parameters, but it doesnt work. They have to be in the header.

      Im not really sure what to do. It does work within APEX application when it allows me to add a header parm, but I am trying to schedule it nightly as a job from the DB.

      Will it hurt anything for me to use the wwv_flow_web_services.make_rest_request?

      Any suggestions?

      Jennifer
        • 1. Re: apex_web_service.make_rest_request wrapper missing header parms
          J-Lig
          This works...

          declare
          l_clob CLOB;

          BEGIN

          l_clob := APEX_040100.wwv_flow_web_services.make_rest_request(
          p_url => 'https://stage-api.govdelivery.com/api/account/CAINSUR/bulletins/send_now',
          p_http_method => 'POST' ,
          p_username => 'user',
          p_password => 'password',
          p_body => '<?xml version="1.0" encoding="UTF-8"?>
          <bulletin>
          <body><![CDATA[<p>BODY in <b>cdata tag</b>
          <br/>
          <br/>This includes a link that should not be
          <a href="http://govdelivery.com">encoded</a>.</p>]]>
          </body>
          <subject>Bulletin sent to [[ACCOUNT_NAME]] using web services</subject>
          <topics type=''array''>
          <topic>
          <code>CAINSUR_1</code>
          </topic>
          </topics>
          <open_tracking type=''boolean''>false</open_tracking>
          <click_tracking type=''boolean''>false</click_tracking>
          </bulletin>
          ',
          p_http_headers => apex_util.string_to_table('Content-Type') ,
          p_http_hdr_values =>apex_util.string_to_table('application/xml'),
          p_wallet_path => 'file:/location/' ,
          p_wallet_pwd => 'password'
          );

          dbms_output.put_line(l_clob);

          END;
          • 2. Re: apex_web_service.make_rest_request wrapper missing header parms
            J-Lig
            Oops! I accidently posted the previous note twice

            Edited by: J-Lig on Sep 14, 2012 12:02 PM
            • 3. Re: apex_web_service.make_rest_request wrapper missing header parms
              J-Lig
              I endedup opening an SR for Oracle. I found out that headers (content-type) are set in global variables before making the apex_web_service.make_rest_request call.

              See http://docs.oracle.com/cd/E17556_01/doc/apirefs.40/e15519/apex_web_service.htm#autoId4 for a description of the headers and cookies.

              I endedup having to add the following to my code before apex_web_service.make_rest_request:

              apex_web_service.g_request_headers(1).name := 'Content-Type';
              apex_web_service.g_request_headers(1).value := 'application/xml';

              Once I did that, my service works. Odd. Not sure why they did it that way because their internal packages take header parameters, but the wrappers do it this way I guess.
              • 4. Re: apex_web_service.make_rest_request wrapper missing header parms
                J-Lig
                I endedup opening an SR for Oracle. I found out that headers (content-type) are set in global variables before making the apex_web_service.make_rest_request call.

                See http://docs.oracle.com/cd/E17556_01/doc/apirefs.40/e15519/apex_web_service.htm#autoId4 for a description of the headers and cookies.

                I endedup having to add the following to my code before apex_web_service.make_rest_request:

                apex_web_service.g_request_headers(1).name := 'Content-Type';
                apex_web_service.g_request_headers(1).value := 'application/xml';

                Once I did that, my service works. Odd. Not sure why they did it that way because their internal packages take header parameters, but the wrappers do it this way I guess.
                • 5. Re: apex_web_service.make_rest_request wrapper missing header parms
                  J-Lig
                  Additional information that may be useful for people related to this topic:

                  Just figured out another nice little nugget...when I got that web service call working, I happened to run a different call and spent hours trying to figure out why it didn’t work anymore. Unfortunately this is not documented very well (at least anywhere I could find). What I figured out (eventually) is that when you set those headers, ALL service calls use them. When I ran my other call, it was trying to use those headers too. In case you have the same issues, here are some helpful tasks that took me forever to figure out:

                  --To check the count of records in that g_request_headers table
                  l_count := apex_web_service.g_request_headers.count;
                  dbms_output.put_line('Count: '||l_count);

                  --To check the name of record (by index) in that g_request_headers table
                  --l_name := apex_web_service.g_request_headers(1).name;
                  dbms_output.put_line('Name: '||l_name);

                  --To check the value of record (by index) in that g_request_headers table
                  --l_value := apex_web_service.g_request_headers(1).value;
                  dbms_output.put_line('Value: '||l_value);

                  --To delete the records from the g_request_headers table
                  apex_web_service.g_request_headers.delete;

                  Jennifer