Pushing Notifications Made Easy!!! : How to Subscribe?
The ‘What’ part – “Notifications”, you must be familiar with this word if you have used iPhones/BlackBerry or any other smartphones and even Facebook!!! Excited to see the notifications from your friends and family!!! How cool would it be to receive notifications regarding SAP Business Processes in your daily office work? Managers, wouldn’t it be cool to get an employee’s leave request on your mobile instead of getting it in the mail client in your laptop? It must be great to do some office activities from the mobile while having no access to your machine, e.g. in the departmental store, in the shopping mall, etc.
So the next question, how do we do it?? You know, it’s really easy and cool!!! Just follow a few steps mentioned below and you’ll be done in no time. Well, that’s not absolutely true!!! It’ll take some time, but not much. 🙂
Before we start, let’s have a quick introduction of the SAP NetWeaver Gateway Subscription & Notification framework.
Basic fact —– Subscribe to get Notified !!!
It’s important to understand that Subscription & Notification are two different functions in Gateway. The below picture shows the difference in a nutshell.
It exactly works like subscribing for a newsletter. Once you subscribe for it, you receive it. Similarly, in case of a Gateway service, you have to subscribe to a Collection in order to get notified about the Business Process. But that’s not the whole story. We’ll see what else needs to be done in the steps to come. Stay tuned!!!
Sample Use Case —— SAP User Administration
Let’s understand the use case in brief. In an organization, an Admin user wants to keep track of all the new SAP usernames being created/changed/deleted in a system. He doesn’t want to login to the system everyday and check for any new users. Instead, he wants to get notified the moment a user is created/changed/deleted.
He thinks it would be great for him to get these alerts in his iPhone. So, he asks for an application which will connect to the Gateway system and get this information to his mobile device. Now, let’s see what needs to be done in the Gateway system in order to get this working for the Admin.
The development activities for this scenario have been split into two steps:
- Creating a Subscription-Enabled OData Service (Steps covered in this blog)
- Enabling Notification Push for the subscribed users (Watch out for this in the next blog)
Creating a Subscription-Enabled OData Service
Step 1 — Creating Model & Data Provider classes
Let’s create a new OData Service for the above mentioned business scenario, which will be enabled for subscription.
- Create a class Z_CL_PUSHDEMO_MPC by inheriting from /IWBEP/CL_MGW_PUSH_ABS_MODEL.
- Redefine the method DEFINE in this class and create your OData service interface. The sample code can be found here.
- Create another class Z_CL_PUSHDEMO_DPC by inheriting from /IWBEP/CL_MGW_PUSH_ABS_DATA.
- Redefine the method CHECK_SUBSCRIPTION_AUTHORITY and write some code to check if the requesting user is authorized to subscribe to this service. You can find some sample code here. Please note that if you get any authorization error later while running a query on UserCollection, comment this code.
- Redefine the method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET and write some code to get a list of users. The sample code can be found here.
- Redefine the method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITY and write some code to get details for a user. The sample code can be found here.
Step 2 — Configuring the OData Service
Once the above steps are completed, maintain the model & service group in the IMG path shown below:
In the Gateway Hub system, activate the above service as shown below.
Activate the service ZPUSHDEMOSRV by clicking on it.
The OData service is now ready to be used for Query & Read operations. 🙂 The table below gives the URLs for various operations supported.
The service document (see below) shows that the ‘UserCollection’ is made subscribable and also you can see two new entities added to the service document (SubscriptionCollection and NotificationCollection).
Now, once you are done with the above steps, you can start with subscribing for a Collection. Nothing much to do here, just a regular HTTP POST as shown below. The sample request body can be found here.
Please note that we will be using a HTTP listener application for receiving the notifications. Hence, the deliveryAddress used while subscribing should be the IP address from the application.
Once you have fired the call, the response is a subscription for this service as shown below.
With this, you have become one of the subscribers for the ‘ZPUSHDEMOSRV‘ SAP NetWeaver Gateway service. Let’s see what else needs to be done for receiving notifications in the next blog – Create a Notification Push Application!