APC - ABAP Push Channels
ABAP push channels (APC) enable bidirectional communication with the Internet for ABAP programs using the WebSocket protocol. Unlike HTTP, the WebSocket protocol, based on TCP, makes push communication possible Under the traditional pull principle, each response of a server requires a preceding client request; under the push principle, however, it is enough to have an open connection between client and server, used by the server to pass information as soon as it becomes available. ABAP push channels can be used to make AS ABAP into a WebSocket server for WebSocket clients. One example of the latter are appropriately programmed Web pages in browsers that support WebSockets.
ABAP push channels are implemented as repository objects to which a service from the service tree in ICF and a APC handler class are associated. To make the WebSocket communication between AS ABAP and the Internet non-dependent on the current application server, ABAP push channels can be associated with ABAP message channels (AMC). Alongside simple character strings and byte strings, SAP's own Push Channel Protocol (PCP) is also available as a format for messages.
7.31 | 7.40 | 7.54
ABAP Push Channels as Repository Objects
An ABAP push channel defined as a repository object must exist for each WebSocket communication. ABAP push channels can be created in Repository Browser in ABAP Workbench by opening the context menu of a package and choosing Connectivity. The Connectivity Browser of the Object Navigator provides another means of access. To open the Object Navigator for APCs, use transaction SAPC.
Each push channel has two further repository objects generated when a push channels is created:
- A node in the service tree of ICF, visible in transaction SICF (the service editor). Like all other ICF services, this node represents the Web address of the push channel. This node can be activated and deactivated in the service editor, but not tested directly. Instead, other systems, such as a Web browser that supports the WebSocket protocol, can use this address to communicate with a push channel.
- An APC handler class saved as a global class in the ABAP Class Library and which can be edited in Class Builder. When the APC framework communicates with a push channel, it creates an instances of the class as an APC handler.
An optional subprotocol of the WebSocket protocol can be assigned to a push channel. Currently, SAP's own Push Channel Protocol (PCP) can be assigned. The generated APC handler class inherits from a different superclass, depending on the protocol used, and includes other interfaces that enable specific access to the protocol.
APC Handler Class
The APC handler class of each ABAP push channel inherits from the superclass
- CL_APC_WSP_EXT_STATELESS_BASE without using a subprotocol
- CL_APC_WSP_EXT_STATELESS_PCP_B when using the Push Channel Protocol (PCP)
Both superclasses contain abstract interface methods ON_START and ON_MESSAGE that can be redefined as application-specific methods:
- In an APC without subprotocol, text messages and binary message content can be read from received message objects and written to message objects waiting to be sent.
- In an APC with Push Channel Protocol (PCP), the content of received messages can be deserialized to ABAP data and ABAP data can be serialized to message objects waiting to be sent.
Further optional interface methods, such as ON_ACCEPT, ON_CLOSE, and ON_ERROR can be implemented to respond to the corresponding events. More particularly, ON_ACCEPT can be used to decide whether a WebSocket connection is opened.
- While a WebSocket message is being handled in an APC handler class, the ABAP program is in a special
context in which certain statements, such as
BREAK-POINT, are handled differently than, say, in dialog processing. External breakpoints can be set to debug programs in this context.
See the APC handler class CL_APC_WS_EXT_DEMO_APC for the ABAP push channel DEMO_APC or CL_APC_WSP_EXT_DEMO_APC_PCP for the ABAP push channel DEMO_APC_PCP.
If no subprotocol is used, there are no special requirements made on a WebSocket client, such as a WebSocket-enabled browser. As a WebSocket server, an AS ABAP can be addressed using text messages and binary messages and with standard techniques.
- The WebSocket client created by the class CL_HTTP_EXT_APC_DEMO uses an ABAP push channel without PCP and does not need a special API.
- The WebSocket client created by the class CL_HTTP_EXT_APC_PCP_DEMO uses an ABAP push channel with PCP and loads and uses the associated API from the MIME repository.
Associating APC with AMC
On its own, the APC framework enables a WebSocket to communicate with precisely one application server. To make communication non-dependent on the current application server, the servers can be associated using ABAP messaging channels. Here, a push channel (during the implementation of its APC handler class with method BIND_AMC_MESSAGE_CONSUMER of interface IF_APC_WS_BINDING_MANAGER of one the relevant generated Binding Managers) can be associated with an AMC consumer for a specific ABAP messaging channel with a suitable message type. Messages sent using this ABAP messaging channel are then handled automatically as APC messages. The APC framework wraps the required methods of the AMC framework. The only prerequisite is that the APC handler class is authorized to bind consumers and to send messages in the messaging channel in question. The association with the AMC consumer can be removed explicitly using the method UNBIND_AMC_MESSAGE_CONSUMER of the binding manager.
- It is not possible to associate APC with AMC during the update process.
- The methods BIND_AMC_MESSAGE_CONSUMER and UNBIND_AMC_MESSAGE_CONSUMER both cause a database commit.
- See WebSocket Communication with APC, where ABAP push channels are demonstrated both with and without PCP.
- Execute DEMO_APC_PING_PONG.
For the ABAP push channel, a virus scan profile can be specified for outbound and inbound messages. This profile is used when the virus scan interface (VSI) runs checks.
As was previously the case, WebSocket messages can only be handled if the WebSocket object is created using a file or website from the same address or domain. In other cases, permitted addresses or domains must be created using transaction SAPC_CROSS_ORIGIN in the table APC_CROSS_ORIGIN. Authorization for the fields of authorization object S_APC_ORIG is required.
Details about APC can be found in the
SAP NetWeaver documentation in SAP Help Portal.