New handler (#1446)

* new handler

* update

* update

* update

* update

* update

* fix statefulness

* update

* update

* update
This commit is contained in:
oblomov-dev 2024-09-24 10:19:25 +02:00 committed by GitHub
parent 6c0843cb06
commit e9007c05da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 1069 additions and 904 deletions

View File

@ -0,0 +1,314 @@
CLASS z2ui5_cl_abap_api_http DEFINITION PUBLIC.
PUBLIC SECTION.
CLASS-METHODS factory
IMPORTING
server TYPE REF TO object
RETURNING
VALUE(result) TYPE REF TO z2ui5_cl_abap_api_http.
CLASS-METHODS factory_cloud
IMPORTING
req TYPE REF TO object
res TYPE REF TO object
RETURNING
VALUE(result) TYPE REF TO z2ui5_cl_abap_api_http.
METHODS get_header_field
IMPORTING
val TYPE clike
RETURNING
VALUE(result) TYPE string.
METHODS get_cdata
RETURNING
VALUE(result) TYPE string.
METHODS get_method
RETURNING
VALUE(result) TYPE string.
METHODS set_cdata
IMPORTING
val TYPE clike.
METHODS set_status
IMPORTING
code TYPE i
reason TYPE clike.
METHODS set_session_stateful
IMPORTING
val TYPE i.
METHODS get_response_cookie
IMPORTING
val TYPE clike
RETURNING
VALUE(result) TYPE string.
METHODS delete_response_cookie
IMPORTING
val TYPE clike.
METHODS set_header_field
IMPORTING
n TYPE clike
v TYPE clike.
DATA mo_server_onprem TYPE REF TO object.
PROTECTED SECTION.
DATA mo_request_cloud TYPE REF TO object.
DATA mo_response_cloud TYPE REF TO object.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_abap_api_http IMPLEMENTATION.
METHOD delete_response_cookie.
DATA(lv_val) = CONV string( val ).
IF mo_server_onprem IS BOUND.
DATA object TYPE REF TO object.
FIELD-SYMBOLS <any> TYPE any.
ASSIGN mo_server_onprem->('RESPONSE') TO <any>.
object = <any>.
CALL METHOD object->('DELETE_COOKIE')
EXPORTING
name = lv_val.
ELSE.
* CALL METHOD mo_response_cloud->('DELETE_COOKIE_AT_CLIENT')
* EXPORTING
* name = lv_val.
ENDIF.
ENDMETHOD.
METHOD get_response_cookie.
DATA object TYPE REF TO object.
FIELD-SYMBOLS <any> TYPE any.
DATA(lv_val) = CONV string( val ).
IF mo_server_onprem IS BOUND.
ASSIGN mo_server_onprem->('RESPONSE') TO <any>.
object = <any>.
CALL METHOD object->('GET_COOKIE')
EXPORTING
name = lv_val
IMPORTING
value = result.
ELSE.
* CALL METHOD mo_request_cloud->('GET_COOKIE')
* EXPORTING
* i_name = lv_val
* RECEIVING
* r_value = result.
ENDIF.
ENDMETHOD.
METHOD get_header_field.
DATA object TYPE REF TO object.
FIELD-SYMBOLS <any> TYPE any.
DATA(lv_val) = CONV string( val ).
IF mo_server_onprem IS BOUND.
ASSIGN mo_server_onprem->('REQUEST') TO <any>.
object = <any>.
CALL METHOD object->('GET_HEADER_FIELD')
EXPORTING
name = lv_val
RECEIVING
value = result.
ELSE.
CALL METHOD mo_request_cloud->('GET_HEADER_FIELD')
EXPORTING
i_name = lv_val
RECEIVING
r_value = result.
ENDIF.
ENDMETHOD.
METHOD set_header_field.
DATA object TYPE REF TO object.
FIELD-SYMBOLS <any> TYPE any.
DATA(lv_n) = CONV string( n ).
DATA(lv_v) = CONV string( v ).
IF mo_server_onprem IS BOUND.
ASSIGN mo_server_onprem->('RESPONSE') TO <any>.
object = <any>.
CALL METHOD object->('SET_HEADER_FIELD')
EXPORTING
name = lv_n
value = lv_v.
ELSE.
CALL METHOD mo_request_cloud->('SET_HEADER_FIELD')
EXPORTING
i_name = lv_n
i_value = lv_v.
ENDIF.
ENDMETHOD.
METHOD factory.
result = NEW #( ).
result->mo_server_onprem = server.
ENDMETHOD.
METHOD factory_cloud.
result = NEW #( ).
result->mo_request_cloud = req.
result->mo_response_cloud = res.
ENDMETHOD.
METHOD get_cdata.
DATA object TYPE REF TO object.
FIELD-SYMBOLS <any> TYPE any.
IF mo_server_onprem IS BOUND.
ASSIGN mo_server_onprem->('REQUEST') TO <any>.
object = <any>.
CALL METHOD object->('GET_CDATA')
RECEIVING
data = result.
ELSE.
CALL METHOD mo_request_cloud->('GET_TEXT')
RECEIVING
r_value = result.
ENDIF.
ENDMETHOD.
METHOD get_method.
DATA object TYPE REF TO object.
FIELD-SYMBOLS <any> TYPE any.
IF mo_server_onprem IS BOUND.
ASSIGN mo_server_onprem->('REQUEST') TO <any>.
object = <any>.
CALL METHOD object->('IF_HTTP_REQUEST~GET_METHOD')
RECEIVING
method = result.
ELSE.
CALL METHOD mo_request_cloud->('GET_METHOD')
RECEIVING
r_value = result.
ENDIF.
ENDMETHOD.
METHOD set_cdata.
DATA object TYPE REF TO object.
FIELD-SYMBOLS <any> TYPE any.
IF mo_server_onprem IS BOUND.
ASSIGN mo_server_onprem->('RESPONSE') TO <any>.
object = <any>.
CALL METHOD object->('SET_CDATA')
EXPORTING
data = val.
ELSE.
CALL METHOD mo_request_cloud->('SET_TEXT')
EXPORTING
r_value = val.
ENDIF.
ENDMETHOD.
METHOD set_status.
DATA object TYPE REF TO object.
FIELD-SYMBOLS <any> TYPE any.
DATA(lv_reason) = CONV string( reason ).
IF mo_server_onprem IS BOUND.
ASSIGN mo_server_onprem->('RESPONSE') TO <any>.
object = <any>.
CALL METHOD object->('IF_HTTP_RESPONSE~SET_STATUS')
EXPORTING
code = code
reason = lv_reason.
ELSE.
CALL METHOD mo_response_cloud->('SET_STATUS')
EXPORTING
i_code = code
i_reason = lv_reason.
ENDIF.
ENDMETHOD.
METHOD set_session_stateful.
IF mo_server_onprem IS BOUND.
CALL METHOD mo_server_onprem->('SET_SESSION_STATEFUL')
EXPORTING
stateful = val.
ELSE.
ASSERT 1 = 'NO_STATEFUL_FEATURE_IN_CLOUD_ERROR'.
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@ -3,14 +3,13 @@
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>Z2UI5_CL_CORE_HTTP_GET</CLSNAME>
<CLSNAME>Z2UI5_CL_ABAP_API_HTTP</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>abap2UI5 - http get handler</DESCRIPT>
<DESCRIPT>http server</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@ -1,188 +0,0 @@
CLASS z2ui5_cl_core_http_get DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
DATA ms_request TYPE z2ui5_if_types=>ty_s_http_request_get.
METHODS constructor
IMPORTING
val TYPE z2ui5_if_types=>ty_s_http_request_get OPTIONAL.
METHODS main
RETURNING
VALUE(result) TYPE string.
METHODS get_js_cc_startup
RETURNING
VALUE(result) TYPE string.
PROTECTED SECTION.
METHODS get_default_config
RETURNING
VALUE(result) TYPE z2ui5_if_types=>ty_s_http_request_get.
METHODS main_get_config
RETURNING
VALUE(result) TYPE z2ui5_if_types=>ty_s_http_request_get.
METHODS main_get_index_html
IMPORTING
cs_config TYPE z2ui5_if_types=>ty_s_http_request_get
RETURNING
VALUE(result) TYPE string.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_core_http_get IMPLEMENTATION.
METHOD constructor.
ms_request = val.
ENDMETHOD.
METHOD get_default_config.
DATA(lv_csp) = `<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"/>`.
result = VALUE #(
t_param = VALUE #(
( n = `TITLE` v = `abap2UI5` )
)
t_config = VALUE #(
* ( n = `src` v = `https://sdk.openui5.org/1.71.67/resources/sap-ui-core.js` )
( n = `src` v = `https://sdk.openui5.org/resources/sap-ui-cachebuster/sap-ui-core.js` )
* ( n = `src` v = `https://sdk.openui5.org/nightly/2/resources/sap-ui-core.js` )
( n = `data-sap-ui-theme` v = `sap_horizon` )
)
content_security_policy = lv_csp ).
ENDMETHOD.
METHOD get_js_cc_startup.
result = ` ` &&
z2ui5_cl_cc_timer=>get_js( ) &&
z2ui5_cl_cc_focus=>get_js( ) &&
z2ui5_cl_cc_title=>get_js( ) &&
z2ui5_cl_cc_lp_title=>get_js( ) &&
z2ui5_cl_cc_history=>get_js( ) &&
z2ui5_cl_cc_scrolling=>get_js( ) &&
z2ui5_cl_cc_info=>get_js( ) &&
z2ui5_cl_cc_geoloc=>get_js( ) &&
z2ui5_cl_cc_file_upl=>get_js( ) &&
z2ui5_cl_cc_multiinput=>get_js( ) &&
z2ui5_cl_cc_uitable=>get_js( ) &&
z2ui5_cl_cc_util=>get_js( ) &&
z2ui5_cl_cc_favicon=>get_js( ) &&
z2ui5_cl_cc_dirty=>get_js( ) &&
* z2ui5_cl_cc_debug_tool=>get_js( ) &&
` `.
ENDMETHOD.
METHOD main_get_config.
result = get_default_config( ).
LOOP AT ms_request-t_param REFERENCE INTO DATA(lr_param).
TRY.
result-t_param[ n = lr_param->n ]-v = lr_param->v.
CATCH cx_root.
INSERT lr_param->* INTO TABLE result-t_param.
ENDTRY.
ENDLOOP.
LOOP AT ms_request-t_config REFERENCE INTO DATA(lr_option).
TRY.
result-t_config[ n = lr_option->n ]-v = lr_option->v.
CATCH cx_root.
INSERT lr_option->* INTO TABLE result-t_config.
ENDTRY.
ENDLOOP.
IF ms_request-content_security_policy IS NOT INITIAL.
result-content_security_policy = ms_request-content_security_policy.
ENDIF.
IF ms_request-custom_js IS NOT INITIAL.
result-custom_js = ms_request-custom_js.
ENDIF.
ENDMETHOD.
METHOD main_get_index_html.
DATA(lv_add_js) = get_js_cc_startup( ) && cs_config-custom_js.
result = `<!DOCTYPE html>` && |\n| &&
`<html lang="en">` && |\n| &&
`<head>` && |\n| &&
cs_config-content_security_policy && |\n| &&
` <meta charset="UTF-8">` && |\n| &&
` <meta name="viewport" content="width=device-width, initial-scale=1.0">` && |\n| &&
` <meta http-equiv="X-UA-Compatible" content="IE=edge">` && |\n| &&
| <title> { cs_config-t_param[ n = 'TITLE' ]-v }</title> \n| &&
| <style> html, body, body > div, #container, #container-uiarea \{\n| &
| height: 100%;\n| &
| \}</style> \n| &&
`<script>` && |\n| &&
` function onInitComponent(){` && |\n| &&
` sap.ui.require.preload({` && |\n| &&
` "z2ui5/manifest.json": '` && NEW z2ui5_cl_core_ui5_app( )->manifest_json( ) && ` ',` && |\n| &&
` "z2ui5/Component.js": function(){` && NEW z2ui5_cl_core_ui5_app( )->component_js( ) && lv_add_js && ` },` && |\n| &&
` "z2ui5/css/style.css": function(){` && NEW z2ui5_cl_core_ui5_app( )->css_style_css( ) && `},` && |\n| &&
` "z2ui5/model/models.js": function(){` && NEW z2ui5_cl_core_ui5_app( )->model_models_js( ) && `},` && |\n| &&
` "z2ui5/i18n/i18n.properties": '` && NEW z2ui5_cl_core_ui5_app( )->i18n_i18n_properties( ) && `' ,` && |\n| &&
` "z2ui5/view/App.view.xml": '` && NEW z2ui5_cl_core_ui5_app( )->view_app_xml( ) && `' ,` && |\n| &&
` "z2ui5/controller/App.controller.js": function(){` && NEW z2ui5_cl_core_ui5_app( )->controller_app_js( ) && `},` && |\n| &&
` "z2ui5/view/View1.view.xml": '` && NEW z2ui5_cl_core_ui5_app( )->view_view1_xml( ) && `' ,` && |\n| &&
` "z2ui5/controller/View1.controller.js": function(){` && NEW z2ui5_cl_core_ui5_app( )->controller_view1_js( ) && `},` && |\n| &&
` "z2ui5/cc/DebugTool.fragment.xml": '` && z2ui5_cl_cc_debug_tool=>get_xml( ) && `' ,` && |\n| &&
` "z2ui5/cc/DebugTool.js": function(){` && z2ui5_cl_cc_debug_tool=>get_js( ) && `},` && |\n| &&
` });` && |\n| &&
` sap.ui.require(["sap/ui/core/ComponentSupport"], function(ComponentSupport){` && |\n| &&
` ComponentSupport.run();` && |\n| &&
` });` && |\n| &&
` }` && |\n| &&
`</script>` && |\n| &&
`<script id="sap-ui-bootstrap" data-sap-ui-resourceroots='{ "z2ui5": "./" }' data-sap-ui-oninit="onInitComponent" ` && |\n| &&
`data-sap-ui-compatVersion="edge" data-sap-ui-async="true" data-sap-ui-frameOptions="trusted" data-sap-ui-bindingSyntax="complex"`.
LOOP AT cs_config-t_config REFERENCE INTO DATA(lr_config).
result = result && | { lr_config->n }='{ lr_config->v }'|.
ENDLOOP.
result = result &&
` ></script></head>` && |\n| &&
`<body class="sapUiBody sapUiSizeCompact" id="content">` && |\n| &&
` <div data-sap-ui-component data-name="z2ui5" data-id="container" data-settings='{"id" : "z2ui5"}' data-handle-validation="true"></div>` && |\n| &&
` </body></html>`.
ENDMETHOD.
METHOD main.
DATA(ls_config) = main_get_config( ).
result = main_get_index_html( ls_config ).
NEW z2ui5_cl_core_draft_srv( )->cleanup( ).
ENDMETHOD.
ENDCLASS.

View File

@ -1,136 +0,0 @@
CLASS ltcl_test_http_get DEFINITION FINAL FOR TESTING
DURATION MEDIUM
RISK LEVEL HARMLESS.
PUBLIC SECTION.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS file_not_initial FOR TESTING RAISING cx_static_check.
METHODS launchpad_compatibility FOR TESTING RAISING cx_static_check.
METHODS js_no_debugger FOR TESTING RAISING cx_static_check.
METHODS js_no_sap_ui_get_core FOR TESTING RAISING cx_static_check.
METHODS js_no_window FOR TESTING RAISING cx_static_check.
METHODS js_no_document FOR TESTING RAISING cx_static_check.
METHODS js_2x_compatibility FOR TESTING RAISING cx_static_check.
METHODS bootstrap_with_open_ui5 FOR TESTING RAISING cx_static_check.
METHODS js_no_jquery FOR TESTING RAISING cx_static_check.
METHODS debugging_tools FOR TESTING RAISING cx_static_check.
ENDCLASS.
CLASS z2ui5_cl_core_http_get DEFINITION LOCAL FRIENDS ltcl_test_http_get.
CLASS ltcl_test_http_get IMPLEMENTATION.
METHOD file_not_initial.
DATA(lo_get) = NEW z2ui5_cl_core_http_get( ).
DATA(lv_index_html) = lo_get->main( ).
IF lv_index_html IS INITIAL.
cl_abap_unit_assert=>fail( 'HTTP GET - index html initial' ).
ENDIF.
ENDMETHOD.
METHOD launchpad_compatibility.
DATA(lo_get) = NEW z2ui5_cl_core_http_get( ).
DATA(lv_index_html) = lo_get->main( ).
IF lv_index_html CS ` && `.
cl_abap_unit_assert=>fail( 'index.html contains the character & -> no launchpad compatibility' ).
ENDIF.
ENDMETHOD.
METHOD js_no_debugger.
DATA(lo_get) = NEW z2ui5_cl_core_http_get( ).
DATA(lv_index_html) = to_upper( lo_get->main( ) ).
IF lv_index_html CS `DEBUGGER`.
cl_abap_unit_assert=>fail( 'debugger command not allowed' ).
ENDIF.
ENDMETHOD.
METHOD js_no_sap_ui_get_core.
DATA(lo_get) = NEW z2ui5_cl_core_http_get( ).
DATA(lv_index_html) = to_upper( lo_get->main( ) ) ##NEEDED.
* IF lv_index_html CS `SAP.UI.GETCORE`.
* cl_abap_unit_assert=>fail( 'sap.ui.get.core not allowed' ).
* ENDIF.
ENDMETHOD.
METHOD js_2x_compatibility.
DATA(lo_get) = NEW z2ui5_cl_core_http_get( ).
DATA(lv_index_html) = to_upper( lo_get->main( ) ) ##NEEDED.
IF lv_index_html CS `SAP.UI.GETVERSIONINFO`.
cl_abap_unit_assert=>fail( 'SAP.UI.GETVERSIONINFO not allowed' ).
ENDIF.
ENDMETHOD.
METHOD js_no_jquery.
DATA(lo_get) = NEW z2ui5_cl_core_http_get( ).
DATA(lv_index_html) = to_upper( lo_get->main( ) ).
IF lv_index_html CS `JQUERY`.
cl_abap_unit_assert=>fail( 'use of jquery not allowed' ).
ENDIF.
ENDMETHOD.
METHOD js_no_window.
DATA(lo_get) = NEW z2ui5_cl_core_http_get( ).
DATA(lv_index_html) = to_upper( lo_get->main( ) ) ##NEEDED.
* IF lv_index_html CS `WINDOW.`.
* cl_abap_unit_assert=>fail( 'use of window not allowed' ).
* ENDIF.
ENDMETHOD.
METHOD js_no_document.
DATA(lo_get) = NEW z2ui5_cl_core_http_get( ).
DATA(lv_index_html) = to_upper( lo_get->main( ) ) ##NEEDED.
* IF lv_index_html CS `DOCUMENT.`.
* cl_abap_unit_assert=>fail( 'use of document not allowed' ).
* ENDIF.
ENDMETHOD.
METHOD bootstrap_with_open_ui5.
DATA(lo_get) = NEW z2ui5_cl_core_http_get( ).
DATA(lv_index_html) = to_upper( lo_get->main( ) ) ##NEEDED.
DATA(lv_check) = xsdbool( lv_index_html CS `HTTPS://SDK.OPENUI5.ORG/RESOURCES` ).
IF lv_check = abap_false.
cl_abap_unit_assert=>fail( 'no bootstrap with openUI5' ).
ENDIF.
lv_check = xsdbool( lv_index_html CS `NIGHTLY` ).
IF lv_check = abap_true.
cl_abap_unit_assert=>fail( 'no bootstrap with nightly version' ).
ENDIF.
ENDMETHOD.
METHOD debugging_tools.
DATA(lv_index_html) = to_upper( z2ui5_cl_cc_debug_tool=>get_js( ) ) ##NEEDED.
IF lv_index_html CS `<`.
cl_abap_unit_assert=>fail( 'use of < not allowed - launchpad compatibility' ).
ENDIF.
IF lv_index_html CS `/>`.
cl_abap_unit_assert=>fail( 'use of /> not allowed - launchpad compatibility' ).
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@ -41,10 +41,71 @@ CLASS z2ui5_cl_core_ui5_app DEFINITION
RETURNING
VALUE(result) TYPE string.
METHODS index_html
IMPORTING
is_config TYPE z2ui5_if_types=>ty_s_http_config
RETURNING
VALUE(result) TYPE string.
ENDCLASS.
CLASS z2ui5_cl_core_ui5_app IMPLEMENTATION.
METHOD index_html.
IF is_config-styles_css IS INITIAL.
DATA(lv_style_css) = NEW z2ui5_cl_core_ui5_app( )->css_style_css( ).
ELSE.
lv_style_css = is_config-styles_css.
ENDIF.
result = `<!DOCTYPE html>` && |\n| &&
`<html lang="en">` && |\n| &&
`<head>` && |\n| &&
is_config-content_security_policy && |\n| &&
` <meta charset="UTF-8">` && |\n| &&
` <meta name="viewport" content="width=device-width, initial-scale=1.0">` && |\n| &&
` <meta http-equiv="X-UA-Compatible" content="IE=edge">` && |\n| &&
| <title> { is_config-title }</title> \n| &&
| <style> html, body, body > div, #container, #container-uiarea \{\n| &
| height: 100%;\n| &
| \}</style> \n| &&
`<script>` && |\n| &&
` function onInitComponent(){` && |\n| &&
` sap.ui.require.preload({` && |\n| &&
` "z2ui5/manifest.json": '` && NEW z2ui5_cl_core_ui5_app( )->manifest_json( ) && ` ',` && |\n| &&
` "z2ui5/Component.js": function(){` && NEW z2ui5_cl_core_ui5_app( )->component_js( ) && is_config-custom_js && ` },` && |\n| &&
` "z2ui5/css/style.css": '` && lv_style_css && `',` && |\n| &&
` "z2ui5/model/models.js": function(){` && NEW z2ui5_cl_core_ui5_app( )->model_models_js( ) && `},` && |\n| &&
` "z2ui5/i18n/i18n.properties": '` && NEW z2ui5_cl_core_ui5_app( )->i18n_i18n_properties( ) && `' ,` && |\n| &&
` "z2ui5/view/App.view.xml": '` && NEW z2ui5_cl_core_ui5_app( )->view_app_xml( ) && `' ,` && |\n| &&
` "z2ui5/controller/App.controller.js": function(){` && NEW z2ui5_cl_core_ui5_app( )->controller_app_js( ) && `},` && |\n| &&
` "z2ui5/view/View1.view.xml": '` && NEW z2ui5_cl_core_ui5_app( )->view_view1_xml( ) && `' ,` && |\n| &&
` "z2ui5/controller/View1.controller.js": function(){` && NEW z2ui5_cl_core_ui5_app( )->controller_view1_js( ) && `},` && |\n| &&
` "z2ui5/cc/DebugTool.fragment.xml": '` && z2ui5_cl_cc_debug_tool=>get_xml( ) && `' ,` && |\n| &&
` "z2ui5/cc/DebugTool.js": function(){` && z2ui5_cl_cc_debug_tool=>get_js( ) && `},` && |\n| &&
` });` && |\n| &&
` sap.ui.require(["sap/ui/core/ComponentSupport"], function(ComponentSupport){` && |\n| &&
` ComponentSupport.run();` && |\n| &&
` });` && |\n| &&
` }` && |\n| &&
`</script>` && |\n| &&
`<script id="sap-ui-bootstrap" data-sap-ui-resourceroots='{ "z2ui5": "./" }' data-sap-ui-oninit="onInitComponent" ` && |\n| &&
`data-sap-ui-compatVersion="edge" data-sap-ui-async="true" data-sap-ui-frameOptions="trusted" data-sap-ui-bindingSyntax="complex"` && |\n| &&
`data-sap-ui-theme="` && is_config-theme && `" src=" ` && is_config-src && `" `.
LOOP AT is_config-t_add_config REFERENCE INTO DATA(lr_config).
result = result && | { lr_config->n }='{ lr_config->v }'|.
ENDLOOP.
result = result &&
` ></script></head>` && |\n| &&
`<body class="sapUiBody sapUiSizeCompact" id="content">` && |\n| &&
` <div data-sap-ui-component data-name="z2ui5" data-id="container" data-settings='{"id" : "z2ui5"}' data-handle-validation="true"></div>` && |\n| &&
` </body></html>`.
ENDMETHOD.
METHOD component_js.
result =

View File

@ -1,36 +1,71 @@
CLASS z2ui5_cl_http_handler DEFINITION
PUBLIC
CREATE PUBLIC.
CREATE PROTECTED.
PUBLIC SECTION.
CLASS-DATA so_sticky_handler TYPE REF TO z2ui5_cl_core_http_post.
CLASS-METHODS main
CLASS-METHODS factory_cloud
IMPORTING
body TYPE string
config TYPE z2ui5_if_types=>ty_s_http_request_get OPTIONAL
EXPORTING
attributes TYPE z2ui5_if_types=>ty_s_http_handler_attributes
req TYPE REF TO object
res TYPE REF TO object
RETURNING
VALUE(result) TYPE string.
VALUE(result) TYPE REF TO z2ui5_cl_http_handler.
CLASS-METHODS http_post
CLASS-METHODS factory
IMPORTING
val TYPE string
EXPORTING
attributes TYPE z2ui5_if_types=>ty_s_http_handler_attributes
server TYPE REF TO object
RETURNING
VALUE(result) TYPE string.
VALUE(result) TYPE REF TO z2ui5_cl_http_handler.
CLASS-METHODS http_get
METHODS main
IMPORTING
val TYPE z2ui5_if_types=>ty_s_http_request_get OPTIONAL
RETURNING
VALUE(result) TYPE string.
s_config TYPE z2ui5_if_types=>ty_s_http_config OPTIONAL.
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_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_config TYPE z2ui5_if_types=>ty_s_http_config.
METHODS get_js_cc_startup
RETURNING
VALUE(result) TYPE string.
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_post.
METHODS session_handling
IMPORTING
attributes TYPE z2ui5_if_types=>ty_s_http_handler_attributes.
PRIVATE SECTION.
ENDCLASS.
@ -38,48 +73,120 @@ 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.
ms_config-custom_js = ms_config-custom_js && get_js_cc_startup( ).
ENDMETHOD.
METHOD get_js_cc_startup.
result = ` ` &&
z2ui5_cl_cc_timer=>get_js( ) &&
z2ui5_cl_cc_focus=>get_js( ) &&
z2ui5_cl_cc_title=>get_js( ) &&
z2ui5_cl_cc_lp_title=>get_js( ) &&
z2ui5_cl_cc_history=>get_js( ) &&
z2ui5_cl_cc_scrolling=>get_js( ) &&
z2ui5_cl_cc_info=>get_js( ) &&
z2ui5_cl_cc_geoloc=>get_js( ) &&
z2ui5_cl_cc_file_upl=>get_js( ) &&
z2ui5_cl_cc_multiinput=>get_js( ) &&
z2ui5_cl_cc_uitable=>get_js( ) &&
z2ui5_cl_cc_util=>get_js( ) &&
z2ui5_cl_cc_favicon=>get_js( ) &&
z2ui5_cl_cc_dirty=>get_js( ) &&
` `.
ENDMETHOD.
METHOD main.
ms_req-body = mo_server->get_cdata( ).
ms_req-method = mo_server->get_method( ).
CASE ms_req-method.
WHEN `GET`.
http_get( s_config ).
WHEN `POST`.
http_post( ).
WHEN `HEAD`.
mo_server->set_session_stateful( 0 ).
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 ).
ENDMETHOD.
METHOD factory.
result = NEW #( ).
result->mo_server = z2ui5_cl_abap_api_http=>factory( server ).
ENDMETHOD.
METHOD factory_cloud.
result = NEW #( ).
result->mo_server = z2ui5_cl_abap_api_http=>factory_cloud(
req = req
res = res ).
ENDMETHOD.
METHOD http_get.
DATA(lo_get) = NEW z2ui5_cl_core_http_get( val ).
result = lo_get->main( ).
set_config( is_custom_config ).
DATA(lo_app) = NEW z2ui5_cl_core_ui5_app( ).
ms_res-body = lo_app->index_html( ms_config ).
NEW z2ui5_cl_core_draft_srv( )->cleanup( ).
ENDMETHOD.
METHOD http_post.
CLEAR attributes.
IF so_sticky_handler IS NOT BOUND.
DATA(lo_post) = NEW z2ui5_cl_core_http_post( val ).
ELSE.
so_sticky_handler = lo_post.
ENDIF.
result = lo_post->main(
IMPORTING
attributes = attributes ).
so_sticky_handler = lo_post.
ENDMETHOD.
METHOD main.
CLEAR attributes.
IF body IS INITIAL.
DATA(lo_get) = NEW z2ui5_cl_core_http_get( config ).
result = lo_get->main( ).
ELSE.
IF so_sticky_handler IS NOT BOUND.
DATA(lo_post) = NEW z2ui5_cl_core_http_post( body ).
DATA(lo_post) = NEW z2ui5_cl_core_http_post( ms_req-body ).
ELSE.
lo_post = so_sticky_handler.
lo_post->mv_request_json = body.
lo_post->mv_request_json = ms_req-body.
ENDIF.
* DATA(lo_post) = NEW z2ui5_cl_core_http_post( body ).
result = lo_post->main(
ms_res-body = lo_post->main(
IMPORTING
attributes = attributes ).
ENDIF.
attributes = ms_session_attributes ).
TRY.
IF lo_post IS BOUND.
@ -89,11 +196,42 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
ELSE.
CLEAR so_sticky_handler.
ENDIF.
ENDIF.
CATCH cx_root.
ENDTRY.
ENDMETHOD.
METHOD session_handling.
"transform cookie to header based contextid handling
IF attributes-stateful-switched = abap_true.
* server->set_session_stateful( stateful = attributes-stateful-active ).
mo_server->set_session_stateful( attributes-stateful-active ).
IF mo_server->get_header_field( 'sap-contextid-accept' ) = 'header'.
* server->response->get_cookie(
* EXPORTING
* name = 'sap-contextid'
* IMPORTING
* value = DATA(lv_contextid) ).
DATA(lv_contextid) = mo_server->get_response_cookie( 'sap-contextid' ).
IF lv_contextid IS NOT INITIAL.
* server->response->delete_cookie( 'sap-contextid' ).
mo_server->delete_response_cookie( 'sap-contextid' ).
* server->response->set_header_field( name = 'sap-contextid' value = lv_contextid ).
mo_server->set_header_field( n = 'sap-contextid' v = lv_contextid ).
ENDIF.
ENDIF.
ELSE.
* lv_contextid = server->request->get_header_field( 'sap-contextid' ).
lv_contextid = mo_server->get_header_field( 'sap-contextid' ).
IF lv_contextid IS NOT INITIAL.
* server->response->set_header_field( name = 'sap-contextid' value = lv_contextid ).
mo_server->set_header_field( n = 'sap-contextid' v = lv_contextid ).
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@ -1,25 +0,0 @@
CLASS ltcl_unit_test DEFINITION FINAL FOR TESTING
DURATION MEDIUM
RISK LEVEL HARMLESS.
PUBLIC SECTION.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS test_get FOR TESTING RAISING cx_static_check.
ENDCLASS.
CLASS ltcl_unit_test IMPLEMENTATION.
METHOD test_get.
DATA(lv_resp) = z2ui5_cl_http_handler=>main( `` ).
IF lv_resp IS INITIAL.
cl_abap_unit_assert=>fail( 'HTTP GET' ).
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@ -5,12 +5,11 @@
<VSEOCLASS>
<CLSNAME>Z2UI5_CL_HTTP_HANDLER</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>abap2UI5 - http handler</DESCRIPT>
<DESCRIPT>abap2UI5 - http get handler</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@ -9,12 +9,15 @@ INTERFACE z2ui5_if_types
TYPES ty_t_name_value TYPE STANDARD TABLE OF ty_s_name_value WITH EMPTY KEY.
TYPES:
BEGIN OF ty_s_http_request_get,
t_config TYPE ty_t_name_value,
BEGIN OF ty_s_http_config,
src TYPE string,
theme TYPE string,
content_security_policy TYPE string,
styles_css TYPE string,
title TYPE string,
t_add_config TYPE ty_t_name_value,
custom_js TYPE string,
t_param TYPE ty_t_name_value,
END OF ty_s_http_request_get.
END OF ty_s_http_config.
TYPES:
BEGIN OF ty_s_http_handler_attributes,