议程
• IBM 移动开发平台简介
• IBM Worklight 简介
• IBM Worklight 的架构分析
• 其他相关移动开发技术和产品
2
Worklight Architecture Overview
Secure back-end integration
XML-based declarative specification
Multi-source data mashups
Eclipse plug-in supporting auto-complete and validation
Simplified adapter testing
Server-side debugging
Web services and JDBC integration
Access to session data and user properties
Back-end Integration
3
Benefits• Universality
• Supports multiple integration technologies and back-end information systems• Read-only as well as Transactional Capabilities
• Adapters support read-only and transactional access modes to back-end systems
• Fast Development• Defined using simple XML syntax, and easily configure with JavaScript API
• Security• Use of flexible authentication facilities to create connections with back-end
systems• Adapters offer control over the identity of the connected user
• Scalability• Adapters reduce the number of transactions performed on back-end systems by
using cache to store retrieved back-end data• Transparency
• Data retrieved from back-end applications is exposed in a uniform manner regardless of the adapter type
4
Adapters Overview• An Adapter is a transport layer used
by the Worklight Platform to connect to various back-end systems.
• Adapters are used for:• Retrieving information • Performing actions
• Out of the box:• SQL Adapter• HTTP Adapter (supports both
REST and SOAP)
5
Information Systems Databases Applications
QueryUpdate
data
Data/Result
as JSON
Invoke adapter
procedure
SQL WS
Worklight
HTTP
Response
1
2 3
4
Adapter Anatomy• Each Worklight Adapter consists of:
•An XML file, describing the connectivity options and listing the procedures exposed to the application or other adapters
•A JavaScript file, containing the implementation of procedures declared in the XML file
•Zero or more XSL files, containing a transformation scheme for retrieved raw XML data
• Data retrieved by an adapter can be returned raw or preprocessed by the adapter itself and, in both cases, presented to the application as a JSON object
6
Adapter AnatomyProcedures
• Adapter functionality is available to the app using procedures
• Procedures call back-end services to retrieve data or to perform actions
• Procedures are declared using XML and are implemented using server-side JavaScript
• Using server-side JavaScript, a procedure can process the data before or after calling the service
• Additional filtering can be applied to retrieved data using simple XSLT
7
Creating an Adapter•Right Click on the Worklight Project node•Add new Worklight Adapter
8
Creating an Adapter
•Choose a Worklightproject
•Choose an adapter type
9
Creating an Adapter
• Choose Worklightproject
• Choose adapter type
• Type a name•Applications will
access the adapter via this name.
• Click Finish
10
Creating an Adapter
• Choose Worklight project • Choose adapter type• Type a name
–Applications will access the adapter via this name.
• Click Finish• The result
•XML files to declare procedures and connection properties
•JavaScript file to define procedures and adapter logic
11
Deploying an adapter• Select an adapter to deploy • Right click on it Run As - Deploy Worklight Adapter
• The Worklight Studio will archive the adapter code and deploy it onto the Worklight Server
• You can see the deployed adapter in the Worklight Console
12
Testing Adapter Procedures• It is possible to test adapter procedures using the
Worklight Studio
• To perform procedure test, click on Invoke WorklightProcedure from the Run As menu
13
Testing Adapter Procedures• Select the procedure you
wish to test
• Enter comma-separated procedure parameters
• Click Run
14
Adapter structureXML
Adapter Name. Mandatory attribute.
15
<wl:adapter name="mySQLAdapter" ><displayName /> <description /> <connectivity>
<connectionPolicy> <loadConstraints>
</connectivity><procedure /><procedure />………
</wl:adapter>
<wl:adapter name="mySQLAdapter" ><displayName /> <description /> <connectivity>
<connectionPolicy> <loadConstraints>
</connectivity><procedure /><procedure />………
</wl:adapter>
Adapter structure XML
Name to be displayed in the Worklight Console.
Optional parameter.
16
<wl:adapter name="mySQLAdapter" ><displayName /> <description /> <connectivity>
<connectionPolicy> <loadConstraints>
</connectivity><procedure /><procedure />………
</wl:adapter>
Adapter structure XML
Additional information to be displayed
in the Worklight Console. Optional parameter.
17
<wl:adapter name="mySQLAdapter" ><displayName /> <description /> <connectivity>
<connectionPolicy> <loadConstraints>
</connectivity><procedure /><procedure />………
</wl:adapter>
Connectivity
•Defines the connection properties and load constraints of the back-end system. •When the backend requires end-user authentication, this element defines how user credentials are obtained.
18
Adapter structure XML
<wl:adapter name="mySQLAdapter" ><displayName /> <description /> <connectivity>
<connectionPolicy> <loadConstraints>
</connectivity><procedure /><procedure />………
</wl:adapter>19
Procedures
Declare a service for accessing a back-end application. One entry per each adapter procedure.
Adapter structure XML
• Each procedure declared in the adapter’s XML file must have a corresponding function in the JS file
• Procedure logics are defined via JavaScript using WL.Server API
20
XML File
JS File
Adapter structureJavaScript
HTTP Adapters
•A Worklight HTTP Adapter:•Retrieved data can be in XML, HTML, JSON or plain text formats
21
XML FileConnectivity Settings
• Open the adapter’s XML file•Set protocol (HTTP or HTTPS)•Set HTTP domain (the domain part of the HTTP URL)•Set TCP Port
22
• Service URL is used for procedure invocation• Some parts of the URL are constant (e.g.
http://acme.com/) – they are declared in the XML file• Other parts of the URL may be parameterized, that is,
substituted at runtime by parameter values provided to the Worklight Procedure
• URL parts that can be parameterized are:•Path elements•Query string parameters•Fragments
• See adapter documentation for advanced options such as cookies, headers, encoding etc.
http://acme.com/rest/customers?custid=12Path elements
Query string
23
JS FileProcedures Implementation, Cont.
• Procedure name in the JavaScript file must be the same as in the XML file
• Required invocation parameters are method, path and returnedContentType
• Procedure can be parameterized at runtime
24
JS FileProcedures Implementation, Cont.
Procedure’s XML file Procedure’s JavaScript file
• To invoke an HTTP request, use the WL.Server.invokeHttpmethod
• It expects input parameters object• You can specify:
–HTTP method (GET or POST)–Returned content type (XML, JSON,
HTML, plain)–Service path–Query parameters –Request body–Transformation type–For a full list of invocation options please see the Developer
Reference Guide under Product Documentation
25
JS FileProcedures Implementation, Cont.
XSL Transformation Filtering• XSL transformation can be applied to the received data• Can be used to filter received data• To apply, specify the transformation options in the
procedure invocation input parameters
26
Creating a SOAP-based Service Request
•SOAP envelope can be created and sent directly using the WL.Server.invokeHttp method:•To invoke a SOAP-based service in an HTTP
adapter you need to encode the SOAP XML envelope within the request body
•Encoding XML within JavaScript is simple using E4X, which is officially part of JavaScript 1.6
•This technology can be used to encode any type of XML document, not necessarily SOAP envelopes
27
Creating a SOAP-based Service Request
•Use JavaScript to create a SOAP Envelope
28
Creating a SOAP-based Service Request•It is possible to insert JavaScript code into SOAP XML. It will be evaluated at runtime
29
Service Request Invocation
•WL.Server.invokeHttp(options) method is used to invoke a request for a SOAP service
•options object must include the following properties:•method – usually POST• returnedContentType – usually XML•path – a service path•body
•content – SOAL XMLas a string
•contentType
30
Service Request Invocation, Cont.•Full SOAP-based service invocation procedure
example
31
SOAP envelope
Options
Request invocation
SQL Adapters
• A Worklight SQL Adapter is designed to communicate with any SQL data source
• Both plain SQL queries or stored procedures can be used
32
• Connection can be either JNDI or data source definition• JNDI - Java Naming and Directory Interface - providing Java
applications with a unified interface for multiple naming and directory services.
• A JNDI name can be declared as a parameter that is defined in a worklight.properties file. This is an adapter’s XML file:
• And these are corresponding entries in the worklight.properties file
XML FileConnectivity Settings
33
JS FileProcedure
• A procedure must be declared in the Adapter’s XML file
• The adapter’s JavaScript file is used to implement the procedure logic
• IMPORTANT – The same name declared in the XML file should be used for the procedure’s JavaScript function
• There are two ways of invoking SQL statements: –Using SQL statement query–Using SQL Stored Procedure
34
JS FileSQL Query
• To execute an SQL query1. Prepare an SQL query using the WL.Server.createSQLStatement
API2. WL.Server.createSQLStatement should ALWAYS be called
outside of the function3. Add additional parameters if required4. Use the WL.Server.invokeSQLStatement API to invoke prepared
queries5. Return invocation result to procedure invocator (application or
another procedure)
35
1
3
4
JS FileStored SQL Procedure
• To execute a stored SQL procedure1. Use the WL.Server.invokeSQLStoredProcedure API to execute a
stored procedure2. Specify an SQL stored procedure name as an invocation parameter3. Add additional parameters if required4. Return invocation result to procedure invocator (application or
another procedure)
36
1
23
WL AdaptersInvocation Result
• Result retrieved as a JSON object
• isSuccessful property defines whether invocation was successful
• resultSet is an array of returned records
37
Server-side ScriptingWhy?
• Enhancing adapter capabilities•Pre & Post processing logic•All processing can be done with only one call to the
server and in one transaction•Enables data mashups from different sources
Invoke Procedure
38
Server-side API• WL.Server.InvokeProcedure (invocationData)
• Procedure invocation from current or other adapter• Same syntax as a client-side WL.Client.invokeProcedure
• WL.Logger.debug (msg)• Outputs messages to the console• Used for debugging
• WL.Server.configuration object• A map containing all the server properties defined in the
worklight.properties file• Syntax
• WL.Server.configuration[“property-name”]• WL.Server.configuration.property-name
• Example• Var addr = WL.Server.configuration[“local.IPAddress”];
39
Data Mashup Example
40
Data Mashup Example• Data Mashup can be implemented in the same way for any
number of data sources and across different adapter types • As an example, we will mashup data from the following sources:
• SQL : • We will extract a list of cities from the weather table• Result will contain list of several cities around the world, their
Yahoo! Weather identifier and some description• HTTP:
• We will connect to Yahoo! Weather Service• We will extract updated weather forecast for each of the cities
retrieved with SQL• Afterwards, the mashed-up data will be returned to the application
for display
41
Data Mashup ExampleSQL Adapter
• Create a new SQL adapter and name it SQLAdapter
• This adapter will contain three procedures:
• getCitiesWeather – a public procedure, declared in the adapter’s XML file. It will be called from the application and return the mashed-up data
• getCitiesList – an internal (private) function, not declared in the adapter’s XML file. It will be called from the adapter using a server API to get the cities list from the SQL server
• getCityWeather – an internal (private) function, not declared in the adapter’s XML file. It will call the getYahooWeather procedure from a different adapter (HTTP) with the Yahoo! Weather ID as a parameter
• Functions will be implemented using Server-side JavaScript
42
Data Mashup ExampleHTTP Adapter
• Create a new HTTP adapter and name it HTTPWeather
• This adapter will connect to Yahoo! Weather RSS feed at http://weather.yahooapis.com/forecastrss
• The adapter will have a single procedure called getYahooWeather
• The HTTP request will have the two following parameters:
• w – Where in the world ID, a city ID used by Yahoo!
• u – units. Can be “c” for Celsius or “f” for Fahrenheit
• Full request URL example:
• City ID parameter is to be provided by procedure invocator
• Units parameter is hard-coded
43
Data Mashup ExampleMashup Schema
44
ApplicationApplication SQLAdapterSQLAdapter
HTTPWeatherHTTPWeather
SQL DatabaseSQL Database
Yahoo! Weather APIYahoo! Weather API
1 2
38
4
5
6
7
getCitiesWeather getCitiesList
getYahooWeather
Data Mashup ExampleMashup Schema
45
Repeated for each city
Data Mashup ExampleServer-side JS
• Declare the getCitiesWeather procedure in SQLAdapter’s XML file.Its function is to get data from two different adapters and mashup the result into one data object
• Create getCitiesList function in SQLAdapter’s JS file and use it to retrieve and return the cities list from the SQL database
• Retrieved data will contain a list of cities with the following fields:• city - a city name
• identifier – city ID for Yahoo! Weather API
• summary – a brief description of the city
46
Data Mashup ExampleServer-side JS
• Create getCityWeather function in SQLAdapter’s JS file and use it to retrieve and return weather data from the HTTPWeather adapter
47
Data Mashup ExampleServer-side JS
48
• Declare the getYahooWeather procedure in HTTPWeather’s XML file
• It’s task is to retrieve weather data using the supplied city ID as a parameter
• Create getYahooWeather function in HTTPWeather’s JS file and use it to retrieve and return weather data using Yahoo! Weather API
Data Mashup ExampleServer-side JS
49
• In SQLAdapter, extract city identifier from city list retrieved earlier and use it to call HTTPWeather adapter’s getYahooWeather procedure
• Repeat for each city attaching the received data to city object
• Return mashed-up data to application
Data Mashup ExampleExamine the Result
50
SQL Data
Yahoo! Weather
Invoking a Procedure From the Application
51
• Adapter procedures can be invoked within Worklightapplications, allowing them to communicate with any data source without being subjected to same-origin constraints
• The first step to invoke an adapter procedure is to create an invocationData object
WL.Client.invokeProcedure (invocationData, options)WL.Client.invokeProcedure (invocationData, options)
Invoking a Procedure From the Application
• The invocationData object is used to provide invocation configuration and procedure parameters
• It consists of a JSON block of properties
52
WL.Client.invokeProcedure (invocationData, options)WL.Client.invokeProcedure (invocationData, options)
Invoking a Procedure From the Application
• The invocationData object is used to provide invocation configuration and procedure parameters
• It consists of a JSON block of parameters
53
adapter (mandatory)
A string containing the name of the adapter as specified in the adapter’s
<wl:adapter> element.
• The invocationData object is used to provide invocation configuration and procedure parameters
• It consists of a JSON block of parameters
WL.Client.invokeProcedure (invocationData, options)WL.Client.invokeProcedure (invocationData, options)
Invoking a Procedure From the Application
procedure (mandatory)
Procedure name as defined in the XML file
54
• The invocationData object is used to provide invocation configuration and procedure parameters
• It consists of a JSON block of parameters
WL.Client.invokeProcedure (invocationData, options)WL.Client.invokeProcedure (invocationData, options)
Invoking a Procedure From the Application
55
parameters (mandatory)
An array of parameters that are passed to the backend JavaScript procedure. Leave
empty if no parameters are required
Invoking a Procedure From the Application
56
•The second step is to define failure and success behavior in options object
The Options Object
• Options object should be passed for all asynchronous calls to the Worklight Server
WL.Client.invokeProcedure (invocationData, options)WL.Client.invokeProcedure (invocationData, options)
The function to be invoked on successful completion of the asynchronous call
The response will typically contain the following properties:• invocationContext: The invocationContext object that was originally passed in the
options object, or undefined if no invocationContext object was passed.• status: The HTTP response status • invocationResult: An object containing the data returned by the invoked
procedure, and additional information about the procedure invocation.57
The Options Object
• Options object should be passed for all asynchronous calls to the WorklightServer
WL.Client.invokeProcedure (invocationData, options)WL.Client.invokeProcedure (invocationData, options)
The function to be invoked on failure• Includes both server-side errors, and client-side (such as server connection
failure or timed out calls). The response will typically contain the following properties:
• invocationContext• errorCode: An error code string. All error codes that can be returned are
defined as constants in the WL.ErrorCode object in worklight.js.• errorMessage: This message is for the developer's use only, and should not be
displayed to the end-user. It will not be translated to the user's language. • status: The HTTP response status
58
The Options Object
• Options object should be passed for all asynchronous calls to the Worklight Server
WL.Client.invokeProcedure (invocationData, options)WL.Client.invokeProcedure (invocationData, options)
Optional parameter. An object that will be returnedto the success and failure handlers
The invocationContext object is used to preserve the context of the calling asynchronous service upon returning from the service.
59
Invoking a Procedure From the Client App
60
•Bringing everything together
1. Invocation data
2. Invoking the procedure
3. Setting the success/failure handlers
4. Success handler
5. Failure handler
Invocation Result• A JSON object containing the data and additional
information about the procedure invocation is returned • Object is returned to a corresponding success/failure
handler
61
Invocation Result
isSuccessful property
true if the procedure invocation succeeded (even if no data was retrieved)
false otherwise
62
Invocation Result
RecordsAn array of records retrieved from the backend. Each array entry is
an object containing the fields of the single record. If the procedure call returns no records, an empty array is returned. If not specified otherwise in the XSL file, default property name is
recordSet
63
Invocation Result
Error/Warn/Info Messages
An optional array of strings containing error messages. If no error messages are provided, this object is NULL.
64
IBM mobile enterprise apps available today
IBM Sterling Integrator Mobile
IBM Sterling Store Associate Mobile
IBM Sterling TMS Carrier Mobile
IBM Sterling Field Sales Mobile
IBM Sterling Order Management Administration MobileIBM Sterling Control Center Mobile
IBM Sterling InFlight Data Management Mobile
IBM Sterling Document Tracking Mobile
CommerceCommerce
IBM Lotus Notes Traveler (email, calendar, contacts)
IBM Connections (social)
IBM Sametime (IM, UC)
IBM SmartCloud Meetings
IBM Symphony (doc viewer)
Social BusinessSocial Business
Coremetrics for Mobile
IBM Cognos Mobile
Business Intelligence & AnalyticsBusiness Intelligence & Analytics
Extend and Transform through MobileIBM Social Business: Mobile Vision
A comprehensive suite of mobile solutions for social business
Device appropriate interfaces for the leading mobile devices - smartphones and tablets
Apple®, Android, BlackBerry®, Nokia
Supported by enterprise governance and security capabilities
Mobile application tools and embedded OpenSocial experiences to build mobile social business solutions
A comprehensive suite of mobile solutions for social business
•
•
Extend and Transform through MobileIBM Social Collaboration apps for mobile devices
IBM Lotus Notes Traveler -- push email, calendar, contacts (also available in IBM SmartCloud)Real-time collaboration ? IBM Sametime presence, IM chat and telephonyOnline meetings for IBM Sametime or via IBM SmartCloud for Social BusinessIBM Connections social software for access to your professional networkIBM Lotus Symphony Viewers for viewing business documents
Available for deployment today
•Traveler monthly calendar view for Android tablets/ phones
•IBM plans are subject to change
•Daily busy time
•Pop up •daily
•summary
•Traveler Calendar + To Do for Android tablets/ phones
•IBM plans are subject to change
•Connections Next - iOS and Android
•IBM plans are subject to change
•New sliding home page •Improved profiles•Improved person card
•Sametime Meetings Viewer for iPad
•IBM plans are subject to change
Build and Connect for Mobile DevicesEmerging needs for mobile enterprise custom solutions
Organizations are:- Seeking solutions to extend their web presence to a variety of mobile devices
Seeking solutions to reduce their costs of mobile development
IBM offers the broadest set of mobile capabilities to address all these needs
Mobile Applications
Multichannel Sites
Provide a consistent integrated web experience across multiple channels (desktop browser, smartphones, tablets, etc..) W
hy?
Nee
ded
Cap
abilit
ies
Exam
ples
Provide an experience that takes full advantage of the device and its ecosystem
Aggregate multiple applications Content management Personalized for roles
Dedicated, task focussed app Integrates with device capabilities (e.g. camera) App store presence
Build and Connect for Mobile DevicesA complete mobile strategy requires a two-pronged approach Where are customers starting today?
Mobile Applications
Multichannel Sites
Provide a consistent integrated web experience across multiple channels (desktop browser, smartphones, tablets, etc..)
Provide an experience that takes full advantage of the device and its ecosystem
Build and Connect for Mobile DevicesIBM solutions address both mobile needs
WebSphere Portal Solutions Worklight Solutions
Build and Connect for Mobile DevicesExample of complete mobile solution
Multi -channel Site Mobile App
Airline check in app available on app store that downloads
electronic boarding pass to the device and sends
notification of delays or gate changes
An airline web site that allows mobile check in, print boarding
pass, change seat, access flight schedules, book a new flight, look up their frequent
flyer account, search for lounge
Mobile app shares consistent content and services as web site
Multichannel SitesBuild, run and manage Web content, applications, and processes that are integrated, personalized for the right user, delivered in the right context and optimized for the right device
personalized integrated optimized
Need Solution
..develop, manage and deploy multichannel web sites for desktop, leading smart phones and tablets?
Portal Mobile Experience + Web Experience Factory/RAD
...develop, manage and deploy a mobile web sites or mobile web applications for a wide variety of devices and device types, including monochrome phones?
Mobile Portal Accelerator (supports 10,000 Devices)
Build and Connect for Mobile DevicesWeb Experiences - Customer Needs and IBM Solutions
WebSphere Portal solutions provide multichannel sites that:
Integrate with your back-end systems, including web content management
Provide single client record
Allow seamless migration between web channels
Are personalized to a user's role, preferences, and behavior across channels and devices
Provide authentication across channels
Support end-user customization
Are secure
Can be measured and optimized using analytics
Has awareness of what device is requesting information
Can adapt their presentation and functionality according to the device
One common framework for multi-channel multi-device Web Sites
•Portal Mobile Experience - Themes
•Site •Navigation•
•
•Look •and Feel•
•Page •Layout••
•Mobile theme • – lightweight, visually rich, exploiting Webkit CSS3 visual •effects•Navigation widgets• •– set of showcase samples of common mobile app •navigation patterns•Page layouts • – set of showcase samples of content interaction patterns•Can be easily extended with •dojo.mobile, jQuery, •etc.. •
• IBM Worklight Mobile Platformhttp://t.cn/zODNySZ
• IBM WebSphere Portal Expresshttp://t.cn/zOkxZrf
• developerWorks 下载中心http://t.cn/zOcXg9P
推荐下载