Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
vfweiss
Participant

A few months ago we had to implement Push notifications for a SAPUI5 hybrid app. Back then the Kapsel side was well documented already by daniel.vanleeuwen in: Getting Started with Kapsel - Part 4 -- Push (SP09+)

However the Backend side was a bit less documented.

There are two roads to follow to get Push notifications working from the backend. One is by leveraging registration ids and logging those in the backend.

This way is thankfully now well described as well in the following document series: How To... Implement End-to-End Push Notifications with HCPms and SAP Gateway by kenichi.unnai.

But there is also extended functionality in the Rest Notification API to send notifications to specific user(names) for specific apps as described for the mobile side in the blog post by Daniel van Leeuwen and in the SMP help documents here: Push Notification API Scenarios - REST API Application Development - SAP Library

We followed the latter route as that scenario was the one preferred for our scenario and the documentation and implementation for the first was a bit scattered around and not on the level it is now.

To implement the username based scenario we wrote a bit of ABAP leveraging the HTTP_CLIENT on the Backend to send a HTTP post call to the SMP server in case a specific object was created for that user.

Ofcourse this is the basic scenario if all your servers are reachable for each other. In case you use HCPms you might have to extend it, as your Backend server probably can't talk to the outside like this.

The basic ABAP code we used looks like this, you still have to change it so the URL is more dynamic.


DATA: SURL        TYPE STRING,


       HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT,


       RLENGTH     TYPE I,


       JSONSTRING  TYPE STRING.




SURL = 'http://<server uri>:<server http port>/restnotification/application/<appname>/user/<username>'.




JSONSTRING = '{"alert": "<alert text>","badge" : <badge number if used>,"data": "<data>","sound": "default"}'.




RLENGTH = STRLEN( JSONSTRING ).




CL_HTTP_CLIENT=>CREATE_BY_URL( EXPORTING URL    = SURL


IMPORTING CLIENT = HTTP_CLIENT ).




CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD


EXPORTING


     NAME  = 'Content-Type'


VALUE = 'application/JSON; charset=utf-8'.




CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD


EXPORTING


     NAME  = 'Authorization'


VALUE = '<authorization of smppush user (Basic .... for example)>'.



CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD


EXPORTING


     NAME  = '~request_method'


VALUE = 'POST'.




CALL METHOD HTTP_CLIENT->REQUEST->SET_CDATA


EXPORTING


DATA   = JSONSTRING


     OFFSET = 0


     LENGTH = RLENGTH.




HTTP_CLIENT->SEND( ).


HTTP_CLIENT->RECEIVE( ).


HTTP_CLIENT->RESPONSE->GET_STATUS( IMPORTING CODE = RLENGTH ).


JSONSTRING = HTTP_CLIENT->RESPONSE->GET_CDATA( ).


HTTP_CLIENT->CLOSE( ).




Something to consider when using this:

- Username is case sensitive. Either make sure that the user name is always the same case on SMP server as on the call from the Backend

or use SMP3 runtime SP10 where you can make it case insensitive.

7 Comments
Labels in this area