handler_cleanup (#1509)

* handler_cleanup

* Update src/02/z2ui5_cl_http_handler.clas.abap

Co-authored-by: abaplint[bot] <24845621+abaplint[bot]@users.noreply.github.com>

---------

Co-authored-by: abaplint[bot] <24845621+abaplint[bot]@users.noreply.github.com>
This commit is contained in:
oblomov-dev 2024-10-17 19:51:18 +02:00 committed by GitHub
parent 0d9ed1adf2
commit f6c111b907
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 118 additions and 95 deletions

View File

@ -353,13 +353,14 @@ CLASS z2ui5_cl_core_client IMPLEMENTATION.
val = `STATEFUL_ALREADY_ACTIVATED_ERROR`.
ENDIF.
IF stateful = abap_true.
mo_action->ms_next-s_set-handler_attrs-stateful-active = 1.
* mo_action->ms_next-s_set-handler_attrs-
mo_action->ms_next-s_set-s_stateful-active = 1.
CAST z2ui5_if_app( mo_action->mo_app->mo_app )->check_sticky = abap_true.
ELSE.
mo_action->ms_next-s_set-handler_attrs-stateful-active = 0.
mo_action->ms_next-s_set-s_stateful-active = 0.
CAST z2ui5_if_app( mo_action->mo_app->mo_app )->check_sticky = abap_false.
ENDIF.
mo_action->ms_next-s_set-handler_attrs-stateful-switched = abap_true.
mo_action->ms_next-s_set-s_stateful-switched = abap_true.
ENDMETHOD.
ENDCLASS.

View File

@ -16,10 +16,8 @@ CLASS z2ui5_cl_core_http_post DEFINITION
val TYPE string.
METHODS main
EXPORTING
attributes TYPE z2ui5_if_types=>ty_s_http_handler_attributes
RETURNING
VALUE(result) TYPE string.
VALUE(result) TYPE z2ui5_if_core_types=>ty_s_http_res.
PROTECTED SECTION.
@ -48,7 +46,7 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION.
METHOD main.
CLEAR attributes.
* CLEAR attributes.
main_begin( ).
DO.
@ -56,8 +54,11 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION.
EXIT.
ENDIF.
ENDDO.
result = mv_response.
attributes = ms_response-s_front-params-handler_attrs.
result = VALUE #(
body = mv_response
s_stateful = ms_response-s_front-params-s_stateful
).
ENDMETHOD.
@ -128,14 +129,8 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION.
METHOD main_process.
TRY.
DATA li_client TYPE REF TO z2ui5_cl_core_client.
TRY.
CREATE OBJECT li_client TYPE ('ZCL_2UI5_CUSTOM_CLIENT')
EXPORTING
action = mo_action.
CATCH cx_root.
li_client = NEW z2ui5_cl_core_client( mo_action ).
ENDTRY.
DATA(li_client) = NEW z2ui5_cl_core_client( mo_action ).
DATA(li_app) = CAST z2ui5_if_app( mo_action->mo_app->mo_app ).
IF li_app->check_sticky = abap_false.

View File

@ -15,6 +15,32 @@ INTERFACE z2ui5_if_core_types
one_time TYPE string VALUE `ONE_TIME`,
END OF cs_bind_type.
TYPES:
BEGIN OF ty_s_http_req,
method TYPE string,
body TYPE string,
END OF ty_s_http_req.
TYPES:
BEGIN OF ty_s_http_res,
body TYPE string,
status_code TYPE i,
status_reason TYPE string,
t_header TYPE z2ui5_if_types=>ty_t_name_value,
BEGIN OF s_stateful,
active TYPE i,
switched TYPE abap_bool,
END OF s_stateful,
END OF ty_s_http_res.
* TYPES:
* BEGIN OF ty_s_http_handler_attributes,
* BEGIN OF stateful,
* active TYPE i,
* switched TYPE abap_bool,
* END OF stateful,
* END OF ty_s_http_handler_attributes.
TYPES:
BEGIN OF ty_s_bind_config,
path_only TYPE abap_bool,
@ -114,7 +140,8 @@ INTERFACE z2ui5_if_core_types
BEGIN OF s_follow_up_action,
custom_js TYPE string,
END OF s_follow_up_action,
handler_attrs TYPE z2ui5_if_types=>ty_s_http_handler_attributes,
* handler_attrs TYPE ty_s_http_handler_attributes,
s_stateful TYPE ty_s_http_res-s_stateful,
END OF ty_s_next_frontend.
TYPES:

View File

@ -4,6 +4,14 @@ CLASS z2ui5_cl_http_handler DEFINITION
PUBLIC SECTION.
CLASS-METHODS run
IMPORTING
server TYPE REF TO object OPTIONAL
req TYPE REF TO object OPTIONAL
res TYPE REF TO object OPTIONAL
config TYPE z2ui5_if_types=>ty_s_http_config OPTIONAL
PREFERRED PARAMETER server.
CLASS-METHODS factory_cloud
IMPORTING
req TYPE REF TO object
@ -28,45 +36,29 @@ CLASS z2ui5_cl_http_handler DEFINITION
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_types=>ty_s_http_handler_attributes.
* DATA ms_session_attributes TYPE z2ui5_if_core_types=>ty_s_http_handler_attributes.
TYPES:
BEGIN OF ty_s_http_req,
method TYPE string,
body TYPE string,
END OF ty_s_http_req.
TYPES:
BEGIN OF ty_s_http_res,
body TYPE string,
status_code TYPE i,
status_reason TYPE string,
t_header TYPE z2ui5_if_types=>ty_t_name_value,
END OF ty_s_http_res.
DATA ms_req TYPE ty_s_http_req.
DATA ms_res TYPE ty_s_http_res.
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 set_config
IMPORTING
is_custom_config TYPE z2ui5_if_types=>ty_s_http_config.
METHODS http_get
IMPORTING
is_custom_config TYPE z2ui5_if_types=>ty_s_http_config.
METHODS http_get.
METHODS http_post.
METHODS session_handling
IMPORTING
attributes TYPE z2ui5_if_types=>ty_s_http_handler_attributes.
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.
@ -77,41 +69,14 @@ ENDCLASS.
CLASS z2ui5_cl_http_handler IMPLEMENTATION.
METHOD set_config.
ms_config = is_custom_config.
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`.
* 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 = `<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' 'unsafe-eval' data: ` &&
`ui5.sap.com *.ui5.sap.com sapui5.hana.ondemand.com *.sapui5.hana.ondemand.com openui5.hana.ondemand.com *.openui5.hana.ondemand.com ` &&
`sdk.openui5.org *.sdk.openui5.org cdn.jsdelivr.net *.cdn.jsdelivr.net cdnjs.cloudflare.com *.cdnjs.cloudflare.com schemas *.schemas"/>`.
ENDIF.
ENDMETHOD.
METHOD main.
ms_req-body = mo_server->get_cdata( ).
ms_req-method = mo_server->get_method( ).
ms_config = s_config.
set_request( ).
CASE ms_req-method.
WHEN `GET`.
http_get( s_config ).
http_get( ).
WHEN `POST`.
http_post( ).
WHEN `HEAD`.
@ -119,11 +84,8 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
RETURN.
ENDCASE.
mo_server->set_cdata( ms_res-body ).
mo_server->set_header_field( n = `cache-control` v = `no-cache` ).
mo_server->set_status( code = 200 reason = `success` ).
session_handling( ms_session_attributes ).
set_response( ).
session_handling( ).
ENDMETHOD.
@ -152,7 +114,6 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
METHOD http_get.
set_config( is_custom_config ).
ms_res-body = get_index_html( ).
ENDMETHOD.
@ -167,9 +128,7 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
lo_post->mv_request_json = ms_req-body.
ENDIF.
ms_res-body = lo_post->main(
IMPORTING
attributes = ms_session_attributes ).
ms_res = lo_post->main( ).
TRY.
IF lo_post IS BOUND.
@ -189,8 +148,8 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
METHOD session_handling.
"transform cookie to header based contextid handling
IF attributes-stateful-switched = abap_true.
mo_server->set_session_stateful( attributes-stateful-active ).
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.
@ -210,6 +169,26 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
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`.
* 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 = `<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' 'unsafe-eval' data: ` &&
`ui5.sap.com *.ui5.sap.com sapui5.hana.ondemand.com *.sapui5.hana.ondemand.com openui5.hana.ondemand.com *.openui5.hana.ondemand.com ` &&
`sdk.openui5.org *.sdk.openui5.org cdn.jsdelivr.net *.cdn.jsdelivr.net cdnjs.cloudflare.com *.cdnjs.cloudflare.com schemas *.schemas"/>`.
ENDIF.
IF ms_config-styles_css IS INITIAL.
DATA(lv_style_css) = z2ui5_cl_app_style_css=>get( ).
ELSE.
@ -263,4 +242,33 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
ENDMETHOD.
METHOD run.
DATA(lo_handler) = factory(
server = server
req = req
res = res
).
lo_handler->main( config ).
ENDMETHOD.
METHOD set_request.
ms_req-body = mo_server->get_cdata( ).
ms_req-method = mo_server->get_method( ).
ENDMETHOD.
METHOD set_response.
mo_server->set_cdata( ms_res-body ).
mo_server->set_header_field( n = `cache-control` v = `no-cache` ).
mo_server->set_status( code = 200 reason = `success` ).
ENDMETHOD.
ENDCLASS.

View File

@ -19,14 +19,6 @@ INTERFACE z2ui5_if_types
custom_js TYPE string,
END OF ty_s_http_config.
TYPES:
BEGIN OF ty_s_http_handler_attributes,
BEGIN OF stateful,
active TYPE i,
switched TYPE abap_bool,
END OF stateful,
END OF ty_s_http_handler_attributes.
TYPES:
BEGIN OF ty_s_draft,
id TYPE string,