René van Mil

Parse.com Push and SAP ABAP

Parse Push is a service which allows you to send push notifications to iOS, Android and Windows devices. An easy to use REST API is provided, which allows you to send push notifications from an SAP system to devices running your app. The REST API is especially useful when compared to the Apple Push Notification Service. APNS uses a streaming TCP socket which is not supported by SAP ABAP.

In this blog post I will describe how to configure SAP to use the Parse Push service, and will provide an example ABAP program which will send a push notification.

Setup Parse Push

Create an account and follow the instructions provided by Parse. Everything is really well documented, so you should be up and running quickly.

Create a test app

Create an app and implement the Parse SDK. Make sure you are able to receive test notifications sent from the Parse dashboard.

Configure SAP

Step 1 - STRUST

To allow SAP to perform HTTPS requests, the SSL Client (Anonymous) must be created. Run transaction STRUST and if the anonymous SSL client PSE is not listed yet, simply create a new one.

Since SAP does not come with preinstalled root certificates, the root certificates used by Parse must be manually installed.

  • You can download the certificates from DigiCert. Download both the DigiCert High Assurance EV Root CA and the DigiCert High Assurance CA-3.
  • Run transaction STRUST and select the anonymous SSL client PSE
  • Select the menu Certificate > Import and select the downloaded certificate file
  • After importing the certificate details should appear in the lower part of the screen. Click the Add to certificate list button, and repeat for the second certificate file

When you’re done with this step, the STRUST transaction should more or less look like this:

Notice that both DigiCert certificates are listed.

Step 2 - SM59

An RFC destination allows you to easily access the Parse Push REST API from your ABAP code. Create a destination with the following settings:

  • Name: PARSEPUSH
  • Connection Type: G
  • Target host: api.parse.com
  • Service No.: blank
  • Path Prefix: /1/push
  • SSL: Active
  • SSL Certificate: ANONYM

Technical Settings:

Logon Security:

Example ABAP Program

Below is an example of a simple ABAP program which sends an “abap test” push notification to iOS devices. It uses the SAP cl_http_client class to execute the HTTPS request for sending a push notification.

Make sure you use the correct application id and REST API key. You can find these on the Parse dashboard under your app’s settings > application keys.

Example program to send a push notification with Parse.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
report zparsepush.

data: client type ref to if_http_client,
      success type abap_bool.

" Create HTTP client
call method cl_http_client=>create_by_destination
  exporting
    destination        = 'PARSEPUSH'
  importing
    client             = client
  exceptions
    argument_not_found = 1
    plugin_not_active  = 2
    internal_error     = 3
    others             = 4.
if sy-subrc = 0.

  " Setup HTTP request
  client->request->set_method( 'POST' ).
  client->request->set_content_type( 'application/json' ).
  client->request->set_header_field( name = 'X-Parse-Application-Id' value = 'your_application_id_see_parse_dashboard' ).
  client->request->set_header_field( name = 'X-Parse-REST-API-Key' value = 'your_rest_api_key_see_parse_dashboard' ).
  client->request->set_cdata( '{ "where": { "deviceType": "ios" }, "data": { "alert": "abap test", "badge": 0, "sound": "" } }' ).

  " Send request
  call method client->send
    exceptions
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      http_invalid_timeout       = 4
      others                     = 5.
  if sy-subrc = 0.

    " Receive response
    call method client->receive
      exceptions
        http_communication_failure = 1
        http_invalid_state         = 2
        http_processing_failed     = 3
        others                     = 4.
    if sy-subrc = 0.

      " Read response
      data status_code type i.
      client->response->get_status( importing code = status_code ).
      if status_code = '200'.
        success = abap_true.
      endif.

    endif.

    " Close connection
    call method client->close
      exceptions
        http_invalid_state = 1
        others             = 2.

  endif.

endif.

if success = abap_true.
  write: 'Notification sent!'.
else.
  write: 'Something went wrong :('.
endif.

Comments

Real Time Web Analytics