Skip to content

Latest commit

 

History

History
187 lines (103 loc) · 8.61 KB

http-communication-via-destination-service-deprecated-43a5ebe.md

File metadata and controls

187 lines (103 loc) · 8.61 KB

HTTP Communication via Destination Service (Deprecated)

Use the destination service in SAP BTP to store destination information that can be reused by applications deployed in one of the BTP environments.

Note:

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:

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:

Sample Code:

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

Destination Service