From eb45fcd2a4bce6f78a09d6d3c36d05cdcf9823a7 Mon Sep 17 00:00:00 2001 From: oblomov-dev <102328295+oblomov-dev@users.noreply.github.com> Date: Mon, 21 Oct 2024 09:02:28 +0200 Subject: [PATCH] adjust http handler to call from outside (#1511) --- src/01/02/z2ui5_cl_core_http_post.clas.abap | 3 +- src/02/z2ui5_cl_http_handler.clas.abap | 182 ++++++++++---------- 2 files changed, 93 insertions(+), 92 deletions(-) diff --git a/src/01/02/z2ui5_cl_core_http_post.clas.abap b/src/01/02/z2ui5_cl_core_http_post.clas.abap index 9c4e0d10..6df7da1a 100644 --- a/src/01/02/z2ui5_cl_core_http_post.clas.abap +++ b/src/01/02/z2ui5_cl_core_http_post.clas.abap @@ -46,7 +46,6 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION. METHOD main. -* CLEAR attributes. main_begin( ). DO. @@ -58,7 +57,7 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION. result = VALUE #( body = mv_response s_stateful = ms_response-s_front-params-s_stateful - ). + ). ENDMETHOD. diff --git a/src/02/z2ui5_cl_http_handler.clas.abap b/src/02/z2ui5_cl_http_handler.clas.abap index 405fd9e6..2c497396 100644 --- a/src/02/z2ui5_cl_http_handler.clas.abap +++ b/src/02/z2ui5_cl_http_handler.clas.abap @@ -28,35 +28,39 @@ CLASS z2ui5_cl_http_handler DEFINITION RETURNING VALUE(result) TYPE REF TO z2ui5_cl_http_handler. + CLASS-METHODS _http_post + IMPORTING + is_req TYPE z2ui5_if_core_types=>ty_s_http_req + RETURNING + VALUE(result) TYPE z2ui5_if_core_types=>ty_s_http_res. + + CLASS-METHODS _http_get + IMPORTING + VALUE(is_config) TYPE z2ui5_if_types=>ty_s_http_config + RETURNING + VALUE(result) TYPE string. + METHODS main IMPORTING s_config TYPE z2ui5_if_types=>ty_s_http_config OPTIONAL. + CLASS-METHODS _main + IMPORTING + is_config TYPE z2ui5_if_types=>ty_s_http_config + is_req TYPE z2ui5_if_core_types=>ty_s_http_req + RETURNING + VALUE(result) TYPE z2ui5_if_core_types=>ty_s_http_res. + PROTECTED SECTION. CLASS-DATA so_sticky_handler TYPE REF TO z2ui5_cl_core_http_post. DATA mo_server TYPE REF TO z2ui5_cl_abap_api_http. -* DATA ms_session_attributes TYPE z2ui5_if_core_types=>ty_s_http_handler_attributes. DATA ms_req TYPE z2ui5_if_core_types=>ty_s_http_req. DATA ms_res TYPE z2ui5_if_core_types=>ty_s_http_res. DATA ms_config TYPE z2ui5_if_types=>ty_s_http_config. - METHODS http_get. - - METHODS http_post. - - METHODS session_handling. -* IMPORTING -* attributes TYPE z2ui5_if_core_types=>ty_s_http_handler_attributes. - - METHODS get_index_html - RETURNING - VALUE(result) TYPE string - ##CALLED. - METHODS set_request. - METHODS set_response. PRIVATE SECTION. @@ -75,17 +79,14 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION. set_request( ). CASE ms_req-method. - WHEN `GET`. - http_get( ). - WHEN `POST`. - http_post( ). WHEN `HEAD`. mo_server->set_session_stateful( 0 ). RETURN. + WHEN OTHERS. + ms_res = _main( is_req = ms_req is_config = ms_config ). ENDCASE. set_response( ). - session_handling( ). ENDMETHOD. @@ -112,97 +113,43 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION. ENDMETHOD. - METHOD http_get. - ms_res-body = get_index_html( ). + METHOD _http_get. - ENDMETHOD. - - - METHOD http_post. - - IF so_sticky_handler IS NOT BOUND. - DATA(lo_post) = NEW z2ui5_cl_core_http_post( ms_req-body ). - ELSE. - lo_post = so_sticky_handler. - lo_post->mv_request_json = ms_req-body. + IF is_config-title IS INITIAL. + is_config-title = `abap2UI5`. ENDIF. - ms_res = lo_post->main( ). - - TRY. - IF lo_post IS BOUND. - DATA(li_app) = CAST z2ui5_if_app( lo_post->mo_action->mo_app->mo_app ). - IF li_app->check_sticky = abap_true. - so_sticky_handler = lo_post. - ELSE. - CLEAR so_sticky_handler. - ENDIF. - ENDIF. - CATCH cx_root. - ENDTRY. - - ENDMETHOD. - - - METHOD session_handling. - - "transform cookie to header based contextid handling - IF ms_res-s_stateful-switched = abap_true. - mo_server->set_session_stateful( ms_res-s_stateful-active ). - IF mo_server->get_header_field( 'sap-contextid-accept' ) = 'header'. - DATA(lv_contextid) = mo_server->get_response_cookie( 'sap-contextid' ). - IF lv_contextid IS NOT INITIAL. - mo_server->delete_response_cookie( 'sap-contextid' ). - mo_server->set_header_field( n = 'sap-contextid' v = lv_contextid ). - ENDIF. - ENDIF. - ELSE. - lv_contextid = mo_server->get_header_field( 'sap-contextid' ). - IF lv_contextid IS NOT INITIAL. - mo_server->set_header_field( n = 'sap-contextid' v = lv_contextid ). - ENDIF. + IF is_config-theme IS INITIAL. + is_config-theme = `sap_horizon`. ENDIF. - ENDMETHOD. - - - METHOD get_index_html. - - IF ms_config-title IS INITIAL. - ms_config-title = `abap2UI5`. - ENDIF. - - IF ms_config-theme IS INITIAL. - ms_config-theme = `sap_horizon`. - ENDIF. - - IF ms_config-src IS INITIAL. - ms_config-src = `https://sdk.openui5.org/resources/sap-ui-cachebuster/sap-ui-core.js`. + IF is_config-src IS INITIAL. + is_config-src = `https://sdk.openui5.org/resources/sap-ui-cachebuster/sap-ui-core.js`. * ms_req_config-src = `https://sdk.openui5.org/1.71.67/resources/sap-ui-core.js`. * ms_req_config-src = `https://sdk.openui5.org/nightly/2/resources/sap-ui-core.js`. ENDIF. - IF ms_config-content_security_policy IS INITIAL. - ms_config-content_security_policy = ``. ENDIF. - IF ms_config-styles_css IS INITIAL. + IF is_config-styles_css IS INITIAL. DATA(lv_style_css) = z2ui5_cl_app_style_css=>get( ). ELSE. - lv_style_css = ms_config-styles_css. + lv_style_css = is_config-styles_css. ENDIF. result = `` && |\n| && `` && |\n| && `` && |\n| && - ms_config-content_security_policy && |\n| && + is_config-content_security_policy && |\n| && ` ` && |\n| && ` ` && |\n| && ` ` && |\n| && - | { ms_config-title } \n| && + | { is_config-title } \n| && | \n| && @@ -210,7 +157,7 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION. ` function onInitComponent(){` && |\n| && ` sap.ui.require.preload({` && |\n| && ` "z2ui5/manifest.json": '` && z2ui5_cl_app_manifest_json=>get( ) && `',` && |\n| && - ` "z2ui5/Component.js": function(){` && z2ui5_cl_app_component_js=>get( ) && ms_config-custom_js && `},` && |\n| && + ` "z2ui5/Component.js": function(){` && z2ui5_cl_app_component_js=>get( ) && is_config-custom_js && `},` && |\n| && ` "z2ui5/css/style.css": '` && lv_style_css && `',` && |\n| && ` "z2ui5/model/models.js": function(){` && z2ui5_cl_app_models_js=>get( ) && `},` && |\n| && ` "z2ui5/view/App.view.xml": '` && z2ui5_cl_app_app_xml=>get( ) && `',` && |\n| && @@ -228,9 +175,9 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION. `` && |\n| && `