‎2015 Mar 18 7:59 AM
Hi All,
I am consuming Webservices,as part of it i have send the json data as string because it is taking input only in the form of json string but i coun't succeed in in that,i got the response 'the request sent by client is syntactically incorrect'.i have posted my code below .
type-POOLs : abap.
TYPES: BEGIN OF header_wa,
TRANSACTION_SUBTYPE(20) TYPE C ,
DOCUMENT_TYPE(20) TYPE c," AUART,
LINE_ITEM_TYPE TYPE MTART,
TRN_REF_DATE TYPE ERDAT,
ISSUED_FORM(20) TYPE C,
TRN_REF_NO(20) TYPE C,
TRANSACTION_TYPE(20) TYPE C,
PARTY_CODE TYPE KUNWE,
PARTY_SHIPPING_CODE TYPE KUNNR,
DEALER_CODE(20) TYPE C,
JURISDICTION_CODE(20) TYPE C,
END OF header_wa.
DATA: header_tab TYPE header_wa.
TYPES : BEGIN OF ty_lineitem,
ITEM_CODE TYPE MATNR,
QUANTITY TYPE MENGE_D,
CHARGES_BEFORE_EXCISE(20) TYPE C,
DEDUCTIONS_BEFORE_EXCISE(20) TYPE C,
CHARGES_BEFORE_SALES_TAX(20) TYPE C,
DEDUCTION_BEFORE_SALES_TAX(20) TYPE C,
TOTAL_EXCISE(20) TYPE C,
END OF ty_lineitem.
data wa TYPE ty_lineitem.
types : BEGIN OF item_wa,
lineitem TYPE ty_lineitem,
END OF item_wa.
DATA: item_tab TYPE TABLE OF item_wa,
wa_lineitem type ty_lineitem.
*DATA: LO_http_client TYPE REF TO if_http_ENTITY,
DATA : LO_client TYPE REF TO if_http_client,
http_url TYPE string VALUE 'http://70.222.43.119/taxilla/rest/addtax/gettax',
LV_RESULT TYPE xstring,
LV_RESULT1 TYPE string,
* json TYPE string,
code_reason TYPE string ,
http_code TYPE i,
wl_url TYPE string,
http_status_code TYPE i,
status_text TYPE string,
emptybuffer TYPE xstring,
wf_string TYPE string,
vg_return TYPE i,
rlength TYPE string,
rlength2 TYPE i,
soap_action TYPE string.
DATA lv_int TYPE i.
data : binary_tab TYPE TABLE OF c.
DATA lv_json TYPE string.
CONSTANTS : lc_newline(1) TYPE c VALUE cl_abap_char_utilities=>NEWLINE. "New line
CONSTANTS : lc_htab(1) TYPE c VALUE cl_abap_char_utilities=>HORIZONTAL_TAB. "Horizontal Tab
data res_tab TYPE TABLE OF repl_result.
DATA rcnt TYPE i.
data ak(400) TYPE c .
data lv_char TYPE X value '0A'.
DATA : GD_FILENAME TYPE STRING,
GD_PATH TYPE STRING,
GD_FULLPATH TYPE STRING,
GD_RESULT TYPE I.
FIELD-SYMBOLS <wa_upd_tab> TYPE XSEQUENCE.
START-OF-SELECTION.
header_tab-TRANSACTION_SUBTYPE = 'normal'.
header_tab-document_type = 'Tax Invoice'.
header_tab-LINE_ITEM_TYPE = 'good'.
header_tab-trn_ref_date = '12/03/2015'.
header_tab-ISSUED_FORM = ' '.
header_tab-TRN_REF_NO = '10001'.
header_tab-TRANSACTION_TYPE = 'sales'.
header_tab-PARTY_CODE = 'C0001'.
header_tab-party_shipping_code = 'CU0001'.
header_tab-DEALER_CODE = ' '.
header_tab-JURISDICTION_CODE = 'DL'.
WA_lineitem-CHARGES_BEFORE_EXCISE = '100'.
WA_lineitem-DEDUCTIONS_BEFORE_EXCISE = '10'.
WA_lineitem-CHARGES_BEFORE_SALES_TAX = '100'.
WA_lineitem-DEDUCTION_BEFORE_SALES_TAX = '10'.
WA_lineitem-TOTAL_EXCISE = '100'.
WA_lineitem-item_code = 'ITC001'.
WA_lineitem-quantity = '100'.
APPEND wa_lineitem to item_tab.
DATA: xml_result TYPE string.
DATA json_writer TYPE REF TO cl_sxml_string_writer.
DATA writer TYPE REF TO if_sxml_writer.
json_writer = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).
writer ?= json_writer.
writer->set_option( option = if_sxml_writer=>co_opt_linebreaks ).
writer->set_option( option = if_sxml_writer=>co_opt_indent ).
data xml_writer TYPE string.
CALL TRANSFORMATION id
SOURCE header = header_tab
itemdetails = item_tab
organizationId = 'ca50abed4bd9673d014bde754716000f'
locationCode = 'DL'
serviceSpecificationId = 'b1680df1-5bc9-4076-91fa-ab3fa40a9771'
RESULT XML json_writer.
DATA o_json TYPE xstring.
o_json = json_writer->get_output( ).
lv_json = cl_abap_codepage=>convert_from( json_writer->get_output( ) ).
CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
EXPORTING
IM_XSTRING = o_json
IM_ENCODING = 'UTF-8'
IMPORTING
EX_STRING = lv_json
.
l_http_client=>create_by_url(
EXPORTING
url = http_url
IMPORTING
client = lo_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4 ).
*set protocol version
CALL METHOD lo_client->request->set_header_field
EXPORTING
name = '~server_protocol'
value = 'HTTP/1.1'.
*
**content type
CALL METHOD lo_client->request->if_http_entity~set_content_type
EXPORTING
content_type = 'application/json'.
lo_client->request->set_header_field( name = '~request_method'
value = 'POST' ).
CALL METHOD lo_client->request->set_header_field
EXPORTING
name = 'Authorization'
value = 'Bearer a2dd4200-aa6f-4796-87d2-9574de3fbb83'.
*
CALL METHOD lo_client->request->set_header_field
EXPORTING
name = 'Content-Type'
value = 'application/json'.
lv_len = strlen( lv_json ).
CALL METHOD lo_client->request->set_cdata " Removed APPEND_CDATA
EXPORTING
data = lv_json
offset = 0
length = lv_len.
lo_client->send(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2 ).
*Receive the Response Object
lo_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3 ).
CLEAR lv_result1 .
lv_result1 = lo_client->response->get_Cdata( ).
write lv_result1.
Please help me how to proceed.Thanks in advance.
Regards,
Anil.
‎2015 Mar 19 2:43 AM
Hi Anil,
I looked at the json string generated and it is syntactically correct, so it must be something else, ie some missing/wrong header? Or maybe although the json is valid, it's not exactly what the service requires. do you have a sample json from the service provider to compare with the one you generated?
Cheers,
Custodio
‎2015 Mar 19 6:14 AM
Hi Custodio,
Thanks for quick reply.
I have attached Json input of the service provider.please review it and guide me how to proceed.
Json Input:
{
"header":{
"transaction_subtype":"Normal",
"document_type":"Tax Invoice",
"line_item_type":"Good",
"trn_ref_date":"19112014",
"issued_form":"",
"trn_ref_no":"10001",
"transaction_type":"Sales",
"party_code":"BBELC001",
"party_shipping_code":"DL001",
"dealer_code":"",
"jurisdiction_code":"DL"
},
"lineItemDetails":[
{
"lineItem":{
"item_code":"ITC001",
"quantity":"100",
"charges_before_excise":"100",
"deductions_before_excise":"10",
"charges_before_sales_tax":"100",
"deduction_before_sales_tax":"10",
"total_excise":"100"
}
}
],
"organizationId":"ca50c7304998c1a50149999248c50011",
"locationCode":"DL",
"serviceSpecificationId":"a0b8921c-4e35-4e24-a087-0bab5c22517c"
}
Thanks,
Anil.
‎2015 Mar 19 7:46 AM
Hi Custodio,
So far i haven't used IF_HTTP_ENTITY~ADD_MULTIPART( ) method .
Do we need to use this method as part of consuming REST based Web services which takes input in the form of JSON . I simply sent data to IF_HTTP_ENTITY~SET_CDATA,but it is showing that 'the request sent by client is syntactically incorrect'.
Do i need to call any method like multipart-form data as part of sending json data to webservice.
I never worked on this so far .
Please guide me how to proceed.
‎2015 Mar 19 6:12 AM
Hi Custodio,
Thanks for quick reply.
I have attached Json input of the service provider.please review it and guide me how to proceed.
Json Input:
{
"header":{
"transaction_subtype":"Normal",
"document_type":"Tax Invoice",
"line_item_type":"Good",
"trn_ref_date":"19112014",
"issued_form":"",
"trn_ref_no":"10001",
"transaction_type":"Sales",
"party_code":"BBELC001",
"party_shipping_code":"DL001",
"dealer_code":"",
"jurisdiction_code":"DL"
},
"lineItemDetails":[
{
"lineItem":{
"item_code":"ITC001",
"quantity":"100",
"charges_before_excise":"100",
"deductions_before_excise":"10",
"charges_before_sales_tax":"100",
"deduction_before_sales_tax":"10",
"total_excise":"100"
}
}
],
"organizationId":"ca50c7304998c1a50149999248c50011",
"locationCode":"DL",
"serviceSpecificationId":"a0b8921c-4e35-4e24-a087-0bab5c22517c"
}
Thanks,
Anil.
‎2015 Apr 04 4:40 PM
‎2015 Apr 07 1:29 AM