method IF_HTTP_EXTENSION~HANDLE_REQUEST.
DATA:
lv_verb TYPE string
.
lv_verb = SERVER->REQUEST->GET_HEADER_FIELD( name = '~request_method' ).
CHECK lv_verb = 'GET'.
SERVER->RESPONSE->SET_STATUS( code = 200 reason = 'Ok' ).
SERVER->RESPONSE->SET_CDATA( data = 'Hello Stefan' ).
endmethod.
#-Begin-----------------------------------------------------------------
#-Sub Main------------------------------------------------------------
Function Main() {
$User = "BCUSER";
$Password = "minisap";
$Pair = $User + ":" + $Password;
$encodedCreds = [System.Convert]::ToBase64String(`
[System.Text.Encoding]::ASCII.GetBytes($Pair));
$basicAuthValue = "Basic " + $encodedCreds;
$header = New-Object `
"System.Collections.Generic.Dictionary[[String],[String]]";
$header.Add("cache-control", "no-cache");
$header.Add("authorization", $basicAuthValue);
$header.Add("accept", "*/*");
$header.Add("accept-encoding", "gzip, deflate");
$RequstURI = "http://abap:8000/stefan";
Try {
$Result = Invoke-WebRequest -Uri $RequstURI -Method Get `
-Headers $header -ErrorVariable RestError;
} Catch {
} Finally {
If ($Result.StatusCode -eq 200) {
Write-Host $Result.Content;
} Else {
Write-Host $RestError;
}
}
}
#-Main----------------------------------------------------------------
Main;
#-End-------------------------------------------------------------------
METHOD IF_HTTP_EXTENSION~HANDLE_REQUEST.
TYPES: BEGIN OF ts_record,
key TYPE string,
value TYPE string,
END OF ts_record.
DATA:
lv_verb TYPE string,
lv_input TYPE string,
lt_input TYPE STANDARD TABLE OF ts_record,
ls_input TYPE ts_record,
lv_name TYPE string,
lv_output TYPE string
.
lv_verb = SERVER->REQUEST->GET_HEADER_FIELD( name = '~request_method' ).
CHECK lv_verb = 'GET'.
lv_input = SERVER->REQUEST->GET_HEADER_FIELD( name = 'input' ).
/ui2/cl_json=>deserialize(
EXPORTING
json = lv_input
CHANGING
data = lt_input
).
LOOP AT lt_input INTO ls_input.
CASE ls_input-key.
WHEN 'name'.
lv_name = ls_input-value.
ENDCASE.
ENDLOOP.
lv_output = `Hello ` && lv_name.
SERVER->RESPONSE->SET_STATUS( code = 200 reason = 'Ok' ).
SERVER->RESPONSE->SET_CDATA( data = lv_output ).
ENDMETHOD.
#-Begin-----------------------------------------------------------------
#-Sub Main------------------------------------------------------------
Function Main() {
$User = "BCUSER";
$Password = "minisap";
$Pair = $User + ":" + $Password;
$encodedCreds = [System.Convert]::ToBase64String(`
[System.Text.Encoding]::ASCII.GetBytes($Pair));
$basicAuthValue = "Basic " + $encodedCreds;
$header = New-Object `
"System.Collections.Generic.Dictionary[[String],[String]]";
$header.Add("cache-control", "no-cache");
$header.Add("authorization", $basicAuthValue);
$header.Add("accept", "*/*");
$header.Add("accept-encoding", "gzip, deflate");
$JSON = '[{"key":"name","value":"Stefan"}]';
$header.Add("input", $JSON);
$RequstURI = "http://abap:8000/stefan?sap-client=001";
Try {
$Result = Invoke-WebRequest -Uri $RequstURI -Method Get `
-Headers $header -ErrorVariable RestError;
} Catch {
} Finally {
If ($Result.StatusCode -eq 200) {
Write-Host $Result.Content;
} Else {
Write-Host $RestError;
}
}
}
#-Main----------------------------------------------------------------
Main;
#-End-------------------------------------------------------------------
CLASS Z_STEFAN DEFINITION
PUBLIC
CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES IF_HTTP_EXTENSION.
METHODS get_data
IMPORTING
VALUE(iv_input) TYPE string
RETURNING
VALUE(rv_output) TYPE string.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS Z_STEFAN IMPLEMENTATION.
* <SIGNATURE>----------------------------------------------------------+
* | Instance Public Method Z_STEFAN->IF_HTTP_EXTENSION~HANDLE_REQUEST
* +--------------------------------------------------------------------+
* | [--->] SERVER TYPE REF TO IF_HTTP_SERVER
* +---------------------------------------------------------</SIGNATURE>
METHOD IF_HTTP_EXTENSION~HANDLE_REQUEST.
DATA:
lv_verb TYPE string,
lv_output TYPE string
.
lv_verb = SERVER->REQUEST->GET_HEADER_FIELD( name = '~request_method' ).
CHECK lv_verb = 'GET'.
lv_output = me->get_data(
iv_input = SERVER->REQUEST->GET_HEADER_FIELD( name = 'input' )
).
SERVER->RESPONSE->SET_STATUS( code = 200 reason = 'Ok' ).
SERVER->RESPONSE->SET_CDATA( data = lv_output ).
ENDMETHOD.
* <SIGNATURE>----------------------------------------------------------+
* | Instance Public Method Z_STEFAN->GET_DATA
* +--------------------------------------------------------------------+
* | [--->] IV_INPUT TYPE STRING
* | [<-()] RV_OUTPUT TYPE STRING
* +---------------------------------------------------------</SIGNATURE>
METHOD get_data.
TYPES: BEGIN OF ts_record,
key TYPE string,
value TYPE string,
END OF ts_record.
DATA:
lt_input TYPE STANDARD TABLE OF ts_record,
ls_input TYPE ts_record,
lv_name TYPE string
.
/ui2/cl_json=>deserialize(
EXPORTING
json = iv_input
CHANGING
data = lt_input
).
LOOP AT lt_input INTO ls_input.
CASE ls_input-key.
WHEN 'name'.
lv_name = ls_input-value.
ENDCASE.
ENDLOOP.
rv_output = `Hello ` && lv_name.
ENDMETHOD.
ENDCLASS.
METHOD IF_HTTP_EXTENSION~HANDLE_REQUEST.
DATA:
lv_verb TYPE string,
lv_length TYPE i,
lt_bin TYPE STANDARD TABLE OF solisti1,
lv_output TYPE string,
lv_data TYPE xstring,
lv_input TYPE string
.
lv_verb = SERVER->REQUEST->GET_HEADER_FIELD( name = '~request_method' ).
CHECK lv_verb = 'POST'.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = SERVER->request->get_data( )
IMPORTING
output_length = lv_length
TABLES
binary_tab = lt_bin.
CALL FUNCTION 'SCMS_BINARY_TO_STRING'
EXPORTING
input_length = lv_length
IMPORTING
text_buffer = lv_input
TABLES
binary_tab = lt_bin.
lv_output = me->get_data(
iv_input = lv_input
).
SERVER->RESPONSE->SET_STATUS( code = 200 reason = 'Ok' ).
SERVER->RESPONSE->SET_CDATA( data = lv_output ).
ENDMETHOD.
#-Begin-----------------------------------------------------------------
#-Sub Main------------------------------------------------------------
Function Main() {
$User = "BCUSER";
$Password = "minisap";
$Pair = $User + ":" + $Password;
$encodedCreds = [System.Convert]::ToBase64String(`
[System.Text.Encoding]::ASCII.GetBytes($Pair));
$basicAuthValue = "Basic " + $encodedCreds;
$header = New-Object `
"System.Collections.Generic.Dictionary[[String],[String]]";
$header.Add("cache-control", "no-cache");
$header.Add("authorization", $basicAuthValue);
$header.Add("accept", "*/*");
$header.Add("accept-encoding", "gzip, deflate");
$header.Add("content-type" , "application/json; charset=utf-8");
$JSON = '[{"key":"name","value":"Rüdiger"}]';
$RequstURI = "http://abap:8000/stefan?sap-client=001";
Try {
$Result = Invoke-WebRequest -Uri $RequstURI -Method Post `
-Headers $header -Body $JSON -ErrorVariable RestError;
} Catch {
} Finally {
If ($Result.StatusCode -eq 200) {
Write-Host $Result.Content;
} Else {
Write-Host $RestError;
}
}
}
#-Main----------------------------------------------------------------
Main;
#-End-------------------------------------------------------------------
CLASS Z_STEFAN DEFINITION
PUBLIC
CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES IF_HTTP_EXTENSION.
METHODS get_data
IMPORTING
VALUE(iv_input) TYPE string
RETURNING
VALUE(rv_output) TYPE string.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS Z_STEFAN IMPLEMENTATION.
* <SIGNATURE>----------------------------------------------------------+
* | Instance Public Method Z_STEFAN->GET_DATA
* +--------------------------------------------------------------------+
* | [--->] IV_INPUT TYPE STRING
* | [<-()] RV_OUTPUT TYPE STRING
* +---------------------------------------------------------</SIGNATURE>
METHOD get_data.
TYPES: BEGIN OF ts_record,
key TYPE string,
value TYPE string,
END OF ts_record.
FIELD-SYMBOLS:
<lt_table> TYPE STANDARD TABLE
.
DATA:
lt_input TYPE STANDARD TABLE OF ts_record,
ls_input TYPE ts_record,
lv_name TYPE string,
lo_table TYPE REF TO data
.
/ui2/cl_json=>deserialize(
EXPORTING
json = iv_input
CHANGING
data = lt_input
).
LOOP AT lt_input INTO ls_input.
CASE ls_input-key.
WHEN 'name'.
lv_name = ls_input-value.
ENDCASE.
ENDLOOP.
CREATE DATA lo_table TYPE TABLE OF (lv_name).
ASSIGN lo_table->* TO <lt_table>.
SELECT * INTO TABLE <lt_table> FROM (lv_name).
rv_output = /ui2/cl_json=>serialize( data = <lt_table> ).
ENDMETHOD.
* <SIGNATURE>----------------------------------------------------------+
* | Instance Public Method Z_STEFAN->IF_HTTP_EXTENSION~HANDLE_REQUEST
* +--------------------------------------------------------------------+
* | [--->] SERVER TYPE REF TO IF_HTTP_SERVER
* +---------------------------------------------------------</SIGNATURE>
METHOD IF_HTTP_EXTENSION~HANDLE_REQUEST.
DATA:
lv_verb TYPE string,
lv_length TYPE i,
lt_bin TYPE STANDARD TABLE OF solisti1,
lv_output TYPE string,
lv_data TYPE xstring,
lv_input TYPE string
.
lv_verb = SERVER->REQUEST->GET_HEADER_FIELD( name = '~request_method' ).
CHECK lv_verb = 'POST'.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = SERVER->request->get_data( )
IMPORTING
output_length = lv_length
TABLES
binary_tab = lt_bin.
CALL FUNCTION 'SCMS_BINARY_TO_STRING'
EXPORTING
input_length = lv_length
IMPORTING
text_buffer = lv_input
TABLES
binary_tab = lt_bin.
lv_output = me->get_data(
iv_input = lv_input
).
SERVER->RESPONSE->SET_STATUS( code = 200 reason = 'Ok' ).
SERVER->RESPONSE->SET_CDATA( data = lv_output ).
ENDMETHOD.
ENDCLASS.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |