Integrating JSession in a Web-Service in SAP

Integrating JSession in a SAP web service requires proper configuration of the SOAP manager transaction to maintain session state across HTTP calls.

Configuring SOAP Manager Transaction

You need to configure the soap manager transaction with the following steps −

  • First, specify the proxy that you have created in the configuration
  • Specify the port number for the web service endpoint
  • Set the access path from transport settings to define the URL pattern

Using cl_http_client for Session Management

The SAP system makes use of cl_http_client class which has a method create_by_destination to make an HTTP call. You can extend that to induce your session logic there.

Example Implementation

Here's how you can implement JSession integration in your SAP web service −

DATA: lo_http_client TYPE REF TO if_http_client,
      lv_destination TYPE string VALUE 'MY_DESTINATION',
      lv_jsessionid TYPE string.

" Create HTTP client by destination
CALL METHOD cl_http_client=>create_by_destination
  EXPORTING
    destination = lv_destination
  IMPORTING
    client      = lo_http_client.

" Set session ID in cookie
IF lv_jsessionid IS NOT INITIAL.
  lo_http_client->request->set_cookie(
    name  = 'JSESSIONID'
    value = lv_jsessionid ).
ENDIF.

" Send request and maintain session
lo_http_client->send( ).
lo_http_client->receive( ).

" Extract session ID from response for future calls
lv_jsessionid = lo_http_client->response->get_cookie( 'JSESSIONID' ).

This approach ensures that the JSession is properly maintained across multiple web service calls, allowing for stateful communication between your SAP system and external web services.

Updated on: 2026-03-13T20:45:42+05:30

187 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements