Hello Experts,
I am trying to consume an OData service in my on premise ERP system inside BTP ABAP environment program using service consumption model.
When I execute the below URL in my SAP gateway client along with HTTP Request header as "accept=application/json", I get the output in JSON format as expected.
http://<host>:8010/sap/opu/odata/sap/ZDEMO_FLIGHT_CDS/ZDEMO_FLIGHT?$top=3
But when I want to achieve the same output using the program below,
TRY.
DATA(http_destination) = cl_http_destination_provider=>create_by_cloud_destination(
i_name = 'DF1'
* i_service_instance_name =
i_authn_mode = if_a4c_cp_service=>service_specific
).
http_client = cl_web_http_client_manager=>create_by_http_destination( i_destination = http_destination ).
CATCH cx_http_dest_provider_error.
"handle exception
CATCH cx_web_http_client_error.
ENDTRY.
odata_client_proxy = cl_web_odata_client_factory=>create_v2_remote_proxy(
EXPORTING
iv_service_definition_name = 'Z_DF1_DEMO_FLIGHT_CDS'
io_http_client = http_client
iv_relative_service_root = '/sap/opu/odata/sap/ZDEMO_FLIGHT_CDS/' ).
" Navigate to the resource and create a request for the read operation
read_list_request = odata_client_proxy->create_resource_for_entity_set( 'ZDEMO_FLIGHT' )->create_request_for_read( ).
read_list_request->set_top( 3 ).
" Execute the request and retrieve the business data
read_list_response = read_list_request->execute( ).
read_list_response->get_business_data( IMPORTING et_business_data = business_data ).
out->write( business_data ).
I am getting runtime error which says the HTTP response format is "text/html; charset=utf-8". Since the Gateway program /IWBEP/CL_CP_SRV_PROXY_REMOTE->set_response_of_action( ) expects the response as JSON, the runtime error is raised.
IF NOT /iwbep/cl_cp_odata_facade=>is_content_type_app_json( lv_http_response_format ). RAISE EXCEPTION NEW /iwbep/cx_cp_remote( textid = /iwbep/cx_cp_remote=>t_wrong_response_format content_type = lv_http_response_format ). ENDIF.
Can you please suggest what is the root cause and how to fix the issue.
Thanks,
Mainak