mirror of
https://github.com/abap2UI5/abap2UI5.git
synced 2025-04-30 00:32:19 +08:00
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:
parent
0d9ed1adf2
commit
f6c111b907
|
@ -353,13 +353,14 @@ CLASS z2ui5_cl_core_client IMPLEMENTATION.
|
||||||
val = `STATEFUL_ALREADY_ACTIVATED_ERROR`.
|
val = `STATEFUL_ALREADY_ACTIVATED_ERROR`.
|
||||||
ENDIF.
|
ENDIF.
|
||||||
IF stateful = abap_true.
|
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.
|
CAST z2ui5_if_app( mo_action->mo_app->mo_app )->check_sticky = abap_true.
|
||||||
ELSE.
|
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.
|
CAST z2ui5_if_app( mo_action->mo_app->mo_app )->check_sticky = abap_false.
|
||||||
ENDIF.
|
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.
|
ENDMETHOD.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|
|
@ -16,10 +16,8 @@ CLASS z2ui5_cl_core_http_post DEFINITION
|
||||||
val TYPE string.
|
val TYPE string.
|
||||||
|
|
||||||
METHODS main
|
METHODS main
|
||||||
EXPORTING
|
|
||||||
attributes TYPE z2ui5_if_types=>ty_s_http_handler_attributes
|
|
||||||
RETURNING
|
RETURNING
|
||||||
VALUE(result) TYPE string.
|
VALUE(result) TYPE z2ui5_if_core_types=>ty_s_http_res.
|
||||||
|
|
||||||
PROTECTED SECTION.
|
PROTECTED SECTION.
|
||||||
|
|
||||||
|
@ -48,7 +46,7 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION.
|
||||||
|
|
||||||
|
|
||||||
METHOD main.
|
METHOD main.
|
||||||
CLEAR attributes.
|
* CLEAR attributes.
|
||||||
|
|
||||||
main_begin( ).
|
main_begin( ).
|
||||||
DO.
|
DO.
|
||||||
|
@ -56,8 +54,11 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION.
|
||||||
EXIT.
|
EXIT.
|
||||||
ENDIF.
|
ENDIF.
|
||||||
ENDDO.
|
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.
|
ENDMETHOD.
|
||||||
|
|
||||||
|
@ -128,14 +129,8 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION.
|
||||||
|
|
||||||
METHOD main_process.
|
METHOD main_process.
|
||||||
TRY.
|
TRY.
|
||||||
DATA li_client TYPE REF TO z2ui5_cl_core_client.
|
|
||||||
TRY.
|
DATA(li_client) = NEW z2ui5_cl_core_client( mo_action ).
|
||||||
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_app) = CAST z2ui5_if_app( mo_action->mo_app->mo_app ).
|
DATA(li_app) = CAST z2ui5_if_app( mo_action->mo_app->mo_app ).
|
||||||
|
|
||||||
IF li_app->check_sticky = abap_false.
|
IF li_app->check_sticky = abap_false.
|
||||||
|
|
|
@ -15,6 +15,32 @@ INTERFACE z2ui5_if_core_types
|
||||||
one_time TYPE string VALUE `ONE_TIME`,
|
one_time TYPE string VALUE `ONE_TIME`,
|
||||||
END OF cs_bind_type.
|
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:
|
TYPES:
|
||||||
BEGIN OF ty_s_bind_config,
|
BEGIN OF ty_s_bind_config,
|
||||||
path_only TYPE abap_bool,
|
path_only TYPE abap_bool,
|
||||||
|
@ -114,7 +140,8 @@ INTERFACE z2ui5_if_core_types
|
||||||
BEGIN OF s_follow_up_action,
|
BEGIN OF s_follow_up_action,
|
||||||
custom_js TYPE string,
|
custom_js TYPE string,
|
||||||
END OF s_follow_up_action,
|
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.
|
END OF ty_s_next_frontend.
|
||||||
|
|
||||||
TYPES:
|
TYPES:
|
||||||
|
|
|
@ -4,6 +4,14 @@ CLASS z2ui5_cl_http_handler DEFINITION
|
||||||
|
|
||||||
PUBLIC SECTION.
|
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
|
CLASS-METHODS factory_cloud
|
||||||
IMPORTING
|
IMPORTING
|
||||||
req TYPE REF TO object
|
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.
|
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 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:
|
DATA ms_req TYPE z2ui5_if_core_types=>ty_s_http_req.
|
||||||
BEGIN OF ty_s_http_req,
|
DATA ms_res TYPE z2ui5_if_core_types=>ty_s_http_res.
|
||||||
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_config TYPE z2ui5_if_types=>ty_s_http_config.
|
DATA ms_config TYPE z2ui5_if_types=>ty_s_http_config.
|
||||||
|
|
||||||
METHODS set_config
|
METHODS http_get.
|
||||||
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_post.
|
METHODS http_post.
|
||||||
|
|
||||||
METHODS session_handling
|
METHODS session_handling.
|
||||||
IMPORTING
|
* IMPORTING
|
||||||
attributes TYPE z2ui5_if_types=>ty_s_http_handler_attributes.
|
* attributes TYPE z2ui5_if_core_types=>ty_s_http_handler_attributes.
|
||||||
|
|
||||||
METHODS get_index_html
|
METHODS get_index_html
|
||||||
RETURNING
|
RETURNING
|
||||||
VALUE(result) TYPE string
|
VALUE(result) TYPE string
|
||||||
##CALLED.
|
##CALLED.
|
||||||
|
|
||||||
|
METHODS set_request.
|
||||||
|
|
||||||
|
METHODS set_response.
|
||||||
|
|
||||||
PRIVATE SECTION.
|
PRIVATE SECTION.
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,41 +69,14 @@ ENDCLASS.
|
||||||
CLASS z2ui5_cl_http_handler IMPLEMENTATION.
|
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.
|
METHOD main.
|
||||||
|
|
||||||
ms_req-body = mo_server->get_cdata( ).
|
ms_config = s_config.
|
||||||
ms_req-method = mo_server->get_method( ).
|
set_request( ).
|
||||||
|
|
||||||
CASE ms_req-method.
|
CASE ms_req-method.
|
||||||
WHEN `GET`.
|
WHEN `GET`.
|
||||||
http_get( s_config ).
|
http_get( ).
|
||||||
WHEN `POST`.
|
WHEN `POST`.
|
||||||
http_post( ).
|
http_post( ).
|
||||||
WHEN `HEAD`.
|
WHEN `HEAD`.
|
||||||
|
@ -119,11 +84,8 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
|
||||||
RETURN.
|
RETURN.
|
||||||
ENDCASE.
|
ENDCASE.
|
||||||
|
|
||||||
mo_server->set_cdata( ms_res-body ).
|
set_response( ).
|
||||||
mo_server->set_header_field( n = `cache-control` v = `no-cache` ).
|
session_handling( ).
|
||||||
mo_server->set_status( code = 200 reason = `success` ).
|
|
||||||
|
|
||||||
session_handling( ms_session_attributes ).
|
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
|
@ -152,7 +114,6 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
|
||||||
|
|
||||||
METHOD http_get.
|
METHOD http_get.
|
||||||
|
|
||||||
set_config( is_custom_config ).
|
|
||||||
ms_res-body = get_index_html( ).
|
ms_res-body = get_index_html( ).
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
@ -167,9 +128,7 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
|
||||||
lo_post->mv_request_json = ms_req-body.
|
lo_post->mv_request_json = ms_req-body.
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
|
||||||
ms_res-body = lo_post->main(
|
ms_res = lo_post->main( ).
|
||||||
IMPORTING
|
|
||||||
attributes = ms_session_attributes ).
|
|
||||||
|
|
||||||
TRY.
|
TRY.
|
||||||
IF lo_post IS BOUND.
|
IF lo_post IS BOUND.
|
||||||
|
@ -189,8 +148,8 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
|
||||||
METHOD session_handling.
|
METHOD session_handling.
|
||||||
|
|
||||||
"transform cookie to header based contextid handling
|
"transform cookie to header based contextid handling
|
||||||
IF attributes-stateful-switched = abap_true.
|
IF ms_res-s_stateful-switched = abap_true.
|
||||||
mo_server->set_session_stateful( attributes-stateful-active ).
|
mo_server->set_session_stateful( ms_res-s_stateful-active ).
|
||||||
IF mo_server->get_header_field( 'sap-contextid-accept' ) = 'header'.
|
IF mo_server->get_header_field( 'sap-contextid-accept' ) = 'header'.
|
||||||
DATA(lv_contextid) = mo_server->get_response_cookie( 'sap-contextid' ).
|
DATA(lv_contextid) = mo_server->get_response_cookie( 'sap-contextid' ).
|
||||||
IF lv_contextid IS NOT INITIAL.
|
IF lv_contextid IS NOT INITIAL.
|
||||||
|
@ -210,6 +169,26 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
|
||||||
|
|
||||||
METHOD get_index_html.
|
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.
|
IF ms_config-styles_css IS INITIAL.
|
||||||
DATA(lv_style_css) = z2ui5_cl_app_style_css=>get( ).
|
DATA(lv_style_css) = z2ui5_cl_app_style_css=>get( ).
|
||||||
ELSE.
|
ELSE.
|
||||||
|
@ -263,4 +242,33 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
|
||||||
|
|
||||||
ENDMETHOD.
|
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.
|
ENDCLASS.
|
||||||
|
|
|
@ -19,14 +19,6 @@ INTERFACE z2ui5_if_types
|
||||||
custom_js TYPE string,
|
custom_js TYPE string,
|
||||||
END OF ty_s_http_config.
|
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:
|
TYPES:
|
||||||
BEGIN OF ty_s_draft,
|
BEGIN OF ty_s_draft,
|
||||||
id TYPE string,
|
id TYPE string,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user