且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SAP BSP应用有状态和无状态行为差异比较

更新时间:2022-09-05 23:22:26

In previous blog Fiori and CRM WebClient UI – Stateless and Stateful, but how? I have researched how stateful and stateless BSP application are handled in ABAP server side. In this blog I will explain how stateful and stateless BSP application behave differently.


The test BSP application I am using

SAP BSP应用有状态和无状态行为差异比较

It consists of three files.

first.json

SAP BSP应用有状态和无状态行为差异比较

Here I use WAIT keyword to simulate that it will take 3 seconds for the first request to finish.


index.html

In this html file, I fire two requests to fetch “first.json” and “second.json” one by one. The first request is sent before second request.

SAP BSP应用有状态和无状态行为差异比较

second.json

SAP BSP应用有状态和无状态行为差异比较

The application is firstly set as Stateful:

SAP BSP应用有状态和无状态行为差异比较

Stateful test

(1) Launch index.html, and in Chrome development tool you can see there are three “set-cookie” in Response Header fields.

SAP BSP应用有状态和无状态行为差异比较

One of them, the sap-contextid is set in method ON_REQUEST_LEAVE of CL_BSP_RUNTIME explained in previous blog.

SAP BSP应用有状态和无状态行为差异比较

And you can observe the cookie in tab “Application”:

SAP BSP应用有状态和无状态行为差异比较

The cookie could also be reviewed in Chrome via Settings

->Advanced Settings->Privacy->Content Settings->All cookies and site data… SAP BSP应用有状态和无状态行为差异比较

(2) click button “Fire two request”, and in console we can observe that these two requests are handled sequentially in server: the response of first request still comes first before the response of second request.

SAP BSP应用有状态和无状态行为差异比较

This could also be confirmed in the Network tab. The first request takes totally 3 seconds to finish. During the wait of this 3 seconds, the process of second request is pending till the first request finishes. As a result finally both request takes around 3 seconds to get handled.


SAP BSP应用有状态和无状态行为差异比较

We can also observe that the cookie set by index.html load is now automatically appended as the request header for “first.json” and “second.json” request:


SAP BSP应用有状态和无状态行为差异比较

Stateless test

Now set application as stateless and open index.html again:

SAP BSP应用有状态和无状态行为差异比较

Compare the cookie with stateful test, this time the cookie

sap-contextid is not there. This observation is consistent with what I found in blog Fiori and CRM WebClient UI – Stateless and Stateful, but how?, as it will only be set in stateful application.

SAP BSP应用有状态和无状态行为差异比较

Click fire button, and we can find in stateless application, these two requests are handled by server in parallel: the response of second request is now coming first before the response of first request.


SAP BSP应用有状态和无状态行为差异比较

In Network tab, once fire button is clicked, the second request gets processed almost immediately, and the first request still has status “Pending”.

SAP BSP应用有状态和无状态行为差异比较

After 3 seconds the first request is done, total duration is around 3 seconds:

SAP BSP应用有状态和无状态行为差异比较

In Stateless application, it is clearly observed that cookie field

sap-contextid is not involved in the request & response handling.

SAP BSP应用有状态和无状态行为差异比较

SAP BSP应用有状态和无状态行为差异比较