method IF_HTTP_EXTENSION~HANDLE_REQUEST . type-pools ABAP. data: s_yaml type string, begin of nl, nl type x value '0A', end of nl, xnl, yaml type standard table of tab512, rfc type tfdir-funcname, rest type string, t_params_p type standard table of RFC_FINT_P, params_p like line of t_params_p, parm type string, val type string, paramtab type ABAP_FUNC_PARMBIND_TAB, paramline like line of paramtab, exceptab type ABAP_FUNC_EXCPBIND_TAB, exceptline like line of exceptab, waref type ref to data, dataname type string, verb type string, excnt type i, waline type tab512, len type i. field-symbols: type any, type any, type standard table. * macro so that I dont have to declare another private method define add_parm. case params_p-paramclass. when 'I' or 'E'. paramline-name = params_p-parameter. if params_p-paramclass = 'E'. paramline-kind = ABAP_FUNC_IMPORTING. else. paramline-kind = ABAP_FUNC_EXPORTING. endif. if params_p-fieldname is initial. dataname = params_p-tabname. else. concatenate params_p-tabname params_p-fieldname into dataname separated by '-'. endif. create data waref type (dataname). assign waref->* to . len = strlen( val ). if val = 'SPACE'. = space. elseif len > 3 and val+0(3) = 'SY-'. assign (val) to . = . unassign . else. = val. endif. unassign . paramline-value = waref. insert paramline into table paramtab. when 'T'. paramline-name = params_p-parameter. paramline-kind = ABAP_FUNC_TABLES. create data waref type standard table of (params_p-tabname). paramline-value = waref. insert paramline into table paramtab. when 'X'. exceptline-name = params_p-parameter. exceptline-value = excnt. insert exceptline into table exceptab. excnt = excnt + 1. when others. call method server->response->set_status( code = '400' reason = 'Application error - unknown parm type' ). exit. endcase. end-of-definition. * silly thing you have to do in ABAP .... write nl+0(1) to xnl+0. * from DJ verb = server->request->get_header_field( name = '~request_method' ). if verb <> 'POST'. call method server->response->set_status( code = '405' reason = 'Method not allowed' ). exit. endif. * get the RFC rfc = server->request->get_header_field( name = '~path_info' ). shift rfc left by 1 places. * do we have the rfc name? call function 'RFC_GET_FUNCTION_INTERFACE_P' exporting funcname = rfc language = sy-langu tables params_p = t_params_p exceptions fu_not_found = 1 nametab_fault = 2 others = 3. if sy-subrc <> 0. call method server->response->set_status( code = '404' reason = 'Transport not found' ). exit. endif. * break out the lines refresh yaml. s_yaml = server->request->get_cdata( ). split s_yaml at xnl into table yaml. * exception counter excnt = 1. * parse each line loop at yaml into waline. * discard blank lines if waline is initial. continue. endif. * discard new document lines if waline+0(3) = '---'. refresh: paramtab, exceptab. continue. endif. * process table lines if waline+0(3) = ' -'. shift waline left by 4 places. assign paramline-value->* to . append waline to . unassign . continue. endif. * process each new parameter if waline cs ': '. split waline at ':' into parm val. * check the parameter exists clear params_p. loop at t_params_p into params_p where parameter = parm. exit. endloop. if sy-subrc = 4. call method server->response->set_status( code = '400' reason = 'Application error - parm name' ). exit. endif. if val is not initial. shift val left by 1 places. endif. add_parm. continue. else. * no idea what yaml this is call method server->response->set_status( code = '400' reason = 'Application error - no parm' ). exit. endif. endloop. * did we get a duff parameter? if params_p-parameter <> parm. exit. endif. * add in missing parameters with defaults loop at t_params_p into params_p. loop at paramtab into paramline. if paramline-name = params_p-parameter. exit. endif. endloop. if paramline-name = params_p-parameter. continue. endif. val = params_p-default. add_parm. endloop. * add in the catch all exception exceptline-name = 'OTHERS'. exceptline-value = excnt. insert exceptline into table exceptab. * do the actual RFC call call function rfc parameter-table paramtab exception-table exceptab. * remove unused exceptions delete exceptab where not value = sy-subrc. * serialise the call results clear s_yaml. refresh yaml. waline = '--- #YAML:1.0'. append waline to yaml. * give back the parameter values loop at paramtab into paramline. waline = paramline-name. if paramline-kind = ABAP_FUNC_TABLES. concatenate waline ':' into waline. append waline to yaml. assign paramline-value->* to . loop at into waline. * swap the string delimiter around depending whats inside if waline cs ''''. concatenate ' - "' waline '"' into waline. else. concatenate ' - ''' waline '''' into waline. endif. append waline to yaml. endloop. elseif paramline-kind = ABAP_FUNC_IMPORTING. concatenate waline ':' into waline. assign paramline-value->* to . concatenate waline into waline separated by' '. append waline to yaml. endif. endloop. * add in the exception if there was one loop at exceptab into exceptline. waline = 'EXCEPTION:'. append waline to yaml. concatenate ' - name:' exceptline-name into waline separated by space. append waline to yaml. write exceptline-value to exceptline-name left-justified. concatenate ' - value:' exceptline-name into waline separated by space. append waline to yaml. endloop. * join up all the lines, and add a final one loop at yaml into waline. concatenate s_yaml waline into s_yaml separated by xnl. endloop. concatenate s_yaml xnl into s_yaml. * set the response headers, and payload call method server->response->set_header_field( name = 'Content-Type' value = 'text/plain; charset=iso-8859-1' ). call method server->response->set_cdata( data = s_yaml ). * endmethod. *