Intro
We got a requirement to create a web application that displays a table component, which should be refreshed after a specific DBTAB is modified (filtered to relevant keys only).
I made a research and concluded that in order to inform the client SSE (Server Side Event) would fit most.
Problem
I implemented a simple POC in ABAP. However, whenever the server is responding - a connection opens, the client receives the response (header & body), but then the connection immediately closes.
What I tried
Request from our basis team to upgrade out
GWto the latest (SAP S/4HANA 2020withSAP_GWFND755).Search Google and SAP KB for
SSE,Server Side Eventetc. Nothing found.Creation of an
SICFnode underdefault_hostnamedSSE_POC.Definition of a single handler
ZCL_CA_SSE_POC.implementation of interface
IF_HTTP_EXTENSIONin classZCL_CA_SSE_POC.ABAPcode:DATA: lo_http_server_net TYPE REF TO cl_http_server_net. lo_response TYPE REF TO cl_http_response. lo_http_server_net ?= server. lo_response ?= lo_http_server_net->response. lo_response->set_header_field( name = 'Content-Type' value = 'text/event-stream' ). lo_response->set_header_field( name = 'Cache-Control' value = 'no-cache' ). " just as a workaround lo_response->set_header_field( name = 'Connection' value = 'keep-alive' ). " just as a workaround lo_response->set_cdata( data = 'event: event\ndata:1\n\n' ).
Debugging
After calling my code, standard code (HTTP_DISPATCH_REQUEST:1726) reaches send_response method of server object.
Inside it, it reaches:
system-call plugin
id 'HTTP' value 'sendAndReturn'
id 'name' value conn_name
id 'Stateful' value stateful
id 'LogonTime' value m_authentication_time
id 'LogonMethod' value authentication_method
id 'AuthorizationTime' value m_authorization_time
id 'ExecutionTime' value m_exe_time
id 'EventHandlerExist' value l_eventhandler_exists
id 'MessageOut' value c_msg
id 'RC' value rc.
After running system-call - the client says an SSE connection opened and immediately closed.
Client code:
const evtSource = new EventSource("http://<server>/sse_poc?sap-client=<mandt>");
evtSource.onmessage = ev => console.log(ev);
evtSource.onopen = _ => console.log("Connection Opened");
evtSource.onerror = ev => console.log(`error${ev.eventPhase === EventSource.CLOSED ? `: "Connection Closed"` : ''}`);
Chrome console:
Connection Opened
Error: "Connection Closed"
Connection Opened
Error: "Connection Closed"
... <every 3 seconds new pair>
Chrome network tab

Postman
Notes
Our system is on-premise.