Beruflich Dokumente
Kultur Dokumente
Purpose
This document presents overview of a Sample User Lookup iPhone application.
Applicable application version 1.0
Application Overview
User Lookup application is a simple application for demonstrating how to implement SOAP and REST web services calls from the iPhone application and handle the following aspects: Basic authentication Client certificate authentication SOAP/XML response parsing REST/JSON response parsing Application specific settings
Page 1 of 16
Application Screens
Description Image A user has to specify a user ID. Depending on a web service type specified in application settings, an application performs SOAP or REST web service request.
If a user has specified a wrong user name or/and password for the Basic authentication type, he gets a prompt asking for authentication credentials.
When an application receives response from a web service, the details screen appears. Depending on a web service type, an application receives SOAP or JSON response. The response is beeing parsed by application and presented to user.
Page 2 of 16
Web Service Type - A user can choose between two web service types. SOAP and REST. SOAP URL - A user has to specify a SOAP service URL. The URL has to be specified without a protocol. (http:// or https:// ) REST URL - A user has to specify a REST service URL. The URL has to be specified without protocol. (http:// or https:// ) SAP Logon Ticket - A user can choose whether to use the SAP Logon Ticket or not. Authentication Type - A user can choose between two authentication types. Basic and Client Certificate authentication. Basic Authentication Settings - A user has to specify a user name and password.
Project Structure
Classes All implementation classes Utils Utility Classes Model Model implementation classes - DataObjects - Service Implementations Web service implementations implementation classes - REST The REST service implementation classes, including data parsing - SOAP The SOAP service implementation classes, including data parsing - Common Common (Abstract) service implementation classes for REST and SOAP View Controllers UI implementation Third Party Libraries JSON Third party JSON parser library Other Sources Other classes including constants Resources NIB Files All *.xib files used in application Settings Configuration files Images All images used in application Frameworks Frameworks included in project Products Compiled application files
Page 3 of 16
Implementation Files
Table below outlines all class files used in an application and their functional area:
Module Delegate Location Classes File UserLookupSampleAppDelegate Description The Application Delegate is a class that receives the applicationlevel messages. It is a subclass of NSObject, which implements UIApplicationDelegate delegate. A utility class that implements interaction with user preferences. Including setting default values when application is installed on a device for the first time. A utility class that implements common methods used in all applications. A data object class that represents a request data object. A data object class that represents a response data object. A subclass of AbstractServiceProvider that implements the specific functionality for a REST web service data request. This class also implements the JSON response parsing using a third-party parser. A subclass of AbstractServiceProvider and it implements specific functionality for a SOAP web service data request. This class also implements an XML response parsing. Delegate protocol for AbstractServiceProvider. An abstract web service provider that has to be extended. This class implements common functionality for the SOAP and REST web service data request, including passing data back to its delegate. Implements user interface for the User Lookup application first screen. It provides capability for a user to enter a User ID and perform the data request. It also informs a user about the asynchronous activity. Implements user interface for the User Lookup application details screen. It provides capability for a user to see the response data. Defines the common constants used in all applications.
Utility Class
Classes/Utils
SettingsManager
Utility Class
Classes/Utils
Utils
Model
Classes/Model/Service Implementations/SOAP
GetUserDetailsSOAPService
Protocol Model
Controller
Classes/View Controllers
RootViewController
Controller
Classes/View Controllers
DetailsViewController
Utility Class
Other Sources
Constants
Page 4 of 16
Prerequisites
User Lookup iPhone application is build as a standard iPhone application using iPhone SDK 3.1. Application is targeted to running on 3.0 or 3.1 iPhone OS (iPhone or iPod Touch), but the Base SDK used here is 3.0.
For application to be used with real data additional web services must be created, deployed and configured on testing environment. For more details refer to Preparing Web Services section
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <yq1:getUserDetails xmlns:yq1="http://www.sap.com/caf/demo.sap.com/userlookup/modeled"> <username>JOHND</username> </yq1:getUserDetails> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Response Sample
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <yq1:getUserDetailsResponse xmlns:yq1="http://www.sap.com/caf/demo.sap.com/userlookup/modeled"> <outputParameter1 xmlns:ns2="http://www.sap.com/caf/demo.sap.com/userlookup/modeled"> <ns2:firstName>John</ns2:firstName> <ns2:lastName>Doe</ns2:lastName> </outputParameter1> </yq1:getUserDetailsResponse> </SOAP-ENV:Body>
Page 5 of 16
Error Sample
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org /soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring>User SOME does not exist</faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
For web service sample implementation please see Enterprise MicroApplications Technical Users Guide for Netweaver 7.0 or 7.1, section Appendix - Creating a Data Service. Guide is available for download under https:// wiki.sdn.sap.com/wiki/display/Img/MicroApplications
Error Sample
{ }
Following web service can be implemented using SAP NetWeaver 7.0 or 7.1, by creating J2EE web application that have servlet acting as endpoint to web service and uses JCo library for accessing SAP backend system. Following could be basic implementation of required functionality:
try{
Page 6 of 16
if(firstName.equals("") && lastName.equals("")){ JCO.Table errorMessage = function.getTableParameterList().getTable("RETURN"); throw new Exception(errorMessage.getString("MESSAGE")); }else{ response.getWriter() .print("{\"UserDetails\":" + "{"+"\"firstName\":\"" + firstName + '"' + "," + "\"lastName\":\"" + lastName + '"' + "}}"); } } catch (Exception ex) { response.setStatus(500); response.getWriter().print("{\"error\":\"" + ex.getMessage()+ "\"}"); ex.printStackTrace(); } finally { mConnection.disconnect(); }
Configuring Authentication
This application demonstrates usage of Basic and Client certificate authentication, as well as SAP Logon ticket. For supporting desired authentication way, web service security must be additionally configured. For complete functionality a web service must have following security mechanisms configured: Basic Authentication Client Certificate SAP Logon Ticket (Create and evaluate) Following is an example of login module configuration:
Login Module Name EvaluateTicketLoginModule com.sap.engine.services.security.server.jaas.ClientCertLoginModule CreateTicketLoginModule BasicPasswordLoginModule CreateTicketLoginModule Flag SUFFICIENT OPTIONAL SUFFICIENT OPTIONAL SUFFICIENT
For web service configuration sample please see Enterprise MicroApplications Technical Users Guide for Netweaver 7.0 or 7.1, section Appendix - Configuring a Data Service.
Page 7 of 16
To build an application using different iPhone SDK version, select Groups & Files > Right click on project > Get Info > Build > iPhone OS Deployment Target.
Page 8 of 16
Page 9 of 16
Select the device, and select the Provisioning Profiles tab. Select a provisioning profile from the list, and click Install.
Page 10 of 16
Build and Go
Before deploying an application to the device, the following must be performed: Set the code signing identity. Select a project in Groups & Files > Right click on project > Get Info > Build > Code Signings Identity. Select the appropriate development profile. Set the appropriate App Id In the project, find the Info.plist file, and in the Bundle identifier row, specify the App ID.
Configuring an Application
This section presents an application settings that must be configured before the application can be used.
Settings.bundle contains two files. The Root.plist file represents the main screen of preferences, but the BasicAuthenticationSettings.plist file represents screen where a user enters a user name and password. The Root.plist file
# Item 1 Settings Parameter Key Type PSGroupSpecifier Description A group item preference. A group type is a method for organizing groups of preferences on a single page. Used to separate Web Service Settings from Authentication Settings Used for a preference that supports a set of mutually exclusive values. A numeric value, that can contain either 0(SOAP) or 1 (REST). Displays an optional title and an editable text field. Must contain a SOAP URL. Displays an optional title and an editable text field. Must contain a REST URL. The RA group item preference. A group type is a method for organizing groups
Item 2
wsType
PSMultiValueSpecifier
soapUrl restUrl
Page 11 of 16
Item 8
Item 2
username
PSTextFieldSpecifier
Item 3
password
PSTextFieldSpecifier
Page 12 of 16
When the certificate link is clicked in iPhone, it asks whether to install it. The certificate will most likely not be verified by another party.
If the certificate is protected with a password, iPhone asks to enter it. Once the password is entered, the certificate is to be installed on the device.
Page 13 of 16
Page 14 of 16
Select the device. Select the Configuration Profiles tab. Select a configuration profile from the list and click Install. To install the profile, on the device, tap Install.
Page 15 of 16
Additional Information
For more information and other sample applications please refer to:
Location MicroApps Home Page MicroApps Code Samples URL http://wiki.sdn.sap.com/wiki/display/Img/MicroApplications/Code+Samples http://wiki.sdn.sap.com/wiki/display/Img/MicroApplications/Code+Samples
Page 16 of 16