4 Replies Latest reply on Apr 21, 2016 3:08 PM by Kris Rice-Oracle

    ORDS3 - Request information

    TimC.

      Dearest forum members.

       

      I recently started porting an ORDS2 webservice to ORDS3, but I'm running into some issues with the bind variables that contain information about the incoming request. The variables :BODY, :CONTENT_TYPE, :X_APEX_METHOD and :X_APEX_PATH are all NULL. I want to use these variables for logging purposes, but have some use cases where we actually need the full request body. I can't find anything about them being replaced by new variables (in fact, it's very hard to find information about them at all) but would really like to use them.

       

      I currently have this code to make the ORDS3 service:

       

      begin
        ORDS.DEFINE_SERVICE(
          p_module_name => 'rs1900.customerspoints' ,
          p_base_path   => '/customerpoints/',
          p_pattern     => '/:STORE',
          p_source_type => ords.source_type_plsql,
          p_source => q'[
            declare
              l_obj_request obj_request_rs;
            begin
              l_obj_request := obj_request_rs(
                  method        => nvl(:X_APEX_METHOD, 'UNK')
                , uri           => nvl(:X_APEX_PATH, '?')
                , content_type  => :content_type
                , body          => :body
              );
              
              -- Log :body - it is always null.
               
              if :STORE is null then 
                htp.prn('{}');
              else 
                pck_rest_klantenpunten_rs.get_klantenpunten(
                    i_request => l_obj_request
                  , i_wnkkl => to_number(:STORE)
                );
              end if;
            exception
              when others then
                -- Write logs.
                raise;
            end;
          ]'
        );
      end;
      

       

      The exact PLSQL block is working on ORDS2 but crashes on ORDS3 because :BODY and :CONTENT_TYPE are NULL.

       

      Does anyone have information about the :BODY,:CONTENT_TYPE,:X_APEX_METHOD and :X_APEX_PATH variables (or their possible replacements) and some documentation about how to use these variables in ORDS3?

       

      Thanks in advance.

        • 1. Re: ORDS3 - Request information
          Kiran Pawar

          Hi TimC,

          TimC. wrote:

           

          I recently started porting an ORDS2 webservice to ORDS3, but I'm running into some issues with the bind variables that contain information about the incoming request. The variables :BODY, :CONTENT_TYPE, :X_APEX_METHOD and :X_APEX_PATH are all NULL. I want to use these variables for logging purposes, but have some use cases where we actually need the full request body. I can't find anything about them being replaced by new variables (in fact, it's very hard to find information about them at all) but would really like to use them.

          I currently have this code to make the ORDS3 service:

          The exact PLSQL block is working on ORDS2 but crashes on ORDS3 because :BODY and :CONTENT_TYPE are NULL.

               With ORDS 3 there are two options to define a RESTful Web Services:

          • RESTful Web Service defined in ORDS Metadata (using SQL Developer or ORDS PL/SQL API) viz. ORDS_METADATA user repository.
          • RESTful Web Service defined in APEX Metadata (using SQL Workshop in APEX) viz. APEX_REST_PUBLIC_USER user repository.

               In fact RESTful Services in Oracle are transitioning from earlier APEX based to now ORDS based.

               So, the following is the answer to your question:

          • Use small cased :body and :content_type instead of :BODY and :CONTENT_TYPE as these bind variables work in ORDS defined web services.
          • There are no :X_APEX_METHOD and :X_APEX_PATH. It is a typo, instead use :X-APEX-METHOD and :X-APEX-PATH. But these bind variables will mostly work in APEX defined web services, than ORDS defined.

           

               Refer: Re: Session bind variables

           

          Regards,

          Kiran

          1 person found this helpful
          • 2. Re: Re: ORDS3 - Request information
            TimC.

            Kiran, thanks for an already helpful answer. However, I still cannot get the information in the request body.

            I currently define the service as such, from SQL developer:

             

            begin
              ords.define_service(
                p_module_name  => 'rs1900.klantenpunten4' ,
                p_base_path    => '/klantenpunten4/',
                p_pattern      => '/:STORE',
                p_source_type => ords.source_type_plsql,
                p_source      => q'[
            declare
              l_obj_request obj_request_rs;
              l_dummy winkels_rs.dewnknr%TYPE;
            begin
              pck_ts_log.init('WEBSERVICE.KLANTENPUNTEN');
              pck_ts_log.add('WEBSERVICE', 'KLANTENPUNTEN', 'NRM', 0, 'Begin');
            
              if :body is null then
                pck_ts_log.add('WEBSERVICE', 'KLANTENPUNTEN', 'NRM', 0, ':body is null');
              else
                pck_ts_log.add('WEBSERVICE', 'KLANTENPUNTEN', 'NRM', 0, 'body length: ' || length(:body));
              end if;
            
              pck_ts_log.write('WEBSERVICE.KLANTENPUNTEN', 'NRM');
            
              pck_rest_klantenpunten_rs.get_klantenpunten(
                i_request => null,
                i_wnkkl  => to_number(:STORE)
              );
            exception when others then
              pck_ts_log.debug('WEBSERVICE', 'KLANTENPUNTEN', 'ERR', 'others' || chr(10)
                                || '    winkel = ' || :STORE
                                , sqlerrm, dbms_utility.format_error_backtrace, null, null);
              pck_ts_log.write('WEBSERVICE.KLANTENPUNTEN', 'ERR');
              raise;
            end;
                ]'
              );
            end;
            

             

            The PCK_TS_LOG package is a custom logging package that writes logs to the database. It always executes the code in the 'if :body is null then' clause, which means it always logs ':body is null'. I'm using lower case letters for the :body variable. Is there anything I am forgetting?

             

            Thanks again!

            • 3. Re: ORDS3 - Request information
              PeeZu

              Hello,

               

              The :body ans :content_type are bind only on POST, PUT and DELETE method.

               

              I don't know if this behaviour is expected or is an ORDS bug.

               

              Regards

              • 4. Re: ORDS3 - Request information
                Kris Rice-Oracle

                HTTP GET requests can not have a body ergo can't have a content type for that body.