100% found this document useful (1 vote)
6 views

ztestproxy2_eg2_auth

Uploaded by

Swarnali Basu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
6 views

ztestproxy2_eg2_auth

Uploaded by

Swarnali Basu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

*&---------------------------------------------------------------------*

*& Report ztestproxy2_eg2_auth


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ztestproxy2_eg2_auth.

************************************************************************

DATA: http_client TYPE REF TO if_http_client,


l_body TYPE string.

DATA: 1_1(8) TYPE c VALUE '10662984',


1_2(2) TYPE c VALUE '22',
l_3(6) TYPE c VALUE 'Fluent'.

************************************************************************

* Structures:

DATA: w_http_error_descr TYPE string,

w_http_error_descr_long TYPE xstring.

DATA: w_http_return_code TYPE i.

************************************************************************

* Variables:

DATA: w_url TYPE string,

w_xml_result_str TYPE string.

DATA: l_xml_result_xstr TYPE xstring.

************************************************************************

*
DATA: p_url LIKE w_url.
DATA: lv_uri TYPE string.
DATA: lv_service_url TYPE string,
lv_url TYPE string,
lv_service_url1 TYPE string,
lo_http_client TYPE REF TO if_http_client,
lo_rest_client TYPE REF TO cl_rest_http_client,
lo_response TYPE REF TO if_rest_entity,
lv_http_status TYPE i,
lv_result TYPE string,
reason TYPE string,
l_url TYPE string,
l_url1 TYPE string,
l_token TYPE string,
lv_token TYPE string.

DATA: lr_object TYPE REF TO ztestsbco_asbtoken_soap,


"ztestsbco_asbtoken_soap,

input TYPE ztestsbget_access_token_soap_i,


output TYPE ztestsbget_access_token_soap_o.

START-OF-SELECTION.
*******code 1

lv_service_url =
'https://asbqa.azurewebsites.net/api/ASBToken/GetAccessToken'.
.
** GET CSRF token
cl_http_client=>create_by_url(
EXPORTING url = lv_service_url " oData service URL
IMPORTING client = lo_http_client
EXCEPTIONS OTHERS = 1 ).
CHECK sy-subrc EQ 0.
lo_http_client->request->set_content_type( 'application/json' ).
CREATE OBJECT lo_rest_client
EXPORTING
io_http_client = lo_http_client.

* body

input-service_bus_name = 'IArcade'.
input-saskey_value = 'cI1A9fzAvMaHAmQKMhCPTDJw1IEwraujCfl39e/cGmA='.
input-processrrfulfilmentforsaphana = 'processteammemberupdatesqueue'.
l_body = | \{ | &&
| "ServiceBusName":"{ input-service_bus_name }", | &&
| "SASKeyValue":"{ input-saskey_value }", | &&
| "processrrfulfilmentforsaphana":"{ input-
processrrfulfilmentforsaphana }" | &&
| \} |.
CALL METHOD lo_http_client->request->set_cdata
EXPORTING
data = l_body.

* fetching token
lo_rest_client->if_rest_client~set_request_header( EXPORTING iv_name =
'X-CSRF-Token' iv_value = 'Fetch' ).

lo_http_client->propertytype_accept_cookie =
if_http_client=>co_enabled.
lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
*****
CALL METHOD lo_http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.

CALL METHOD lo_http_client->receive


EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
IF sy-subrc <> 0.
MESSAGE e000(oo) WITH 'Processing failed !'.
ENDIF.
DATA: wf_string1 TYPE string.
wf_string1 = lo_http_client->response->get_cdata( ).
REPLACE ALL OCCURRENCES OF '"' IN wf_string1 WITH ''.
lv_token = wf_string1.

FREE lo_http_client.

WRITE: / 'HTTP_STATUS_CODE = ',


w_http_return_code,
/ 'STATUS_TEXT = ',
w_http_error_descr,
/ 'TOKEN =',
lv_token
.

WRITE: / 'result = ',


lv_result.

**code 2 for POST


*****
* step 4:- fill headers and body for http post method

p_url =
'https://IArcade.servicebus.windows.net/processteammemberupdatesqueue/
messages?timeout=60'.

*code for destimaton

cl_http_client=>create_by_url(
EXPORTING url = p_url " oData service URL
IMPORTING client = lo_http_client
EXCEPTIONS OTHERS = 1 ).

CALL METHOD lo_http_client->request->set_header_field


EXPORTING
name = 'Authorization'
value = lv_token.

****body for post


CLEAR l_body.

*
* l_url =
'http://xmlns.lntinfotech.com/UNIFYEnterpriseDataModelLibrary/Enterprise/
HR/Employee/ImmigrationLanguageMaster'.
* l_url1 = 'http://schemas.xmlsoap.org/soap/envelope/'.
*l_data = '10662984'.
l_body = | \{ | &&
| "ServiceHeader" : " " , | &&
| "ImmigrationLanguageData" : \{ | &&
| "LanguageDetails" : \{ | &&
| "EMPID":"{ 1_1 }" , | &&
| "LANGUAGE_CODE" : " { 1_2 } " , | &&
| "READ" : " { l_3 } " , | &&
| "WRITE" : " { l_3 }" ,| &&
| "SPEAK" : "{ l_3 }" | &&
| \} | &&
| \} | &&
| \} |.

CALL METHOD lo_http_client->request->set_cdata


EXPORTING
data = l_body.
* update the HTTP Method

CALL METHOD lo_http_client->request->set_method


EXPORTING
method = lo_http_client->request->co_request_method_post.
****content TYPE

CALL METHOD lo_http_client->request->set_content_type


EXPORTING
content_type = 'application/json'. "'application/atom+xml'. "

lo_http_client->propertytype_accept_cookie =
if_http_client=>co_enabled.
lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.

lo_http_client->send(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2 ). "send the http request

lo_http_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3 ). "receive the response

CLEAR: w_http_return_code,w_http_error_descr.
lo_http_client->response->get_status( IMPORTING code =
w_http_return_code ).
lo_http_client->response->get_status( IMPORTING reason =
w_http_error_descr ).
CLEAR lv_result.
lv_result = lo_http_client->response->get_cdata( ).
FREE lo_http_client.

WRITE: / 'HTTP_STATUS_CODE_FOR_POST = ',


w_http_return_code,
/ 'STATUS_TEXT_FOR_POST = ',
w_http_error_descr
.

WRITE: / 'result = ',


lv_result.
* /'Body =', l_body.

END-OF-SELECTION.

You might also like