Skip to Content
SAP Mobile Platform

SUP REST API Application Development for Windows mobiles

Tags:

Sybase Unwired Platform 2.2.x – REST API Application Development

Author              : Ravikumar K (I057038)

Company          : SAP Labs India Pvt Ltd

This document provides information on development of applications using Sybase Unwired Platform (SUP) 2.2.x version. SUP provides feature called ODP (Odata Proxy) using which developers can build applications based on REST methodology.

The Sybase Unwired Platform REST Services API enables standard HTTP client applications running in any platform to access Sybase Unwired Platform REST services.

Unwired Server provides REST services so that applications can be built as any standard HTTP application to leverage Unwired Server for security and push features among others.

More Information:

http://infocenter.sybase.com/help/index.jsp àSybase Unwired Platform 2.2 SP03 à Developer Guide: REST API Applications 2.2 SP03.

Prerequisites:

·         SUP 2.2.x server is installed

·         SUP 2.2.x SDK installed and client SDKs are available. Client SDKs are valid for IOS & Android development.

·         SAP Netweaver Gateway service is ready.

SCC Configuration:

·         Creation of Security Configuration

·         Registration (by creating an application connection)

ü  Security Configuration:

1.       Login to Sybase control center (SCC) and navigate to Security node in the left panel.

2.       Select General tab and click New

3.       Click OK. Now a new security configuration with name “Mirnah“ got created. By default all the modes like Authentication, Authorization.. will be in NoSecLoginModule.

4.       These modes can be changed by adding a New provider.

More information : http://infocenter.sybase.com/help/index.jsp à Sybase Unwired Platform 2.1 ESD #3 à Developer Guide: Unwired Server Management API 2.1 ESD #3 à Client Metadata à Security Configuration

ü  Application Connection:

1.       Select Applications in SCC left panel.

2.       Open Applications tab and click on New button.

3.       Enter Application ID (SCC accepts fully qualified name as application id Ex: com.sap.mirnah). Select Security Configuration, check Configure additional settingsand click on Next.

4.       In the additional settings, goto Proxy and in the Application Endpoint enter SAP Gateway URL and click on Finish.

Ex: http://<Gatewayservermachine>:<port>/sap/opu/odata/sap/<SERVICEDOCNAME>/

Important:

Successful creation of Application will generate a proxy connection entry with same name as application. Navigate to Domains à default àConnections to view the connection pool name of type Proxy. Using this connections SCC communicates with SAP Netweaver gateway server. Check properties of connection to verify gateway url configuration.

This completes configuration in SCC.

Client Side Development:

·         Device Registration

·         Application Connection ID storage

·         Loading Collections (Entity sets)

ü  Device Registration:

1.       Registration of a device has to be done from client device/emulator.

---------------------------------------

Device Registration Code

---------------------------------------

//URL to register device

url = "http://<SUPServermachine>:8000/odata/applications/v1/<ApplicatinID>/

Connections";

// Create a new HttpWebRequest object.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

request.ContentType = "application/atom+xml";

request.Accept = "application/xml,application/atom+xml";

//Credentials of gateway server

request.Credentials = new NetworkCredential("<GatewayUser>", "<GatewayPassword>");

//Security Configuration created

request.Headers.Add("X-SUP-SC", "mirnah");

request.AllowWriteStreamBuffering = true;           

// Set the Method property to 'POST' to post data to the URI.

request.Method = "POST";

Stream postStream = request.GetRequestStream();

//Post Data input, in which device details will be provided

string postData = "<?xml version='1.0' encoding='utf-8'?>" +

                          "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:d='http://schemas.microsoft.com/ado/2007/08/dataservices' xmlns:m='http://schemas.microsoft.com/ado/2007/08/dataservices/metadata'>"+

                          "<title type='text' />" +

                          "<author><name/></author>"+

                          "<category term='applications.Connection' scheme='http://schemas.microsoft.com/ado/2007/08/dataservices/scheme' />" +

                          "<content type='application/xml'>"+

                          "<m:properties>" +

                          "<d:ApplicationConnectionId></d:ApplicationConnectionId>"+

                          "<d:CustomCustom1></d:CustomCustom1>"+

                          "<d:DevicePhoneNumber>1234567890</d:DevicePhoneNumber>"+

                          "<d:DeviceType>WinMobile</d:DeviceType>"+

                          "<d:DeviceModel m:null='true' /><d:ApnsDeviceToken></d:ApnsDeviceToken>" +

                          "</m:properties></content></entry>";

// Convert the string into a byte array.

byte[] byteArray = Encoding.UTF8.GetBytes(postData);

// Write to the request stream.

postStream.Write(byteArray, 0, postData.Length);

postStream.Close();

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

Stream streamResponse = response.GetResponseStream();

StreamReader streamRead = new StreamReader(streamResponse);

string strresponse = streamRead.ReadToEnd();

// Close the stream object

streamResponse.Close();

streamRead.Close();

// Release the HttpWebResponse

response.Close();

Response from Sybase server will provide application connection details and XML looks like this

<?xml version='1.0' encoding='utf-8'?>

<entry

    xmlns="http://www.w3.org/2005/Atom"

    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"

    xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="http://<SUPServer>:8000/odata/applications/v1/com.sap.mirnah/">

    <id>http://<SUPServer>:8000/odata/applications/v1/com.sap.mirnah/Connections('a3b23f30-749a-4fe5-8550-235e2010ef77')</id>

    <title type="text" />

    <updated>2013-05-21T09:46:40Z</updated>

    <author>

        <name />

    </author>

    <link rel="edit" title="Connection" href="Connections('a3b23f30-749a-4fe5-8550-235e2010ef77')" />

    <category term="applications.Connection" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

    <content type="application/xml">

        <m:properties>

            <d:ETag>2013-05-21 15:16:38.0</d:ETag>

            <d:ApplicationConnectionId>a3b23f30-749a-4fe5-8550-235e2010ef77</d:ApplicationConnectionId>

            <d:AndroidGcmPushEnabled m:type="Edm.Boolean">false</d:AndroidGcmPushEnabled>

            <d:AndroidGcmRegistrationId m:null="true" />

            <d:AndroidGcmSenderId m:null="true" />

            <d:ApnsPushEnable m:type="Edm.Boolean">true</d:ApnsPushEnable>

            <d:ApnsAlerts m:type="Edm.Boolean">true</d:ApnsAlerts>

            <d:ApnsBadges m:type="Edm.Boolean">true</d:ApnsBadges>

            <d:ApnsSounds m:type="Edm.Boolean">true</d:ApnsSounds>

            <d:ApnsAlertMessage>New Items Available</d:ApnsAlertMessage>

            <d:ApnsDeviceToken></d:ApnsDeviceToken>

            <d:CustomizationBundleId m:null="true" />

            <d:ApplicationVersion m:null="true" />

            <d:ClientSdkVersion m:null="true" />

            <d:BlackberryPushEnabled m:type="Edm.Boolean">true</d:BlackberryPushEnabled>

            <d:BlackberryDevicePin m:null="true" />

            <d:BlackberryBESListenerPort m:type="Edm.Int32">5011</d:BlackberryBESListenerPort>

            <d:CapabilitiesPasswordPolicy m:type="Edm.Boolean">false</d:CapabilitiesPasswordPolicy>

            <d:CustomCustom1></d:CustomCustom1>

            <d:CustomCustom2 m:null="true" />

            <d:CustomCustom3 m:null="true" />

            <d:CustomCustom4 m:null="true" />

            <d:DeviceModel m:null="true" />

            <d:DeviceType>WinMobile</d:DeviceType>

            <d:DeviceSubType m:null="true" />

            <d:DevicePhoneNumber>1234567890</d:DevicePhoneNumber>

            <d:DeviceIMSI m:null="true" />

            <d:PasswordPolicyEnabled m:type="Edm.Boolean">true</d:PasswordPolicyEnabled>

            <d:PasswordPolicyDefaultPasswordAllowed m:type="Edm.Boolean">false</d:PasswordPolicyDefaultPasswordAllowed>

            <d:PasswordPolicyMinLength m:type="Edm.Int32">8</d:PasswordPolicyMinLength>

            <d:PasswordPolicyDigitRequired m:type="Edm.Boolean">false</d:PasswordPolicyDigitRequired>

            <d:PasswordPolicyUpperRequired m:type="Edm.Boolean">false</d:PasswordPolicyUpperRequired>

            <d:PasswordPolicyLowerRequired m:type="Edm.Boolean">false</d:PasswordPolicyLowerRequired>

            <d:PasswordPolicySpecialRequired m:type="Edm.Boolean">false</d:PasswordPolicySpecialRequired>

            <d:PasswordPolicyExpiresInNDays m:type="Edm.Int32">0</d:PasswordPolicyExpiresInNDays>

            <d:PasswordPolicyMinUniqueChars m:type="Edm.Int32">0</d:PasswordPolicyMinUniqueChars>

            <d:PasswordPolicyLockTimeout m:type="Edm.Int32">0</d:PasswordPolicyLockTimeout>

            <d:PasswordPolicyRetryLimit m:type="Edm.Int32">20</d:PasswordPolicyRetryLimit>

            <d:ProxyApplicationEndpoint>http://<GatewayServer>:<Port>/sap/opu/odata/sap/<ServiceDocName>/</d:ProxyApplicationEndpoint>

            <d:ProxyPushEndpoint>http://<SUPServer>:8000/notifications/v1</d:ProxyPushEndpoint>

        </m:properties>

    </content>

</entry>

ü  Application Connection ID Storage:

1.       Extract Application Connection ID from the response and store it in device.

2.       Application Connection ID is highlighted in the above XML.

---------------------------------------------

Code to extract ApplicationConnectionId

---------------------------------------------

string ApplicationConnectionId = string.Empty;

XDocument document = XDocument.Parse(response);

XNamespace m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";

XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";

XNamespace o = "http://www.w3.org/2005/Atom";

IEnumerable<string> query = from doc in document.Elements(o + "entry").Elements(o + "content").Elements(m + "properties").Elements(d + "ApplicationConnectionId") select doc.Value;

foreach (strings in query)

ApplicationConnectionId = s;

ü  Loading Collections (Entity Sets):

//URL to get data

url = "http://<SUPServermachine>:8000/<ApplicationID>/<GatewayCollection>";           

// Create a new HttpWebRequest object.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

request.ContentType = "application/atom+xml";

request.Accept = "application/xml,application/atom+xml";

//Credentials of gateway server

request.Credentials = new NetworkCredential("<GatewayUser>", "<GatewayPassword>");

//Headers

request.Headers.Add("X-SUP-SC", "Mirnah");

//Application Connection ID is necessary to connect to proper application in SCC

request.Headers.Add("X-SUP-APPCID", ApplicationConnectionId);

request.Headers.Add("X-SUP-URLREWRITE-ENABLED", "False");           

// Set the Method property to 'POST' to post data to the URI.

request.Method = "GET";

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

Stream streamResponse = response.GetResponseStream();

StreamReader streamRead = new StreamReader(streamResponse);

//This string holds entire gateway entity set collection data

ResponseFromGW = streamRead.ReadToEnd();

           

// Close the stream object

streamResponse.Close();

streamRead.Close();

// Release the HttpWebResponse

response.Close();

Important:

Response XML will hold entire data from gateway server. Parse the XML and bind data using different ODATA parser methologies.

Device Logs:

1.       Login to SCC.

2.       Navigate to Domains à default à Log. All the logs of the devices will be logged here.

Former Member