Sunday, March 25, 2018

Gateway Debug Points


Debug point to decide Entity, Entityset, Count, Metadata etc.

Class: /IWCOR/CL_DS_PROC_DISPATCHER
method /IWCOR/IF_DS_PROCESSOR~PROCESS.
  DATA:
    lo_uri TYPE REF TO /IWCOR/if_DS_uri,
    lv_http_method TYPE string,
    lv_content_type TYPE string,
    lo_edm_error TYPE REF TO /IWCOR/cx_DS_edm_error,
    lo_move_cast_error TYPE REF TO cx_sy_move_cast_error,
    lo_multipart_entity TYPE REF TO /IWCOR/if_REST_MP_entity,
    lo_entity TYPE REF TO /iwcor/if_rest_entity,
    lo_ds_exception TYPE REF TO /iwcor/cx_ds_exception.

  mo_context io_context.
  TRY.
      mo_service ?= io_context->get_service).
    CATCH cx_sy_move_cast_error INTO lo_move_cast_error.
      RAISE EXCEPTION TYPE /IWCOR/cx_DS_internal_error
        EXPORTING
          previous lo_move_cast_error.
  ENDTRY.

  mv_header_accept io_request->get_header_fieldif_http_header_fields=>accept ).

  lv_http_method io_request->get_method).
  TRANSLATE lv_http_method TO UPPER CASE.
  lo_uri io_context->get_uri).

  TRY.

    CASE lo_uri->uri_type.

        " service
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_0.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get.
            process_serviceio_uri lo_uri io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        " entity set
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_1 OR
           /IWCOR/if_DS_uri=>gc_uri_type_6b.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get.
            process_entity_set(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_response io_response ).
          WHEN /IWCOR/if_REST_request=>gc_method_post.
            lo_entity io_request->get_entity).
            process_entity_set(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_request_entity lo_entity
              io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        " entity
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_2 OR
           /IWCOR/if_DS_uri=>gc_uri_type_6a.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get OR
               /IWCOR/if_REST_request=>gc_method_delete.
            process_entity(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_response io_response ).
          WHEN /IWCOR/if_REST_request=>gc_method_put OR
               /IWCOR/if_REST_request=>gc_method_merge OR
               /IWCOR/if_REST_request=>gc_method_patch.
            lo_entity io_request->get_entity).
            process_entity(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_request_entity lo_entity
              io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        " entity complex property
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_3.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get.
            process_complex_property(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_response io_response ).
          WHEN /IWCOR/if_REST_request=>gc_method_put OR
               /IWCOR/if_REST_request=>gc_method_merge OR
               /IWCOR/if_REST_request=>gc_method_patch.
            lo_entity io_request->get_entity).
            process_complex_property(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_request_entity lo_entity
              io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        " entity simple property or entity simple property value
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_4 OR
           /IWCOR/if_DS_uri=>gc_uri_type_5.
        IF lo_uri->value abap_true.
          CASE lv_http_method.
            WHEN /IWCOR/if_REST_request=>gc_method_get OR
                 /IWCOR/if_REST_request=>gc_method_delete.
              process_property_value(
                iv_http_method lv_http_method
                io_uri lo_uri
                io_response io_response ).
            WHEN /IWCOR/if_REST_request=>gc_method_put OR
                 /IWCOR/if_REST_request=>gc_method_merge OR
                 /IWCOR/if_REST_request=>gc_method_patch.
              lo_entity io_request->get_entity).
              process_property_value(
                iv_http_method lv_http_method
                io_uri lo_uri
                io_request_entity lo_entity
                io_response io_response ).
            WHEN OTHERS.
              RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
          ENDCASE.
        ELSE.
          CASE lv_http_method.
            WHEN /IWCOR/if_REST_request=>gc_method_get.
              process_simple_property(
                iv_http_method lv_http_method
                io_uri lo_uri
                io_response io_response ).
            WHEN /IWCOR/if_REST_request=>gc_method_put OR
                 /IWCOR/if_REST_request=>gc_method_merge OR
                 /IWCOR/if_REST_request=>gc_method_patch.
              lo_entity io_request->get_entity).
              process_simple_property(
                iv_http_method lv_http_method
                io_uri lo_uri
                io_request_entity lo_entity
                io_response io_response ).
            WHEN OTHERS.
              RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
          ENDCASE.
        ENDIF.

        " entity link
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_7a.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get OR
               /IWCOR/if_REST_request=>gc_method_delete.
            process_link(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_response io_response ).
          WHEN /IWCOR/if_REST_request=>gc_method_put OR
               /IWCOR/if_REST_request=>gc_method_merge OR
               /IWCOR/if_REST_request=>gc_method_patch.
            lo_entity io_request->get_entity).
            process_link(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_request_entity lo_entity
              io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        " entity links
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_7b.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get.
            process_links(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_response io_response ).
          WHEN /IWCOR/if_REST_request=>gc_method_post.
            lo_entity io_request->get_entity).
            process_links(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_request_entity lo_entity
              io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        "  $metadata
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_8.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get.
            process_metadataio_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        " $batch
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_9.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_post.
            lv_content_type io_request->get_header_fieldif_http_header_fields=>content_type ).
            TRANSLATE lv_content_type TO LOWER CASE.
            IF lv_content_type IS INITIAL.
              RAISE EXCEPTION TYPE /IWCOR/cx_DS_bad_request.
            ELSEIF strlenlv_content_type 15 or lv_content_type(15<> /IWCOR/if_REST_media_type=>gc_multipart_mixed.
              RAISE EXCEPTION TYPE /IWCOR/cx_DS_unsupp_media_type.
            ENDIF.
            TRY.
                lo_multipart_entity ?= io_request->get_entity).
              CATCH cx_sy_move_cast_error INTO lo_move_cast_error.
                RAISE EXCEPTION TYPE /IWCOR/cx_DS_unsupp_media_type
                  EXPORTING
                    previous lo_move_cast_error.
            ENDTRY.
            process_batch(
              io_request_entity lo_multipart_entity
              io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        " function import
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_10 OR
           /IWCOR/if_DS_uri=>gc_uri_type_11 OR
           /IWCOR/if_DS_uri=>gc_uri_type_12 OR
           /IWCOR/if_DS_uri=>gc_uri_type_13.
        process_function_import(
          iv_http_method lv_http_method
          io_uri      lo_uri
          io_response io_response ).

        " function import primitve
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_14.
        IF lo_uri->value abap_true.
          process_function_import_value(
            iv_http_method lv_http_method
            io_uri      lo_uri
            io_response io_response ).
        ELSE.
          process_function_import(
            iv_http_method lv_http_method
            io_uri      lo_uri
            io_response io_response ).
        ENDIF.

        " entity set count
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_15.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get.
            process_entity_set_countio_uri lo_uri io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        " entity exists
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_16.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get.
            process_entity_existsio_uri lo_uri io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        " media resource
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_17.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get OR
               /IWCOR/if_REST_request=>gc_method_delete.
            process_entity_media(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_response io_response ).
          WHEN /IWCOR/if_REST_request=>gc_method_put.
            lo_entity io_request->get_entity).
            process_entity_media(
              iv_http_method lv_http_method
              io_uri lo_uri
              io_request_entity lo_entity
              io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        " entity link exists
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_50a.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get.
            process_link_existsio_uri lo_uri io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

        " entity links count
      WHEN /IWCOR/if_DS_uri=>gc_uri_type_50b.
        CASE lv_http_method.
          WHEN /IWCOR/if_REST_request=>gc_method_get.
            process_links_countio_uri lo_uri io_response io_response ).
          WHEN OTHERS.
            RAISE EXCEPTION TYPE /IWCOR/cx_DS_methd_not_allowed.
        ENDCASE.

      WHEN OTHERS.
        RAISE EXCEPTION TYPE /IWCOR/cx_DS_internal_error.
    ENDCASE.

   CATCH /iwcor/cx_ds_exception into lo_ds_exception.

      RAISE EXCEPTION TYPE /iwcor/cx_ds_internal_error
        EXPORTING
          previous lo_ds_exception.

  ENDTRY.

endmethod.

No comments:

Post a Comment