Skip to Content
0
Jun 01 at 04:00 PM

Get Session ID as Token and pass this token to SOAP Header parameter with actual Payload

151 Views Last edit Jun 01 at 04:19 PM 2 rev

Could please me help me on this scenario as below.

Sender is ABAP, Receiver is CPI

before Sending the actual payload, i need to get the session ID by logging into the CPI system, and use the session id to pass in SOAP header with actual payload to POST the data. The code I was using previously was as follows:

  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url                = p_url
      ssl_id             = p_ssl
    IMPORTING
      client             = go_client
    EXCEPTIONS
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      OTHERS             = 4.

lo_ixml = cl_ixml=>create( ).

 lo_logon_req = lo_ixml->create_document( ).

  lo_logon_req->set_declaration( declaration = abap_false ).

  lo_element_envelope = lo_logon_req->create_simple_element(
    name    = 'soapenv:Envelope'
    parent  = lo_logon_req ).

  lo_element_envelope->set_attribute_ns(
    name = 'xmlns:soapenv'
    value = 'http://schemas.xmlsoap.org/soap/envelope/' ).

  lo_element_envelope->set_attribute_ns(
    name = 'xmlns:web'
    value = 'http://webservices.dsod.sap.com/' ).

  lo_element_head = lo_logon_req->create_simple_element(
    name    = 'soapenv:Header'
    parent  =  lo_element_envelope ).

  lo_element_body = lo_logon_req->create_simple_element(
    name    = 'soapenv:Body'
    parent  =  lo_element_envelope ).

  lo_element_action = lo_logon_req->create_simple_element(
    name    = 'web:logonRequest'
    parent  = lo_element_body ).

  lo_logon_req->create_simple_element(
    name    = 'orgName'
    parent  = lo_element_action
    value   = p_orgn ).

  lo_logon_req->create_simple_element(
    name    = 'userName'
    parent  = lo_element_action
    value   = p_uname ).

  lo_logon_req->create_simple_element(
    name    = 'password'
    parent  = lo_element_action
    value   = p_pass ).

  lo_logon_req->create_simple_element(
    name    = 'isProduction'
    parent  = lo_element_action
    value   = p_isprod ).
  "Convert document to xstring
  CALL FUNCTION 'SDIXML_DOM_TO_XML'
    EXPORTING
      document      = i_ref_dom
    IMPORTING
      xml_as_string = lv_xstring
    EXCEPTIONS
      no_document   = 1
      OTHERS        = 2.

  IF sy-subrc <> 0.
    MESSAGE 'Error creating XML string!' TYPE 'E'.
  ENDIF.

  "convert xstring to string
  CALL METHOD cl_abap_conv_in_ce=>create
    EXPORTING
      encoding    = 'UTF-8'
      endian      = 'L'
      ignore_cerr = 'X'
      replacement = '#'
      input       = lv_xstring              " Xstring
    RECEIVING
      conv        = convin.

  CALL METHOD convin->read
    IMPORTING
      data = ev_xml_string.                  " String


The output from the above code was used to login to the CPI system to get the sessionID. Then i used the sessionID in the SOAP header along with the actual payload to POST the data.

The only issue I am facing here is the client doesn't want to expose the username/password. I tried using the method CL_HTTP_CLIENT=>CREATE_BY_DESTINATION so as not to expose the login credentials but i am not sure how to get the sessionID using this method. Please let me know if there is a different way of doing this.

Thank you in advance.