Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
method DISPATCH.
data:
l_script type string
, lt_meth_parm type abap_parmbind_tab
, lt_resp_parm type abap_parmbind_tab
, lt_meth_excp type abap_excpbind_tab
, ls_parm type abap_parmbind
, lo_excp type ref to cx_sy_dyn_call_error
, l_excptext type string
, lo_handler type ref to object
.
method = server->request->get_header_field( '~request_method' ).
* Work around issue with urlsuffix losing trailing slash
path = server->request->get_header_field( '~request_uri' ).
l_script = server->request->get_header_field( '~script_name' ).
replace first occurrence of l_script in path with ''.
call method derive_handler
exporting path = path
importing class = handlerclass
matches = matches
.
* For receiving response on GET_RESPONSE call
ls_parm-name = 'RESPONSE'.
ls_parm-kind = cl_abap_objectdescr=>receiving.
get reference of server->response into ls_parm-value.
insert ls_parm into table lt_resp_parm.
* For supplying matches on method call
ls_parm-name = 'MATCHES'.
ls_parm-kind = cl_abap_objectdescr=>exporting.
get reference of matches into ls_parm-value.
insert ls_parm into table lt_meth_parm.
* Instantiate handler object
try.
create object lo_handler type (handlerclass)
exporting server = server.
catch cx_sy_create_object_error.
server->response->set_status( code = '404' reason = 'NOT FOUND (NO CLASS)' ).
exit.
endtry.
* Call handler method (GET, POST, etc)
try.
call method lo_handler->(method)
parameter-table lt_meth_parm
exception-table lt_meth_excp.
* Retrieve response
call method lo_handler->(GET_RESPONSE)
parameter-table lt_resp_parm.
catch cx_sy_dyn_call_illegal_method.
* XXX Need to send 'Allow' header with this
server->response->set_status( code = '405' reason = 'NOT IMPLEMENTED' ).
exit.
catch cx_sy_dyn_call_error into lo_excp.
l_excptext = lo_excp->get_text( ).
server->response->set_status( code = '500' reason = l_excptext ).
exit.
endtry.
endmethod.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment