Use the destination service in SAP BTP to store destination information that can be reused by applications deployed in one of the BTP environments.
You can use the destination service. However, this approach is deprecated. We recommend using the communication arrangement approach instead. See HTTP Communication via Communication Arrangements for more information.
You've the following options to consume a destination service:
-
Dynamic by using a communication arrangement and a communication system
-
Static by using the method
create_by_cloud_destination
in the code
When using create_by_cloud_destination
, proceed as follows:
Create a destination object using class cl_http_destination_provider
and method create_by_cloud_destination
with the following parameters:
-
i_name
: the name of the destination -
Optional:
i_service_instance_name
: Typically, you use the destinations of the subaccount in which the ABAP instance resides or, in case of a SaaS solution based on the ABAP environment, the destinations of the consumer subaccount. However, you can add more destinations using your own destination service instance and communication scenarioSAP_COM_0276
, for example, to achieve separation of concerns (see also Create a Destination). In this case, specify the value of the service instance name property of the communication arrangement forSAP_COM_0276
. -
i_authn_mode
: Set the value of this parameter according to the authentication method configured in your destination. If the authentication method uses user propagation, the value isif_a4c_cp_service=>user_propagation
, if it doesn't, setif_a4c_cp_service=>service_specific
:Value
Proxy Type Internet
Proxy Type OnPremise
if_a4c_cp_service=>user_propagation
if_a4c_cp_service=>service_specific
-
No Authentication
-
Basic Authentication
-
No Authentication
-
Basic Authentication
-
Other authentication methods are currently not supported by the SAP BTP, ABAP environment.
The actual processing of an HTTP request and its response is shown in the following code example:
DATA lo_http_destination TYPE REF TO if_http_destination. DATA lo_http_client TYPE REF TO if_web_http_client. DATA lo_http_response TYPE REF TO if_web_http_response. TRY. " create HTTP destination by cloud destination lo_http_destination = cl_http_destination_provider=>create_by_cloud_destination( i_name = 'DestinationName' i_authn_mode = if_a4c_cp_service=>service_specific ). " create HTTP client by HTTP destination lo_http_client = cl_web_http_client_manager=>create_by_http_destination( lo_http_destination ). " adding header fields lo_http_client->get_http_request( )->set_header_fields( VALUE #( ( name = if_web_http_header=>content_type value = if_web_http_header=>accept_application_json ) ( name = if_web_http_header=>accept value = if_web_http_header=>accept_application_json ) ) ). " execute HTTP GET-request and store response lo_http_response = lo_http_client->execute( if_web_http_client=>get ). " print response text to console DATA(ls_status) = lo_http_response->get_status( ). out->write( |Response is: { ls_status-code } { ls_status-reason }.| ). out->write( lo_http_response->get_text( ) ). CATCH cx_http_dest_provider_error cx_web_http_client_error INTO DATA(lx_error). " display error details out->write( lx_error->get_text( ) ). ENDTRY.
To test your outbound call, configure an HTTP destination as described in Create HTTP Destinations
Authentication Methods
- Only the authentication methods listed in table Authentication Methods are available.
- If you're using Client Certificate Authentication as authentication method, activate Use client provided certificate. This flag is only visible if the URL field contains a URL string starting with https://... .
- For proxy type Internet and the use of authentication type client certificate, you must upload the X.509 client certificate in P12 format on the client side in the SAP BTP, ABAP environment using the Maintain Client Certificates application. For more information, see Maintain Client Certificates. Uploading the client certificate via destination service isn't supported.
- The use of
if_a4c_cp_service=>user_propagation
isn't supported in the ADT class runner. It can only be tested when a business user context is available, for example, during processing of OData services or HTTP services.
Related Information