Quantcast
Channel: SCN : Blog List - ABAP Connectivity
Viewing all articles
Browse latest Browse all 68

ABAP Push / Messaging Channel and SAPUI5 Demo Application

$
0
0

Based on the Blog series published by Masoud Aghadavoodi Jolfaei:

 

ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels

ABAP Channels Part 2: Publish/Subscribe Messaging Using ABAP Messaging Channels

ABAP Channels Part 3: Collaboration Scenario Using ABAP Messaging and ABAP Push Channels

Specification of the Push Channel Protocol (PCP)

 

I've created an SAPUI5 Demo application using the ABAP Push Channel (APC, WebSockets) and ABAP Messaging Channel (AMC). To benefit from the WebSocket technology in your browser please check the support matrix at https://en.wikipedia.org/wiki/WebSocket#Browser_implementation. At the ABAP Backend I've used a NetWeaver ABAP Application Server 7.40 SP8.

 

ABAP Push Channel

 

Let's define the ABAP Push Channel first. Check out the above mentioned Blog's for details:

APC-ZAMC_ECHO.PNG

 

Here's the source code of the class Implementation:

 

CLASS zcl_apc_wsp_ext_zapc_echo DEFINITION  PUBLIC  INHERITING FROM cl_apc_wsp_ext_stateless_pcp_b  FINAL  CREATE PUBLIC .  PUBLIC SECTION.    METHODS if_apc_wsp_ext_pcp~on_message         REDEFINITION .    METHODS if_apc_wsp_ext_pcp~on_start         REDEFINITION .  PROTECTED SECTION.  PRIVATE SECTION.    CLASS-METHODS prepare_message_for_ui      IMPORTING        !iv_text       TYPE string      RETURNING        VALUE(rv_text) TYPE string .
ENDCLASS.
CLASS zcl_apc_wsp_ext_zapc_echo IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_APC_WSP_EXT_ZAPC_ECHO->IF_APC_WSP_EXT_PCP~ON_MESSAGE
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_MESSAGE                      TYPE REF TO IF_AC_MESSAGE_TYPE_PCP
* | [--->] I_MESSAGE_MANAGER              TYPE REF TO IF_APC_WSP_MESSAGE_MANAGER_PCP
* | [--->] I_CONTEXT                      TYPE REF TO IF_APC_WSP_SERVER_CONTEXT
* +--------------------------------------------------------------------------------------</SIGNATURE>  METHOD if_apc_wsp_ext_pcp~on_message.    DATA: lo_producer TYPE REF TO cl_amc_message_type_pcp.    TRY.
* retrieve the text message        DATA(lv_text) = i_message->get_text( ).        lo_producer ?= cl_amc_channel_manager=>create_message_producer(          i_application_id = 'ZAMC_ECHO'          i_channel_id     = '/echo' ).        lv_text = prepare_message_for_ui( lv_text ).        DATA(lo_msg) = cl_ac_message_type_pcp=>create( ).        lo_msg->set_text( i_message = lv_text ).        lo_producer->send( i_message = lo_msg ).      CATCH cx_ac_message_type_pcp_error INTO DATA(lx_pcp_error).        MESSAGE lx_pcp_error->get_text( ) TYPE 'E'.      CATCH cx_amc_error INTO DATA(lx_amc_error).        MESSAGE lx_amc_error->get_text( ) TYPE 'E'.      CATCH cx_apc_error INTO DATA(lx_apc_error).        MESSAGE lx_apc_error->get_text( ) TYPE 'E'.    ENDTRY.  ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_APC_WSP_EXT_ZAPC_ECHO->IF_APC_WSP_EXT_PCP~ON_START
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_CONTEXT                      TYPE REF TO IF_APC_WSP_SERVER_CONTEXT
* | [--->] I_MESSAGE_MANAGER              TYPE REF TO IF_APC_WSP_MESSAGE_MANAGER_PCP
* +--------------------------------------------------------------------------------------</SIGNATURE>  METHOD if_apc_wsp_ext_pcp~on_start.    TRY.
* bind the WebSocket connection to the AMC channel        DATA(lo_binding) = i_context->get_binding_manager( ).        lo_binding->bind_amc_message_consumer(          i_application_id = 'ZAMC_ECHO'          i_channel_id     = '/echo' ).      CATCH cx_apc_error INTO DATA(lx_apc_error).        DATA(lv_message) = lx_apc_error->get_text( ).        MESSAGE lx_apc_error->get_text( ) TYPE 'E'.    ENDTRY.  ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Private Method ZCL_APC_WSP_EXT_ZAPC_ECHO=>PREPARE_MESSAGE_FOR_UI
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_TEXT                        TYPE        STRING
* | [<-()] RV_TEXT                        TYPE        STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>  METHOD prepare_message_for_ui.    TYPES: BEGIN OF t_message,             text TYPE string,             user TYPE uname,             date TYPE timestamp,           END OF t_message.    DATA: ls_message TYPE t_message.    ls_message-text = iv_text.    ls_message-user = sy-uname.    GET TIME STAMP FIELD ls_message-date.    DATA(lo_json_witer) = cl_sxml_string_writer=>create(                            type = if_sxml=>co_xt_json                          ).    CALL TRANSFORMATION id SOURCE ls_message = ls_message                        RESULT XML lo_json_witer.    DATA(lv_xstr) = lo_json_witer->get_output( ).    CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'      EXPORTING        im_xstring = lv_xstr
*       im_encoding = 'UTF-8'      IMPORTING        ex_string  = rv_text.  ENDMETHOD.
ENDCLASS.

 

ABAP Messaging Channel

 

For the ABAP Messaging Channel it is important to define the Authorized Programs:

AMC-ZAMC_ECHO.PNG

 

HCP Git to GitHub

 

This is just to document how to bring an app developed in SAP Web IDE from the HCP Trial Git repository to GitHub. I've used the following steps adopted from the documentation:

 

Adding an existing project to GitHub using the command line - User Documentation


First of all clone the HCP Git repository to the local system and switch to the new folder:

 

git clone https://<HCP Username>@git.hanatrial.ondemand.com/<HCP Accountname>/<HCP GIT Repository Name>
cd apcecho/

Now create a new repository on GitHub and add this repository. I've named it "github":

 

git remote add github https://github.com/gregorwolf/apcecho.git

As I've created some files (Readme, License) in the GitHub Repository this files have to be pulled from the repository:

 

git pull github

And merged with the master:

 

git merge github/master

Then push the changes to both repositories:

 

git push github master
git push origin master

 

 

SAPUI5 Frontend

 

I've used the SAPUI5 Application Template in SAP Web IDE to bootstrap my app. You can get the source at:


gregorwolf/apcecho


You can use the Project SAPUI5-Deployer by Graham Robinson to import this Git repository directly into your ABAP stack.


That's for the moment. Looking forward for your feedback.


Viewing all articles
Browse latest Browse all 68

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>