Hi to all,
What I would like to share in this blog is how we are going to create an app using Sencha Touch 2 that is able to perform device registration automatically in the SAP Mobile Platform.
What You Need
These are the components that you need in order to execute the app:
Setting Up Application ID in SAP Mobile Platform
ID | com.FD.Demo |
Name | com.FD.Demo |
Vendor | FD |
Description | FD Demo |
EndPoint | http://sapes1.sapdevcenter.com:8080/sap/opu/odata/iwbep/gwdemo/ |
Connect to | Internet |
Rewrite URL | Checked |
Allow anonymous connection | Checked |
Username | Username (for example: P1940517116) |
Password | password |
You can use any OData services available from SAP OData backend service that you have registered. I am using the CountryCollection to get the country description: http://sapes1.sapdevcenter.com:8080/sap/opu/odata/iwbep/gwdemo/CountryCollection
Security Profile Name | com_FD_demo |
Authentication Type | Basic Authentication |
Authentication URL | http://sapes1.sapdevcenter.com:8080/sap/opu/odata/iwbep/gwdemo/ |
Connect to | Internet |
Test the SAP Mobile Platform Connection
To test the setting that we have done it in the above steps, please go to the Application page, select the application ID that we have created, com.FD.Demo and click Ping. If successful, you will see the green checked icon status for both Backend and Security profiles.
Setting up Sencha Touch
Don't worry about writing the codes, you can download the source code from the Github site: https://github.com/ferrygun/SenchaSMP3.0.
You can create a new app in Sencha working folder by typing:
sencha -sdk "<path_to_ SDK touch-2.3.1>” generate app -name <Name_of_App> -path "<path_to_App>"
For example, if you want to create the Sencha app named with FD4 and SDK folder is in C:\touch-2.3.1 and your Sencha working folder is in C:\SenchaTouch\FD4, then you can type the following command in the command-prompt:
sencha -sdk "C:\touch-2.3.1" generate app -name FD4 -path "C:\SenchaTouch\FD4"
In this app, a user will enter the country code to get the description of the country code. The country code entered by the user will be passed to OData service:
http://sapes1.sapdevcenter.com:8080/sap/opu/odata/iwbep/gwdemo/CountryCollection('<country_code>’)
If the country code exist, it will print the country code description in another page.
In order to access the data from SMP, firstly we need to register the device in the SMP. Below simple workflow describes the logic to connect to the application ID. This process will be executed every time the app is loaded. Please put this under controller init function: /app/controller/note.js > init.function().
Ext.Ajax.request({
url: '<apache_web_server>/sapgw/com.FD.demo'
headers: {
"Content-Type" : "application/atom+xml; charset=UTF-8",
"Authorization" : 'Basic UDE5NDA1MTcxMTY6UGFwYW1hbWExOA=='
},
method: 'GET',
withCredentials: true,
useDefaultXhrHeader: false,
disableCaching: false
The Authorization value above is the result of the base64.encode of your username and password in the SAP OData backend service. The above code is calling the application ID com.FD.Demo that we have defined in the SMP and perform the GET request.
Content-Type | application/atom+xml; charset=UTF-8 |
Authorization | Basic UDE5NDA1MTcxMTY6UGFwYW1hbWExOA== |
XML Body | <?xml version="1.0" encoding="utf-8"?> |
if(response.statusText == 'Not Found' || response.statusText == 'Forbidden' ) {
if(Ext.os.is.iPad) {
devtype = 'iPad'
} else if(Ext.os.is.iPhone) {
devtype = 'iPhone'
} else if(Ext.os.is.iPod) {
devtype = 'iPod'
} else if(Ext.os.is.iOS) {
devtype = 'iOS'
} else if(Ext.os.is.MacOS) {
devtype = 'iOS'
} else if(Ext.os.is.Android) {
devtype = 'Android'
} else if(Ext.os.is.BlackBerry) {
devtype = 'BlackBerry'
} else if(Ext.os.is.Windows) {
devtype = 'Windows'
} else if(Ext.os.is.Other) {
devtype = 'Unknown'
}
var regXML = '<?xml version="1.0" encoding="utf-8"?>' +
'<entry xmlns="://www.w3.org/2005/Atom" xmlns:m="://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="://schemas.microsoft.com/ado/2007/08/dataservices">' +
'<content type="application/xml">' +
'<m:properties>' +
'<d:DeviceType>' + devtype + '</d:DeviceType>' +
'</m:properties>' +
'</content>' +
'</entry>'
Ext.Ajax.request({
url: '//<apache_web_server>/sapgw/odata/applications/latest/com.FD.Demo/Connections',
headers: {
"Content-Type" : "application/atom+xml; charset=UTF-8",
"Authorization" : 'Basic UDE5NDA1MTcxMTY6UGFwYW1hbWExOA=='
},
method: 'POST',
withCredentials: true,
useDefaultXhrHeader: false,
xmlData: regXML,
disableCaching: false
Hopefully the above blog will benefit you to gain insight and experience in using the SAP Mobile Platform. Off course you also can put the log-on page before the app checks the connection ID to enforce the security.
Thanks for reading my blog and feel free to drop me any comments.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |