Kolbans Worklight Book 2014 09

Embed Size (px)

Citation preview

  • 8/17/2019 Kolbans Worklight Book 2014 09

    1/298

    September 2014

     Never memorize what you can look up in books.

      - Albert Einstein

    Page 1

  • 8/17/2019 Kolbans Worklight Book 2014 09

    2/298

    Table of ContentsMobile Applications...........................................................................................................................13

    Types of Mobile App architectures...............................................................................................13

    esign gui!elines for Mobile Apps...............................................................................................13

    "orklight............................................................................................................................................1#$eleases.........................................................................................................................................1#

    Architecture........................................................................................................................................1#

    A!apter %omponents.....................................................................................................................1&

    Application %enter.........................................................................................................................1&

    'nstallation..........................................................................................................................................1(

    Prere)usites....................................................................................................................................1(

    Parts *ist........................................................................................................................................1(

    'nstalling "orklight +tu!io...........................................................................................................1(

    'nstalling an An!roi! +, -clipse Plugin....................................................................................3

    %onfiguring the "orklight +tu!io embe!!e! Application +erver................................................#

    'nstalling Mobile Test "orkbench for "orklight.........................................................................&'nstalling "orklight +erver...........................................................................................................&

    'nstalling the Application %enter...................................................................................................3/

    'nstalling "A+ *iberty..................................................................................................................3/

    0ther 'nstallation Tasks.................................................................................................................#

    +ources of 'nformation.......................................................................................................................&

    The 'nfo%enter...............................................................................................................................&

    '2M ome Page............................................................................................................................&

    $e!books.......................................................................................................................................&

    !eveloper"orks.............................................................................................................................&

    %ommunities..................................................................................................................................4

    5ou Tube.......................................................................................................................................4Application evelopment...................................................................................................................(

    "orklight +tu!io............................................................................................................................(

    %reating a "orklight Pro6ect........................................................................................................./

    Anatomy of a Pro6ect...................................................................................................................../

    Application escriptor...................................................................................................................#

    Application Architecture................................................................................................................#

    A!!ing targete! environments.......................................................................................................#

    "orklight evelopment +erver.....................................................................................................#3

    eveloping 7' 8 $ich Page -!itor................................................................................................#

    esigning visually.....................................................................................................................#/

    %o!ing in the TM* source.....................................................................................................&9

    'mages an! graphics..................................................................................................................&9

    0ff:line +torage.............................................................................................................................&1

    The "orklight ;+0N+tore........................................................................................................&1

    Push Notification...........................................................................................................................&

    Testing...........................................................................................................................................&

    7sing the Mobile 2rowser +imulator.......................................................................................&3

    'nstalling the 7serAgent +witcher -

  • 8/17/2019 Kolbans Worklight Book 2014 09

    3/298

    %reating a new A!apter.................................................................................................................49

    A!apter 'mplementation................................................................................................................41

    A!apter ;ava+cript implementation..........................................................................................41

    A!apter Types................................................................................................................................4

    TTP A!apter...........................................................................................................................4

    TTP A!apter Proce!ure implementations.........................................................................43

    %onfiguring the TTP A!apter for ++*..............................................................................4-ile %oncatenation........................................................................................................................./3

    +ecurity.............................................................................................................................................../3

    +ecure on:!evice store! !ata........................................................................................................./

    0ffline Authentication.................................................................................................................../

    Preventing tampere! apps............................................................................................................../

    irect 7p!ate................................................................................................................................./

    $emote isable............................................................................................................................../

    "orklight protecte! resources......................................................................................................./

    %ross site $-+T calls...................................................................................................................../#

    Programatically authenticating with "A+..................................................................................../#

    Application eployment..................................................................................................................../#

    0perations.........................................................................................................................................19

    Programming $eferences.................................................................................................................19

    %lient +i!e AP' Programming.....................................................................................................193

    "*.%lient................................................................................................................................193

    The common ?options? ob6ect............................................................................................193

    "*.%lient.a!!@lobalea!erhea!erNameB hea!erCalueD.................................................193"*.%lient.closeD...............................................................................................................193

    "*.%lient.connectoptionsD...............................................................................................19

    "*.%lient.!elete7serPrefkeyB optionsD............................................................................19

    "*.%lient.getAppPropertypropertyNameD.......................................................................19

    "*.%lient.get-nvironmentD..............................................................................................19

    "*.%lient.get*oginNamerealmD......................................................................................19#

    "*.%lient.get7ser'nforealmB keyD...................................................................................19#

    "*.%lient.get7serNamerealmD........................................................................................19#

    "*.%lient.get7serPrefkeyD..............................................................................................19#

    "*.%lient.has7serPrefkeyD..............................................................................................19#

    "*.%lient.initoptionsD......................................................................................................19&

    Page 3

  • 8/17/2019 Kolbans Worklight Book 2014 09

    4/298

    "*.%lient.invokeProce!ureinvocationataB optionsD......................................................194

    "*.%lient.is7serAuthenticate!realmD..............................................................................194

    "*.%lient.logActivityactivityTypeD.................................................................................194

    "*.%lient.loginrealmB optionsD........................................................................................194

    "*.%lient.logoutrealmB optionsD......................................................................................19(

    "*.%lient.minimizeD........................................................................................................19(

    "*.%lient.reloa!AppD......................................................................................................19("*.%lient.remove@lobalea!erhea!erNameD.................................................................19(

    "*.%lient.seteart2eat'ntervalintervalD..........................................................................19(

    "*.%lient.set7serPrefkeyB valueB optionsD......................................................................19(

    "*.%lient.set7serPrefsprefsB optionsD.............................................................................19/

    "*.%lient.up!ate7ser'nfooptionsD...................................................................................19/

    "*.2usy'n!icatorcontainer'!B optionsD...........................................................................19/

    "*.Toast.showmessageD..................................................................................................119

    "*.;+0N+tore.......................................................................................................................111

    "*.;+0N+tore.a!!!ataB optionsD.....................................................................................111

    "*.;+0N+tore.changePasswor!ol!Passwor!B newPasswor!B userNameD......................111

    "*.;+0N+tore.closeAllD..................................................................................................111"*.;+0N+tore.countD......................................................................................................111

    "*.;+0N+tore.!estroyD...................................................................................................111

    "*.;+0N+tore.!ocumentifyi!B !ataD...............................................................................111

    "*.;+0N+tore.enhancenameB funcD................................................................................11

    "*.;+0N+tore.fin!)ueryB optionsD..................................................................................11

    "*.;+0N+tore.fin!AlloptionsD........................................................................................11

    "*.;+0N+tore.fin!2y'!i!D..............................................................................................11

    "*.;+0N+tore.getcollectionNameD.................................................................................11

    "*.;+0N+tore.get-rrorMessageerror%o!eD....................................................................113

    "*.;+0N+tore.getPush$e)uire!D....................................................................................113

    "*.;+0N+tore.initD..........................................................................................................113

    "*.;+0N+tore.isPush$e)uire!!ocD................................................................................11

    "*.;+0N+tore.loa!D........................................................................................................11

    "*.;+0N+tore.push!ocsD................................................................................................11

    "*.;+0N+tore.push$e)uire!%ountD...............................................................................11

    "*.;+0N+tore.remove!ocB optionsD................................................................................11

    "*.;+0N+tore.remove%ollectionD..................................................................................11

    "*.;+0N+tore.replace!ocB optionsD................................................................................11#

    "*.;+0NM+tore.to+tringD...............................................................................................11#

    "*.evice...................................................................................................................................11#

    "*.evice.getNetwork'nfocallbackD....................................................................................11#0ther........................................................................................................................................11#

    +erver +i!e AP' Programming....................................................................................................11&

    "*.+erver...............................................................................................................................11&

    "*.+erver.invoke+=*+tore!Proce!ureoptionsD..............................................................11&

    "*.+erver.create+=*+tatementstatementD......................................................................11&

    "*.+erver.invoke+=*+tatementoptionsD........................................................................11&

    "*.+erver.invokettpoptionsD.........................................................................................114

    "*.+erver.rea!+ingle;M+MessageoptionsD....................................................................1

    "*.+erver.rea!All;M+MessagesoptionsD........................................................................13

    "*.+erver.write;M+MessageoptionsD.............................................................................13

    "*.+erver.re)uest$eply;M+MessageoptionsD................................................................1

    Page

  • 8/17/2019 Kolbans Worklight Book 2014 09

    5/298

    An!roi! evelopment......................................................................................................................1#

    'nstalling the An!roi! +,.........................................................................................................1#

    Managing the An!roi! +,........................................................................................................1#

    An!roi! -mulator........................................................................................................................1#

    ;ava+cript >rameworks....................................................................................................................1&

     6=uery Mobile..............................................................................................................................1&

    o6o an! o6o Mobile.................................................................................................................1&+encha Touch...............................................................................................................................1&

    *ocal storage of !ata........................................................................................................................14

    "eb Programming............................................................................................................................1(

    evelopment tools.......................................................................................................................1(

    ocument 0b6ect Mo!el 8 The 0M.........................................................................................1/

    TM*..........................................................................................................................................1/

    'mages..........................................................................................................................................1/

    ;ava+cript.....................................................................................................................................139

    ;ava+cript 8 ate ob6ect..........................................................................................................139

    7sing ;+int...........................................................................................................................139

    %alling ;ava+cript from ;ava..................................................................................................131%asca!ing +tyle +heets 8 %++.....................................................................................................131

    The ElessF language................................................................................................................13

    Cariables.............................................................................................................................13

    Mi

  • 8/17/2019 Kolbans Worklight Book 2014 09

    6/298

    !o6oH!om.................................................................................................................................13

    !o6oH!om:construct.................................................................................................................13

    !o6oH)uery...............................................................................................................................13

    !o6oH!om:geometry.................................................................................................................1#

    o6o ates an! Times..................................................................................................................1#

    !o6oH!ate..................................................................................................................................1#

    !o6oH!ateHlocale.......................................................................................................................1&!o6oH!ateHstamp.......................................................................................................................1&

    i6it "i!gets................................................................................................................................14

    %reating a wi!get instance programatically............................................................................14

    !i6itHregistry : i6it an! by'!...................................................................................................1(

    i6its an! events......................................................................................................................1(

    o6o style sheets an! themes..................................................................................................1(

    >orm "i!gets..........................................................................................................................1/

    !i6itHformH>orm...................................................................................................................1/

    !i6itHformH2utton.................................................................................................................1#9

    !i6itHformH$a!io2utton.......................................................................................................1#1

    !i6itHfromH%ombo2o

  • 8/17/2019 Kolbans Worklight Book 2014 09

    7/298

    !i6itHlayoutHTab%ontainer...................................................................................................1&4

    !i6itHTitlePane.....................................................................................................................1&(

    !i6itHlayoutH+tack%ontainer.................................................................................................1&(

    !i6itHlayoutH2or!er%ontainer..............................................................................................1&(

    !o6o

  • 8/17/2019 Kolbans Worklight Book 2014 09

    8/298

    Progress 2ar............................................................................................................................1/3

    !o6oacet................................................................................................9

    7sing the "eb Preview +erver runtime..................................................................................

    o6o evelopment with Microsoft ''+ -

  • 8/17/2019 Kolbans Worklight Book 2014 09

    9/298

    !o6o

  • 8/17/2019 Kolbans Worklight Book 2014 09

    10/298

    The ello "orl! app...................................................................................................................#

    The ;ava>G igh *evel Architecture..........................................................................................#

     6avafG *abel..........................................................................................................................&/

    ;ava>G *istCiew.....................................................................................................................49;ava>G Passwor!>iel!............................................................................................................49

    ;ava>G Progress2ar................................................................................................................49

    ;ava>G $a!io2utton...............................................................................................................41

    ;ava>G +eparator....................................................................................................................41

    ;ava>G +li!er..........................................................................................................................41

    ;ava>G TableCiew..................................................................................................................41

    %ell>actory.........................................................................................................................43

    -!iting a table cell..............................................................................................................4#

    ;ava>G TableCiew 8 etecting selections.........................................................................4&

    ;ava>G TableCiew 8 ynamic %olumns...........................................................................4&

    ;ava>G Te

  • 8/17/2019 Kolbans Worklight Book 2014 09

    11/298

    ;ava>G Teiel!....................................................................................................................44

    ;ava>G Toggle2utton.............................................................................................................4(

    ;ava>G Tooltip........................................................................................................................4(

    ;ava>G TreeCiew...................................................................................................................4(

    ;ava>G TreeTableCiew..........................................................................................................4(

    ;ava>G "ebCiew...................................................................................................................4(

    %alling ;ava+cript in the "eb-ngine.................................................................................4/%alling ;ava from the browser............................................................................................4/

    ;ava>G Menus.............................................................................................................................4/

    ;ava>G Menu2ar....................................................................................................................(9

    ;ava>G Menu..........................................................................................................................(9

    ;ava>G Menu'tem...................................................................................................................(9

    ;ava>G %heckMenu'tem.........................................................................................................(1

    ;ava>G $a!ioMenu'tem.........................................................................................................(1

    ;ava>G %ustomMenu'tem......................................................................................................(1

    ;ava>G +eparatorMenu'tem...................................................................................................(1

    ;ava>G %onteG %ontainers.......................................................................................................................(1;ava>G Accor!ion...................................................................................................................(1

    ;ava>G AnchorPane................................................................................................................(

    ;ava>G 2or!erPane.................................................................................................................(

    ;ava>G >lowPane...................................................................................................................(

    ;ava>G @ri!Pane....................................................................................................................(

    ;ava>G 2oG Pane............................................................................................................................(

    ;ava>G $egion........................................................................................................................(

    ;ava>G +crollPane..................................................................................................................(

    ;ava>G +plitPane....................................................................................................................(

    ;ava>G +tackPane...................................................................................................................(

    ;ava>G TabPane.....................................................................................................................(

    ;ava>G TilePane.....................................................................................................................(3

    ;ava>G Title!Pane..................................................................................................................(3

    ;ava>G C2oG 0ther classes...................................................................................................................(3

    ;ava>G Popup.........................................................................................................................(3

    ;ava>G Popup"in!ow...........................................................................................................(3

    ;ava>G -vent an!ling...............................................................................................................(3

    ;ava>G *amb!a functions...........................................................................................................(

    %hange*istener.......................................................................................................................(;ava>G 7tilities...........................................................................................................................(

    ;ava>G Multiple+electionMo!el............................................................................................(

    ;ava>G evelopment...................................................................................................................(

    +cenic Ciew............................................................................................................................(#

    +keleton ;ava>G >iles.................................................................................................................(#

    +ample application..................................................................................................................(#

    +ample %omponent.................................................................................................................(#

    ;ava>G 3r! Party Packages..........................................................................................................(&

    %ontrols>G..............................................................................................................................(&

    org.controlsf

  • 8/17/2019 Kolbans Worklight Book 2014 09

    12/298

    Apache TTP +erver.......................................................................................................................((

    +etting up a pro

  • 8/17/2019 Kolbans Worklight Book 2014 09

    13/298

    Mobile ApplicationsApplications are no longer limite! to 6ust running on a !esktop P% or laptop. 'nstea!B we now have

    a plethora of !evices on which applications can live. +pecificallyB we will be thinking about smart

     phones an! tablets. These !evices have something in common L they are consumer items that are

    generally small enough to be carrie! with a person. 7nlike classic P% !esktops which are

     physically cumbersome an! remain static in a persons office or homeB the phone an! tablet travelwith people. 'n other wor!sB they are ?mobile?. Applications written specifically for phones an!

    tablets are terme! ?mobile applications?.

    ow !oes a ?mobile application? !iffer from a ?regular application?J The answer to that is not

    always so clear. There are some obvious thoughts. >irstB the phone an! the tablet !ont commonly

    have keyboar!s or mice attache!. As suchB user interaction is primarily performe! through touch

    an! gestures. This changes the way in which 7' styling is built. Neor these reasons an! many moreB when one is consi!ering an application to be hoste! by one of

    these !evicesB there are consi!erations to be taken into account which are not present for !esktop

    applications that simply run "in!ows. 2ecause of the wi!e variety of new areas to be covere!B

    there is the nee! for new frameworksB platforms an! tools to support such new application

    !evelopment. 't is for this purpose that '2M built "orklight.

    Types of Mobile App architectures

    "hen looking at a Mobile appB there are number of high level architectures that can be employe!.

    The first is the "eb or TM*# type. 'n this styleB the app is written purely as a web page using a

    combination of stan!ar!ize! technologies TM*B 0MB ;ava+cript an! %++. A key benefit to a

    web app is that it can run without mo!ification on a variety of platforms without mo!ification.

    7nfortunatelyB pure web:apps typically re)uire a network connection in or!er to run as they must be

    !ownloa!e! for e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    14/298

    The patterns for !esigning user interfaces for mobile apps takes a !ifferent style from that for

    !esktop.

    +ee alsoK

    • esigning for i0+ 4

    Page 1

    https://developer.apple.com/library/ios/documentation/userexperience/conceptual/MobileHIG/index.htmlhttps://developer.apple.com/library/ios/documentation/userexperience/conceptual/MobileHIG/index.html

  • 8/17/2019 Kolbans Worklight Book 2014 09

    15/298

    Worklight'2M "orklight is a !evelopment an! runtime platform for buil!ing a variety of user interfaces

    inclu!ing mobile.

     ReleasesThere have been a number of releases of "orklightK

    • ;une 91 8 #.9

    • ecember 91 8 #.9.#

    • April 913 8 #.9.&

    ;une 913 8 &.9•  November 913 8 &.1

    +ee alsoK

    • "orklight forum

    Architecture"orklight provi!es a set of components which work together to achieve a buil! an! run:time

    environment for mobile applications. ere we start to un!erstan! the pieces involve!.

    The architecture of "orklight is compose! of a number of partsK

    Page 1#

    http://stackoverflow.com/search?q=worklighthttp://stackoverflow.com/search?q=worklight

  • 8/17/2019 Kolbans Worklight Book 2014 09

    16/298

    • "orklight +tu!io 8 An integrate! !evelopment environment '-D built on -clipse use! by

    a !eveloper to buil! a mobile app.

    • "orklight evice $untime 8 A framework supplie! with the application that provi!es

    services use! by that application.

    • "orklight +erver 8 A back:en! server environment use! to service re)uests from a mobile

    app.

    • "orklight %onsole 8 A web base! application use! to manage an! monitor mobile apps.

    • "orklight Application %enter 8 A "orklight +erver hoste! application that provi!es the

    ability for users to select an! install applications onto their mobile !evices. evelopers an!

    a!ministrators can also publish applications that can then be accesse!.

     Adapter Components

    %lient applications often have to interact with back:en! systems to retrieve or store !ata. "orklight

     provi!es an abstraction of such back:en! interactions an! calls these ?A!apters?. The way a client

    interacts with an a!apter is common irrespective of the implementation of that a!apter. %ommon

    a!apter types inclu!e TTP connectionsB +0AP web servicesB +=* !atabase access an! others.

    +ee alsoK

    • A!apters

     Application Center 

    0n the 'nternetB mobile applications are commonly store! installe! from Apples iTunes store or

    from @oogles Play +tore. >or mobile applications written for a business this may not be

    appropriate. >or e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    17/298

    %enter can be thought of as a private app store however it provi!es more function than that.

    evelopers within your own company can publish new versions of the app for users to access

    without being at the mercy of 3r! party provi!ers who may !elay publication. 'n a!!itionB the

    Application %enter is common across !evice platforms meaning that you may publish it once for a

    variety of !evices without having to worry about !ifferent processes to be followe!.

    The Application %enter also provi!es a rich fee!back mechanism where users can post comments

    that can be seen by !evelopers.

    +ee alsoK

    • Application %enter 

    Page 14

  • 8/17/2019 Kolbans Worklight Book 2014 09

    18/298

    InstallationThe installation of "orklight can be broken !own into the installation of the !istinct components

    associate! with it. These inclu!eK

    • "orklight +tu!io 8 evelopment tools

    • "orklight +erver 8 Test an! pro!uction servers for application eI3

    There !ont appear to be other partsO

    %',5M* 8 "A+ *iberty %ore (.#.#

    +upplements 1 of 3

    "A+ *iberty %ore (.#.# +upplements 1 of 3

    %',M* 8 "A+ *iberty %ore (.#.#

    +upplements of 3

    "A+ *iberty %ore (.#.# +upplements of 3

    %',39M* 8 "A+ *iberty %ore (.#.#+upplements 3 of 3

    "A+ *iberty %ore (.#.# +upplements 3 of 3

    %'MT&M* 8"A*I$untimeIArchiveI*%IC(.#.#

    "eb+phere Application *iberty $untime ArchiveB for *iberty%ore C(.#.#D

    %'MT4M* 8 "eb+phere Application *iberty-

  • 8/17/2019 Kolbans Worklight Book 2014 09

    19/298

    C:\IBM\Worklight

    to serve as the root of my "orklight installations. ' then e Istall !e" #o$t"are%%%?

    Page 1/

  • 8/17/2019 Kolbans Worklight Book 2014 09

    20/298

    . A!! a new repository to install.

    3. +elect the 'P file containing "orklight +tu!io. As &.1.9B this is the file CI&'P(!%)ip.

    . +elect the features to install

    Page 9

  • 8/17/2019 Kolbans Worklight Book 2014 09

    21/298

     Note that it is essential that the -clipse environment have 'nternet connectivity as installation of

    "orklight +tu!io will also re)uire the installation of pre:re) -clipse components not !istribute!

    with the base -clipse environment. This will likely mean connecting to the 'nternet to access the

    -clipse framework !ownloa!s. ont try an! install "orklight +tu!io unless you are 'nternet

    connecte!.

    0nce selecte!B click !e*t.

    #. $eview the parts

    Page 1

  • 8/17/2019 Kolbans Worklight Book 2014 09

    22/298

    &. Accept the license agreement

    Page

  • 8/17/2019 Kolbans Worklight Book 2014 09

    23/298

    '2M "orklight +tu!io will now install.

    4. -clipse will now restart.

    +ee alsoK

    • "orklight +tu!io

     Installing an Android !D" #clipse Plugin

    'f you are going to be buil!ing An!roi! applicationsB you will likely wish to install the An!roi!

    +, tools into the same -clipse environment as the "orklight +tu!io environment.

    1. +tart -clipse

    . @o to Help > Istall !e" #o$t"are

    3. %lick ?Add? to A!! a new source

    Page 3

  • 8/17/2019 Kolbans Worklight Book 2014 09

    24/298

    . efine the AT

    As of 913:11:11 8 the location for the plugin isK

    httpsKHH!l:ssl.google.comHan!roi!HeclipseH

    +ee the following web page for vali!ation an! !etailsK

    'nstalling the -clipse Plugin

    #. 'nstall the An!roi! evelopment Tools

    Page

    https://dl-ssl.google.com/android/eclipse/http://developer.android.com/sdk/installing/installing-adt.htmlhttps://dl-ssl.google.com/android/eclipse/http://developer.android.com/sdk/installing/installing-adt.html

  • 8/17/2019 Kolbans Worklight Book 2014 09

    25/298

    5ou may see a security warning similar to the followingK

    This is e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    26/298

    this port number however it is easy to change.

     Installing Mobile Test Worbench for Worlight 

     Installing Worlight !er$er 

    The "orklight +erver runs on top of an Application +erver. A number of !ifferent flavors of

    hosting application server are supporte!K• "eb+phere Application +erver *iberty %ore

    • "eb+phere Application +erver 

    • Apache Tomcat

    'n a!!itionB "orklight +erver re)uires a !atabases for its own operation. +upporte! !atabase types

    areK

    • '2M 2

    • 0racle

    • My+=*

    • Apache erby embe!!e!D

    "orklight +erver is supplie! as an '2M 'nstallation Manager repository. 0nce the package has

     been !efine! as a repositoryB it can then be installe!.

    The first page we are presente! with !uring the installation is the obligatory license agreement. '

    Page &

  • 8/17/2019 Kolbans Worklight Book 2014 09

    27/298

    suspect that everyone simply says ?yeah yeah? an! clicks ne

  • 8/17/2019 Kolbans Worklight Book 2014 09

    28/298

     Ne

  • 8/17/2019 Kolbans Worklight Book 2014 09

    29/298

     Now we are being offere! the opportunity to configure our installation. The first )uestion asks

    whether or not we wish to install the Application %enter.

    Page /

  • 8/17/2019 Kolbans Worklight Book 2014 09

    30/298

    "e are now aske! what kin! of !atabase we wish to use.

    Page 39

  • 8/17/2019 Kolbans Worklight Book 2014 09

    31/298

    "e are now aske! for information on how to connect to the !atabase of the type we previouslyselecte!. This consists of entering the hostname an! port number as well as pointing to a ;2%

    !river for that !atabase.

    Page 31

  • 8/17/2019 Kolbans Worklight Book 2014 09

    32/298

    'n or!er to access the !atabaseB we nee! to specify a user we will use to connect.

    Page 3

  • 8/17/2019 Kolbans Worklight Book 2014 09

    33/298

    %$-AT- ATA2A+- APP%NT$ %0**AT- 7+'N@ +5+T-M PA@-+'- 34&(

    Page 33

  • 8/17/2019 Kolbans Worklight Book 2014 09

    34/298

     Now we specify which kin! of application server will be use! to host the "orklight +erver.

    Page 3

  • 8/17/2019 Kolbans Worklight Book 2014 09

    35/298

    'f installing into a "A+ N environmentB you must select the eployment Manager profile.

    Page 3#

  • 8/17/2019 Kolbans Worklight Book 2014 09

    36/298

    Page 3&

  • 8/17/2019 Kolbans Worklight Book 2014 09

    37/298

    Page 34

  • 8/17/2019 Kolbans Worklight Book 2014 09

    38/298

    Page 3(

  • 8/17/2019 Kolbans Worklight Book 2014 09

    39/298

    The servers hosting "orklight +erver shoul! be restarte!.

    -

  • 8/17/2019 Kolbans Worklight Book 2014 09

    40/298

     Ne

  • 8/17/2019 Kolbans Worklight Book 2014 09

    41/298

     Now we select where on the file system we wish to install the pro!uct co!e. 'n my e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    42/298

     Ne

  • 8/17/2019 Kolbans Worklight Book 2014 09

    43/298

    0ne final check before install continues.

    Page 3

  • 8/17/2019 Kolbans Worklight Book 2014 09

    44/298

    An! at the en!B we have installe! the pro!uct.

    Page

  • 8/17/2019 Kolbans Worklight Book 2014 09

    45/298

    %ther Installation Tass

    >ollowing the installation of "orklight componentsB other installation tasks may be performe!.

    • ;ava runtime for browsers 8 A number of browser components use! by "orklight rely upon

    ;ava. This may be !ownloa!e! from www.6ava.com.

    • 7serAgent switcher 8 The mobile test environment re)uires the installation of the

    7serAgent switcher. +eeK

    'nstalling the 7serAgent +witcher -

  • 8/17/2019 Kolbans Worklight Book 2014 09

    46/298

    Sources of Information

    The InfoCenter 

    '2Ms 'nfo%enter is the primary source for knowle!ge on "orklight. 't is the on:line

    !ocumentation for the pro!uct. 't can be freely accesse! at anytime whether or not one has

     purchase! the pro!uct. 't can be foun! hereKhttpKHHpic.!he.ibm.comHinfocenterHwrklightHv&r9m9Hin!e'P+ 19: TTP+ encryption for '2M "orklight mobile apps  8 913:9/:

    • %reate a mobile 2PM application by integrating '2M "orklight an! '2M 2usiness Process Manager   8 913:9(:(

    • eliver an e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    47/298

    application with "eb+phere Portal pages 8 913:9(:94

    • Prototype mobile applications built with '2M "orklight for '2M "atson  8 913:9(:9#

    • 7sing the '2M "orklight optimization framework to buil! a cross:platform mobile application for multiple !evices 8 913:94:14

    • +erver:si!e mobile application !evelopment with '2M "orklightK Part . 'ntegrate the '2M "orklight a!apter with +%A 1.1 services 8

    913:9&:1(

    • '2M "orklight server configuration for >'P+ 19: vali!ation an! certificationB Part K eploying your mobile app on "eb+phere

    Application +erver   8 913:9&:1

    • '2M "orklight server configuration for >'P+ 19: vali!ation an! certificationB Part 1K %onfiguring a server:si!e "eb+phere Application

    +erver infrastructure  8 913:9#:(

    • +erver:si!e mobile application !evelopment with '2M "orklightK Part 3. 'ntegrate the '2M "orklight a!apter with $-+Tful services  8913:9#:1

    • Automate the !eployment of an '2M "orklight customization "A$ file on '2M "eb+phere Application +erver   8 913:9#:9

    • +erver:si!e mobile application !evelopment with '2M "orklightK Part . '2M "orklight a!apter integration with web service business

    logic  8 913:9#:94

    • +erver:si!e mobile application !evelopment with '2M "orklightK Part 1. '2M "orklight a!apter integration with ;ava business logic  8

    913:9:39

    • eliver an e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    48/298

    Application Development

    Worlight !tudio

    "orklight +tu!io is the -clipse base! '- for buil!ing "orklight pro6ects. 't can be launche! by

    starting the -clipse framework into which you installe! the "orklight +tu!io environment.

    "hen ' buil! "orklight pro6ectsB ' choose to create a new win!ows fol!er for each pro6ect. 'n thatfol!erB ' create a new fol!er calle! ?Work#pace?. This is where the artifacts ' will buil! will

    resi!e.

     Ne

  • 8/17/2019 Kolbans Worklight Book 2014 09

    49/298

    +ee alsoK

    • 'nstalling "orklight +tu!io

    Creating a Worlight Pro)ect 

    0ne of the first things we will !o when buil!ing a new solution is create a new "orklight Pro6ect.This is performe! within "orklight +tu!io.

    "e are now given the choice of buil!ing one of four types of solutionK

    • ybri! Application 8 An application that can be e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    50/298

    "ithin the pro6ect we have a fol!er calle! ?apps?. 't is within here that we will have a fol!er for

    each in!ivi!ual app within the pro6ect. Note that this implies a single pro6ect can contain multiple

    apps.

    "ithin a specific app fol!erB we have another fol!er calle! ?common?. This contains artifacts that

    are to be common between multiple !eployment environments. The types of artifacts we will be

    working with inclu!eK

    • TM*

    • %++

    • ;ava+cript

    • 'mages

    "hen we create a pro6ectB a set of !efault artifacts are create! for us un!erneath the appK

    Page #9

  • 8/17/2019 Kolbans Worklight Book 2014 09

    51/298

    There areK

    ile Description

    co,,ocss%cssco,,oi,agesico%pg

    co,,oi,agesthu,bail%pg

    co,,o.s%.s

    co,,o.siit/ptios%.s

    co,,o.s,essages%.s

    co,,o%ht,l

    legallicese%t*t

    applicatio-descriptor%*,l %ontains application meta!ata.

    build-settigs%*,l

    An App fol!er will also contain fol!ers for each platform targete!. These inclu!eK

    • an!roi!

    •  blackberry19

    •  blackberry

    • ipa!

    • iphone

    • win!owsphone(

    • win!owsphone

    • air 

    • !esktopbrowser

    • mobilewebapp

    • win!ows(

    Page #1

  • 8/17/2019 Kolbans Worklight Book 2014 09

    52/298

     Application Descriptor 

    The Application escriptor is an GM* file containe! within the application portion of the pro6ect

    that has the file name ?applicatio-descriptor%*,l?. "orklight +tu!io provi!es a rich

    e!itor for working with its content but it can also be eor e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    53/298

    >rom thereB a !ialog will be presente! where one or more of the target environments can be a!!e!K

    Worlight De$elopment !er$er 

    A copy of the "orklight +erver hoste! by the "eb+phere Application +erver *iberty %ore is

    Page #3

  • 8/17/2019 Kolbans Worklight Book 2014 09

    54/298

    supplie! an! configure! with "orklight +tu!io. 't can be seen within the +ervers viewK

    The applications !eploye! to it are also shown.

     De$eloping *I + Rich Page #ditor 

    The primary !evelopment component within +tu!io for buil!ing user interfaces is the ?$ich Page

    -!itor?. This e!itor provi!es the ability for the programmer to buil! TM* either visually through

    a !rag an! !rop mechanism or in an TM* source e!itor. 2y !efaultB the $ich Page -!itor isstarte! when an TM* file is re)ueste! to be opene!. 't can also be e 7ich Page (ditor? option.

    "hen an TM* file is opene!B the e!itor environment looks as followsK

    Page #

  • 8/17/2019 Kolbans Worklight Book 2014 09

    55/298

    The e!itor is full of features an! function. *et us try an! break some of these !own. The primary

    e!iting surface takes up the ma6ority of the area. 0ne can look at this area in esign mo!e a what:

    you:see:is:what:you:get mo!eD or a +ource mo!e raw TM*D or a +plit mo!e half the win!ow isesign Mo!e an! half is +ource Mo!eD. The choice of mo!es can be selecte! at the bottom left of

    the win!ow.

    'n +plit Mo!eB we can choose whether to split the win!ow horizontally or vertically. 2uttons on the

    menu bar select which is to be use!K

    To the right of the primary e!iting area is a ?palette? of items that can be inserte! into the page in

    !esign mo!e. The palette can be toggle on an! off using a menu bar buttonK

    2eneath the palette area is a Properties area. This too can be toggle! on an! off using another menu

     bar buttonK

    "hen working with !evices that can be physically oriente! from lan!scape to portrait mo!eB a

    menu bar button can be use! to show what the screen woul! like like if rotate!K

    "hen mo!eling against some !evicesB the screen size of the !evice may be too large to be shown in

    the esign area. "e can scale the screen to be shown in its entirety through a menu buttonK

    Page ##

  • 8/17/2019 Kolbans Worklight Book 2014 09

    56/298

    The implementation of the $ich Page -!itor relies on a browser being available on the 0+ running

    '2M "orklight +tu!io. Not all browser types are supporte!K

    "in!ows   • 'nternet -irefo<

    *inu<   • >irefo<• "ebkit

    Mac   • +afari

    The above !oes not mean that other browser types arent supporte! for use with a final applicationB

    rather these browsers are the ones use! !uring !evelopment time within the $ich Page -!itor.

    The "orklight client framework provi!es some a!!itions to any frameworks you may use. These

    inclu!eK

    • "*.2usy'n!icator 

    • "*.+impleialog

    • "*.Tab2ar 

    • "*.0ptionsMenu

    "hen buil!ing a mobile appB it is common for the app to contain multiple ?views? or pages of !ata.

    The Mobile Navigation win!ow shows the !efine! views within the application an! which one is

    currently visible in the canvasK

    %licking on a !ifferent view changes the visible view in the canvas. %hanging view also changes

    the source view to the start to the view !efinition.

    The ?plus? button allows us to a!! a new instance of a view. "hen selecte!B a new !ialog win!ow

    appears. >rom here we can select the creation of the new view from a set of pre!efine! 7' patternsor simply create an empty view.

    Page #&

  • 8/17/2019 Kolbans Worklight Book 2014 09

    57/298

    The ne

  • 8/17/2019 Kolbans Worklight Book 2014 09

    58/298

    'f we choose to set the view as the !efaultB any previously selecte! !efault view will have its !efault

    attribute remove!.

    Another important win!ow in the $ich Page -!itor is the 0utline win!ow. This shows a

    hierarchical tree structure of your TM* !ocument. >rom there you can select elements from the

    list an! they become selecte! in both the visual an! source e!itors.

    Page #(

  • 8/17/2019 Kolbans Worklight Book 2014 09

    59/298

    Designing visually

    'n the $ich Page -!itors visual mo!eB a palette of available TM* an! "i!gets can be seen in the

    right han! si!e of the win!ow.

    The palette is split into category fol!ers correspon!ing to the wi!get sets that you have chosen to be

     part of the pro6ect.

    • TM* Tags 8 The core TM* elements

    • TM* >orm Tags 8 The core TM* form elements

    • o6o ata "i!gets 8 o6o wi!gets that rea! an! write !ata

    • o6o Mobile "i!gets 8 The ?!o6o

  • 8/17/2019 Kolbans Worklight Book 2014 09

    60/298

    itemB the position within the !ocument where the item will be inserte! is shown. $eleasing the

    mouse will insert the component. 'n a!!ition to !ragging a component into the visual canvasB a

    component can also be !roppe! in the source.

    -ach component a!!e! to the canvas may have a variety of properties associate! with it. A win!ow

    title! ?Properties? provi!es an visualization of these properties inclu!ing the ability to change their

    values.

    Coding in the HTML source

    The reality of buil!ing a 7' is that we can not buil! everything we nee! in the visual !esigner. "e

    will invariably have to buil! out parts of our solution in the te. This is the recommen!e! fol!er

    for hol!ing graphics components. "ithin the TM*B a reference to ?i,ages?

    will access the image.

    "hen buil!ing out mobile appsB it is common to want to fin! images to be use! in icons an!

     buttons. A goo! source for such is the 'con>in!er web site httpsKHHwww.iconfin!er.comH D. Always

    rea! the licensing agreements for any icons use!. The web site has the ability to filter on icons to

    fin! freeHunrestricte! items.

    Page &9

    https://www.iconfinder.com/https://www.iconfinder.com/

  • 8/17/2019 Kolbans Worklight Book 2014 09

    61/298

    %ff,line !torage

    0ne of the core architectural concepts that !istinguish mobile apps from other types of app is that

    they are only transiently connecte! to a network. There is no assurance that at any given time they

    have access to a network. 'f an application is reliant on !ata this can result in the application being

    unable to be use! while off:line. A solution to this is to provi!e off:line storage of !ata such thatwhen the application is on:lineB it can retrieve some set of !ata that the en! user can use to !o work

    an! save it locally. 'f the app subse)uently becomes network isolate!B the app can still work to

    some !egreeD using the local !ata that it previously store!.

    The Worklight J!"tore

    "orklight provi!es a concept calle! ;+0N+tore. This is a component that e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    62/298

    "ithin a ;+0N+tore one will fin! a set of ?ocuments?. This might be a confusing name as they

    shoul! not be consi!ere! !ocuments such as P>B "or! or -

  • 8/17/2019 Kolbans Worklight Book 2014 09

    63/298

    #sing the Mobile $ro%ser imulator 

    "orklight provi!es an application which runs in the browser that simulates a !evice. This can be

    use! to test your application without having to !eploy it to an actual !evice or !evice supplie!

    emulator.

    To launch the simulatorB open the conte Pre6ie"K

    't is not yet known why there are two menu entries both labele! Preview. A new browser win!ow

    will open showing a simulation of the applicationK

    Page &3

  • 8/17/2019 Kolbans Worklight Book 2014 09

    64/298

    "hen a browser runsB it provi!es an i!entification of what kin! of browser an! what environment it

    is running upon to the hoste! ;ava+cript application. This i!entity is calle! the ?7serAgent?.

    "hile working with the browser simulatorB we may wish to ?overri!e? the 7serAgent i!entity to

    simulate multiple platforms. To achieve thatB we nee! to enable 7serAgent switching. 'f we !o not

    enable user agent switchingB the simulator will only show iPhone styling.

    Installing the UserAgent Switcher Extension

    'f we wish the mobile browser simulator to be able to inform the application of a specific !evice

    typeB we must install the 7serAgent +witcher -

  • 8/17/2019 Kolbans Worklight Book 2014 09

    65/298

    %licking the ?Istall Bro"ser (*tesio? will !ownloa! the installer into the ownloa!s

    fol!er of your P%.

    To manually install this e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    66/298

    #. A new entry will appear in the %hrome -or the importB select >ile R 'mport from the menu an! then un!er the @eneral categoryB select

    ?-

  • 8/17/2019 Kolbans Worklight Book 2014 09

    67/298

    5ou can now select the 'P file that was previously e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    68/298

    At the conclusion of this stepB a new pro6ect can be foun! which will be the import of the previouse

  • 8/17/2019 Kolbans Worklight Book 2014 09

    69/298

    A!apters't is very common for a mobile app to interact with back:en! systems to retrieve informationB

    re)uest actions to be performe! or store new !ata. To achieve thisB the app must make a re)uest to

    the back:en!. 7nfortunatelyB this opens up a whole slew of challenges. ifferent back:en!s will

    support !ifferent communication protocolsB !ifferent security re)uirements an! more. -ach of these

    has to be co!e! to an! learne! an! can increase the time to buil! an! test applications.

    "orklight intro!uces the mo!el of the ?A!apter?. An a!apter is a server si!e component which

    listens for incoming re)uests from "orklight client applications. "hen an a!apter receives a

    re)uestB it then makes contact with the back:en! system to perform the re)uest on behalf of the app.

    -ffectively acting as a pro

  • 8/17/2019 Kolbans Worklight Book 2014 09

    70/298

    returns ;+0N then that !ata is left as:is. 'f the !ata returne! is something other than ;+0N then it is

    converte! into GM* an! then an G+* style sheet may be applie! to buil! ;+0N. >inallyB before

    sen!ing the result back to the clientB the a!apter can manipulate the final !ata.

    Creating a ne. Adapter 

    "hen we !esign a new mobile application that wishes to interact with a back:en! systemB we will

    create a new a!apter to achieve that goal.

    "ithin a "orklight pro6ect within "orklight +tu!ioB we select !e" > AdapterK

    "hen we create an a!apterB we !efine which pro6ect it is going to be containe! withinB what type of

    a!apter it will be an! the name of the a!apter to be create!.

    The types of a!apter available to us areK

    • TTP A!apter 

    • +=* A!apter 

    • ;M+ A!apter 

    • %ast 'ron A!apter 

     

    This will create the a!apter file system structure with the GM* configuration fileB ;ava+cript an!

    G+* which can then be mo!ifie! for specific access to a back:en!.

    Page 49

  • 8/17/2019 Kolbans Worklight Book 2014 09

    71/298

     Adapter Implementation

    An a!apter is implemente! by a set of artifacts. To be specificK

    • An a!apter configuration file in GM* "ithin this fileB a !escription of each of the

     proce!ures supplie! by that a!apter is !efine!.

    A ;ava+cript file. "ithin this file one will fin! an implementation of each of the proce!uresoffere! by the a!apter.

    • ero or more G+* files use! to convert back:en! !ata to ;+0N.

    An a!apter is the aggregation of each of the above an! is package! into a 'P file with a file type of 

    ?%adapter?.

    The GM* configuration file has the following general format

    %%%

    -ach  element can have a number of attributes.

    • a,e 8 The name of the proce!ure

    •  platformCersion

    • coectAs 8 +ecurity i!entity use! to connect to the back:en! system. %hoices areK

    ◦ server 

    ◦ en!7ser 

    • resposei,eoutI#ecods 8 ow long to wait for a back:en! response before

    timing out. The !efault is 39 secon!s.

    • audit 8 +houl! this a!apter be au!ite!J Calues are ?true? an! ?false?.

    • securityest 8 A test that can be performe! to protect the a!apter.

    • !ebugPort

    • run0nNo!e

    Although the GM* configuration file can be e!ite! within a te

  • 8/17/2019 Kolbans Worklight Book 2014 09

    72/298

    commonly interacting with the back:en! server through some other protocol.

    "hen we !efine the a!apterB we !efine one or more proce!ures that can be calle! by the client. >or

    each proce!ureB we nee! to create a correspon!ing function !efinition in the ;ava+cript. >or

    e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    73/298

    • protocol 8 The network protocol use! to connect to the back:en! server. The choices are

    either ?http? or ?https?. 7se http for un:encrypte! network traffic an! https for

    encrypte! network traffic using ++*. +ee %onfiguring the TTP A!apter for ++* for

    !etails on a!!itional consi!erations when using ++*.

    • do,ai 8 The network !omain name or 'P a!!ress of the server hosting the back:en!

    service.

    • port 8 The T%PH'P port number on which the back:en! TTP service is listening upon for

    incoming re)uests.

    • cookiePolicy

    • ma

  • 8/17/2019 Kolbans Worklight Book 2014 09

    74/298

    Configuring the HTTP Adapter for SSL

    "hen the TTP a!apter connects to the back:en! server it can utilize the TTP protocol over

    either plain T%P or ++*. To use ++* re)uires some setup.

    1. %hange the protocol type of the A!apters GM* configuration to ?https?.

    . %hange the port number to be that of the back:en! servers port for ++*.

    Example HTTP Adapter 

    0n the 'nternet there is an e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    75/298

    +ecurity consi!erations !oe

    $eturne! !ata format M+

    "e create a new a!apter that we call +enatorsK

    "e !elete the sample proce!ures associate! with it.

     Ne

  • 8/17/2019 Kolbans Worklight Book 2014 09

    76/298

    At this point we have a !efine! a!apter but no implementation for the server si!e proce!ure which

    calls the back:en! service. "e open up the ?#eators-i,pl%.s? implementation file for the

    a!apter. "e nee! none of the co!e template! by '2M. 'nstea! we co!e onlyK$uctio get#eatorBy#tate3state4

    6ar optios 0 1,ethod1: 1get11path1: 1getall@ses@bystate%php11returedCotetype1: 1*,l11para,eters1:

    1state1: stateD

    D2retur W+%#er6er%i6okeHttp3optios42

    D

    >inallyB in the %onnection Policy of the a!apter !efinitionB we supply the connection information

    for the server machineK

    Page 4&

  • 8/17/2019 Kolbans Worklight Book 2014 09

    77/298

    This completes our implementation. "e can now test the a!apter through +tu!io by selecting the

    a!apter an! running 7u As > I6oke Worklight ProcedureK

    Page 44

  • 8/17/2019 Kolbans Worklight Book 2014 09

    78/298

    This shows a !ialog in which the proce!ure name an! parameters may be supplie!.

    %licking the 7u button shows us the results of invoking the a!apter on the "orklight +erverK

    JM &dapter 

    The ;M+ a!apter allows a "orklight client to sen! or receive messages from a ;ava Message

    +ervice ;M+D )ueening provi!er. The ;M+ a!apter encapsulates all access to the ;M+ system sothat the client !eveloper nee! only invoke the a!apter without having to have knowle!ge of the

    un!erlying mechanics of ;M+ access.

    2efore we !ive !eeper into the a!apterB let us first review our un!erstan!ing of ;M+. ;M+ provi!es

    an abstraction to ;ava programmers who wish to access )ueuing systems. A variety of ven!ors

     provi!e )ueuing systems each of which are !ifferent. This woul! mean that a ;ava programmer

    wishing to use one woul! be boun! to that ;M+ provi!er. The ;M+ specification !escribes a ven!or 

    neutral set of interfaces that a ;ava programmer can use. 'n or!er for a ;ava application to be able

    to access the ;M+ provi!erB it nee!s two pieces of information. The first is calle! the ;M+

    %onnection >actory !efinition. This is a ;N' entry that points to a ;M+ provi!er supplie!

    configuration for accessing that ;M+ provi!er. The secon! !efinition is the i!entity of a ;M+ )ueue

    to which messages will be rea! or written. This is again !efine! through a ;N' !efinition.

    Page 4(

  • 8/17/2019 Kolbans Worklight Book 2014 09

    79/298

    "hen a ;M+ a!apter is !efine!B the connection policy looks as followsK

    'n the .,sCoectio settings we have entries forK

    • coectio5actory 8 The ;N' entry name use! to lookup the ;M+ connection

    factory that will be use! to connect to the ;M+ provi!er.

    • user 8 The useri! use! to connect to the ;M+ provi!er.

    pass"ord 8 The passwor! of the user use! to connect to the ;M+ provi!er.

    'n the naming%onnection settings we have entries forK

    • initial%onteactory

    •  passwor!

    • url

    • user 

    +ee alsoK

    • '2M "orklight v&.9.9 @etting +tarte! 8  ;M+ A!apter 8 %ommunicating with ;M+  8 913:94:/

    JS Adapter Procedure implementations

    0nce the a!apter has been !efine!B we can create proce!ure !efinitions. These will be the e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    80/298

    • "*.+erver.write;M+MessageoptionsD

    • "*.+erver.re)uest$eply;M+MessageoptionsD

    (L &dapter 

    The +=* a!apter allows a "orklight client to eor e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    81/298

    • Pass"ord 8 The passwor! for the user use! to connect to the !atabase.

    The !efinitions for the a!apter are save! in its GM* configuration file calle! %*,l.

    This will contain an GM* section calle!  un!er the

     element. >or e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    82/298

    Calling an adapter from the Client 

    >rom the client si!eB we can invoke an a!apter with "orklight provi!e! AP'K

    W+%Cliet%i6okeProcedure3i6ocatioEata optios4

    This is !escribe! in !etail on the AP' page for that function.

    +ee alsoK

    • "*.%lient.invokeProce!ureinvocationataB optionsD

    • A!apters

    Page (

  • 8/17/2019 Kolbans Worklight Book 2014 09

    83/298

     #rror 'andling for Adapters

    +ee alsoK

    • !eveloper"orks 8  -rror han!ling in '2M "orklight a!apters : 91:1:9#

     In$oing /a$a code from an Adapter "hen an a!apter is invoke! by the client a ;ava+cript routine is e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    84/298

    /. efine an a!apter proce!ure calle! ?get?reetig?

    19. 'n the A!apter;ava:impl.6s ;ava+cript fileB implement the ?get@reeting? functionK$uctio get?reetig3a,e4

    6ar adapterJa6aIstace 0 e" co,%kolba%AdapterJa6a3426ar greetig 0 adapterJa6aIstace%get?reetig3a,e42retur 1resp1: greetigD2

    D

    11. eploy the a!apter to the "orklight server 

    1. $un the a!apter test tool from +tu!io foun! in 7u As > I6oke Worklight

    ProcedureK

    Page (

  • 8/17/2019 Kolbans Worklight Book 2014 09

    85/298

    13. -rom the above output we see that the response now contains the te

  • 8/17/2019 Kolbans Worklight Book 2014 09

    86/298

    Application %enterAfter you have built your mobile applicationB your ne

  • 8/17/2019 Kolbans Worklight Book 2014 09

    87/298

     Installing the Application Center mobile client 

    Page (4

  • 8/17/2019 Kolbans Worklight Book 2014 09

    88/298

    Page ((

  • 8/17/2019 Kolbans Worklight Book 2014 09

    89/298

    The installer for An!roi! can be foun! in the file calle!K

    Q"orklight+erverRHApplication%enterHinstallerH'2MApplication%enter.apk 

    Page (/

  • 8/17/2019 Kolbans Worklight Book 2014 09

    90/298

    Page /9

  • 8/17/2019 Kolbans Worklight Book 2014 09

    91/298

    +ee alsoK

    • Application %enter 

    • $e!book 8 -nabling Mobile Apps with '2M "orklight Application %enter 8 $-P:#99#:99 : 913:9&:11

    Page /1

  • 8/17/2019 Kolbans Worklight Book 2014 09

    92/298

    PerformanceThe performance of solutions built with "orklight can be improve! via a number of !ifferent

    techni)ues.

     Minification

    "hen a "orklight solution containing ;ava+cript an! %++ is builtB part of the ?cost? of e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    93/298

    • $emove white spaces an! comments

    • @oogle %losure %ompile +imple 0ptimization

    'n a!!ition you can specify while files to inclu!e an! e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    94/298

     !ecure on,de$ice stored data

    The nature of a mobile !evice is that L it is mobile. This means it can be carrie! aroun! with you

    an!B as suchB can be lost by you. +ince mobile !evices are fre)uently lostB we have the concept that

    any !ata kept on that !evice may be accesse! by unwante! parties. To solve that problemB we have

    the option to encrypt sensitive !ata. This means that the !ata is converte! into an unintelligibleform an! if it became known in that stateB woul!nt be of any use to receiver.

    "orklight provi!es the ability to encrypt an! !ecrypt !ata an! have that !ata store! in either

    TM*# local storage or in the "orklight ;+0N+tore.

    +ee alsoK

    • 0ff:line +torage

    %ffline Authentication

    'f a mobile !evice is not network connecte! a user may still have to prove that they are who they

    claim to be before using an app. This is actually )uite easy to !o. 'f information is save! encrypte!

    to local storage when a users i!entity is prove! then when !isconnecte!B the keys to !ecrypt the

    !ata will only be known by the actual user.

     Pre$enting tampered apps

    A concern that nee!s to be a!!resse! is the notion that an app can be tampere! with by a malicious

     programmer. This coul! happen in a number of ways. Perhaps the app was replace! on the !evice

    while it was out of your !irect control. Perhaps the app that you !ownloa!e! was from a fake

    repository. -ither wayB you coul! be tricke! into thinking you are running a legitimate app when in

    fact it is a trap.

    "orklight can !etect a tampere! app by signing the original app. "hen an app tries to contact

    "orklight +erver through an a!apterB it sen!s knowle!ge of whether or not it was mo!ifie! an!

    "orklight can !isallow mo!ifie! apps.

     Direct *pdate

    >or "eb an! ybri! "orklight applicationsB we have the ability to push up!ates to an app to the

    !evice transparently. This feature is calle! ?irect 7p!ate?.

     Remote Disable

    'f a version of an app is known to contain a security flawB access to "orklight server by apps of that

    version can be !isable!. -ffectively !isabling that version of the app.

    Worlight protected resources

    "orklight can protect the following types of resourcesK

    • Application

    • A!apter Proce!ure

    • -vent +ource 8 A re)uest to subscribe to a push notification

    • +tatic $esource

    Page /

  • 8/17/2019 Kolbans Worklight Book 2014 09

    95/298

    Cross site R#!T calls

    'f you are using the %hrome web browserB it has a comman! line option calle! ?--disable-

    "eb-security? that switches off web security +ame 0rigin PolicyD for that instance of the

     browser. This is useful for !evelopment but shoul! never be use! or suggeste! for pro!uction.

    5ou will know it is working because you will see a warning messageK

    +ee alsoK

    • TTP access control %0$+D

    • %ross:0rigin $esource +haring : 91:91:1&

     Programatically authenticating .ith WA! 

    "hen interacting with a "A+ serverB on many occasions the "A+ server has to know who we are

    in or!er to allow us to interact.

    +ee alsoK

    • 7sing the ;ava Authentication an! Authorization +ervice programming mo!el for web authentication

    Application Deplo"ment0nce you have built a "orklight applicationB you are very likely going to want to !eploy this for

    e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    96/298

    !b +-T %7$$-NT +%-MA "$,+%M

    !b :vf QworklightIinstallI!irRH"orklight+erverH!atabasesHcreate:worklight:!b.s)l :t

    . %reate a !ata source for the "orklight !atabase

    Page /&

  • 8/17/2019 Kolbans Worklight Book 2014 09

    97/298

    Page /4

  • 8/17/2019 Kolbans Worklight Book 2014 09

    98/298

    Page /(

  • 8/17/2019 Kolbans Worklight Book 2014 09

    99/298

    #. %reate the "orklight $eports atasource

    Page //

  • 8/17/2019 Kolbans Worklight Book 2014 09

    100/298

    Page 199

  • 8/17/2019 Kolbans Worklight Book 2014 09

    101/298

    &. %reate the "0$,*'@TI'N+TA**I'$ variable

    4. efine a new share! library entry

    Page 191

  • 8/17/2019 Kolbans Worklight Book 2014 09

    102/298

    (. !

    /. !

    19. !

    11. !

    1.

    13. s

    1. s

    &perationsAfter having installe! an! configure "orklight an! built applications for !istributionB it is likely

    that you will want to operate an! maintain a variety of components inclu!ing "orklight +erver.

    Areas to be consi!ere! inclu!ing backing up the system for recoveryB performance tuningB security

    consi!erations

    Programming 'eferences

    Page 19

  • 8/17/2019 Kolbans Worklight Book 2014 09

    103/298

    Client !ide API Programming 

    A ;ava+cript ob6ect calle! ?W+? is create! by the "orklight framework. This can then be use! as

    the root or name:space for all other functions.

    WL)Client

    The ;ava+cript ob6ect calle! ?W+? contain a chil! ob6ect calle! ?Cliet? which acts as a container 

    for a set of metho!s relate! to client si!e functions. The following act as a gui!e an! notes on some

    of the functions available.

    The common &options& o"'ect 

    Many of the functions !ocumente! here accept an ?options? ob6ect. This ob6ect is common

    amongst many of the asynchronous calls. This ob6ect contains the following propertiesK

    • o#uccess 8 A callback function that receives a ?response? ob6ect. The response ob6ect

    will contain amongst other itemsDK

    ◦ invocation%onte

  • 8/17/2019 Kolbans Worklight Book 2014 09

    104/298

    (L)Client)connect+options/

    This metho! forms a connection to the "orklight +erver. 't must be eor A!obe A'$ apps onlyB shoul! the app show in the task  bar.

    W+%AppProperty%H8MB!AI+@IMA?(@87+ An absolute 7$* for the thumbnail image for theapplication.

    (L)Client)getEn$ironment+/

    $eturns the environment in which the application is runningB possible values inclu!eK

    • "*.-nvironment.A02-IA'$ 

    Page 19

  • 8/17/2019 Kolbans Worklight Book 2014 09

    105/298

    • "*.-nvironment.AN$0'

    • "*.-nvironment.-M2--

    • "*.-nvironment.'PA

    • "*.-nvironment.'P0N-

    • "*.-nvironment.M02'*-I"-2

    • "*.-nvironment.P$-C'-"

    • "*.-nvironment."'N0"+IP0N-I(

    • "*.-nvironment."'N0"+IP0N-

    • "*.-nvironment."'N0"+(

    (L)Client)getLogin,ame+realm/

    $eturns the login name the user use! !uring authentication.

    • realm 8 JJJ

    +ee alsoK

    • "*.%lient.get7serNamerealmD

    (L)Client)getUserInfo+realm- 0e1/

    $etrieve a property of the current use! name! by the key.

    • realm 8 JJJ

    • key 8 JJJ

    (L)Client)getUser,ame+realm/

    $etrieve the real name of the current user.

    • realm 8 JJJ

    +ee alsoK

    • "*.%lient.get*oginNamerealmD

    (L)Client)getUserPref+0e1/

    $etrieve a user preference by key. 'f no preference is known for that keyB null is returne!.

    • key 8 JJJ

    +ee alsoK

    • "*.%lient.has7serPrefkeyD

    • "*.%lient.set7serPrefkeyB valueB optionsD

    • "*.%lient.set7serPrefsprefsB optionsD

    (L)Client)hasUserPref+0e1/

    etermine if there is a user preference for the supplie! key

    Page 19#

  • 8/17/2019 Kolbans Worklight Book 2014 09

    106/298

    • key 8 JJJ

    +ee alsoK

    • "*.%lient.get7serPrefkeyD

    • "*.%lient.set7serPrefkeyB valueB optionsD

    • "*.%lient.set7serPrefsprefsB optionsD

    (L)Client)init+options/

    'nitialize the "orklight client environment. This metho! shoul! be calle! before any other

    W+%Cliet function. 't is commonly calle! in the ?iit/ptios%.s? ;ava+cript file.

    • optios 8 The options !efining the initialization of the "*.%lient environment

    ◦ ti,eout 8 The timeout in millisecon!s for all calls to the "orklight server. 'f not

    supplie!B a timeout of 39 secon!s is use!.

    ◦ eable+ogger 8 %ontrols whether or not W+%+ogger%debug34 output will be

    logge!. +ettings this to ?true? !efaultD causes !ebug output to appear in the appropriatelog.

    ◦ ,essages 8 A !ictionary ob6ect for localizing message te

  • 8/17/2019 Kolbans Worklight Book 2014 09

    107/298

    (L)Client)in$o0eProcedure+in$ocation!ata- options/

    'nvoke a proce!ure e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    108/298

    • realm 8 JJJ

    • options 8 JJJ

    (L)Client)logout+realm- options/

    A function which when calle! will logout the user.

    • realm 8 JJJ

    • options 8 JJJ

    (L)Client)minimi2e+/

    Minimize a wi!get when A!obe A'$ is use! as the !eployment target.

    (L)Client)reloadApp+/

    $eloa! the whole application.

    (L)Client)remo$e*lo"alHeader+header,ame/

    $emove an TTP hea!er !efinition sent to the "orklight server by this client application. The

    hea!er woul! previously have been a!!e! by a call to "*.%lient.a!!@lobalea!erD.

    • header!a,e 8 The name of the hea!er property to remove.

    +ee alsoK

    • "*.%lient.a!!@lobalea!erhea!erNameB hea!erCalueD

    (L)Client)setHeart#eatInter$al+inter$al/

    +et the interval to be use! to check connectivity between the client an! the "orklight server. The

    value is supplie! as the number of secon!s.

    +ee alsoK

    • "*.%lient.initoptionsD

    (L)Client)setUserPref+0e1- $alue- options/

    +et or change a name! property for a user to a specific value. There are a ma

  • 8/17/2019 Kolbans Worklight Book 2014 09

    109/298

    (L)Client)setUserPrefs+prefs- options/

    +et multiple properties for a user in one single call.

    •  prefs 8 A ;ava+cript ob6ect where the names of the properties in the ob6ect will be use! as

    the names of the properties to be create! an! the correspon!ing values in the ob6ect use! as

    the values of the properties.

    • options 8 JJJ

    +ee alsoK

    • "*.%lient.get7serPrefkeyD

    • "*.%lient.has7serPrefkeyD

    • "*.%lient.set7serPrefkeyB valueB optionsD

    (L)Client)updateUserInfo+options/

    $efreshes the !ata that will be returne! byK

    "*.%lient.get7serNamerealmD• "*.%lient.get*oginNamerealmD

    • "*.%lient.is7serAuthenticate!realmD

    +ee alsoK

    • "*.%lient.get7serNamerealmD

    • "*.%lient.get*oginNamerealmD

    • "*.%lient.is7serAuthenticate!realmD

    (L)#us1Indicator+containerId- options/

    This function will show a ?2usy? bo< on the screen which contains some teor e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    110/298

    6ar busy 0 e" W+%BusyIdicator3ull 1te*t1: 1IO, Busy1D42busy%sho"342

    0n an An!roi! !evice this will show asK

    (L)Toast)show+message/

    >or An!roi! onlyB shows a ?Toast? message.

    "*.%lient.init

    "*.%lient.reloa!App"*.%lient.login

    "*.%lient.logout

    "*.%lient.get-nvironment

    "*.%lient.set7serPref 

    "*.%lient.set7serPrefs

    "*.%lient.get7serPref 

    "*.%lient.!elete7serPref 

    Page 119

  • 8/17/2019 Kolbans Worklight Book 2014 09

    111/298

    "*.%lient.has7serPref 

    "*.%lient.logActivity

    WL)J!"tore

    The "*.;+0N+tore functions provi!e access to the ;+0N+tore AP's.

    (L)JS3,Store)add+data- options/

    The a!!D metho! a!!s a new !ocument into the collection.

    • !ata 8 A ;ava+cript ob6ect or array of ob6ects that will be a!!e! to the collection

    • options 8 A ;ava+cript ob6ect that provi!es options to the a!!D metho!K

    ◦ a!!itional+earch>iel!s

    ◦  push

    The a!!D metho! returns a Promise.

    (L)JS3,Store)changePassword+oldPassword- newPassword- user,ame/

    The changePasswor!D metho! changes the passwor! on a collection.

    • ol!Passwor! 8 The original passwor! of the new collection.

    • newPasswor! 8 The new passwor! of the collection.

    • userName 8 The i!entity of the user changing the passwor!.

    The changePasswor!D metho! returns a Promise.

    (L)JS3,Store)closeAll+/

    %lose access to all currently opene! collections.

    (L)JS3,Store)count+/

    etermine the number of !ocuments insi!e a given collection.

    The countD metho! returns a Promise.

    (L)JS3,Store)destro1+/

    $emoves all ;+0N+tore information for the application inclu!ing storesB collectionsB !ocuments

    an! meta:!ata.

    (L)JS3,Store)documentif1+id- data/

    @iven a !ocument ' an! a ;ava+cript ob6ect representing !ataB a ;+0N+tore !ocument instance is

    create!.

    • i! 8 The i! of a !ocument

    • !ata 8 A ;ava+cript ob6ect representing !ata

    The !ocumentifyD metho! returns a ;+0N+tore !ocument ob6ect.

    Page 111

  • 8/17/2019 Kolbans Worklight Book 2014 09

    112/298

    (L)JS3,Store)enhance+name- func/

    This function will a!! a name! metho! to the prototype of %ollections effectively e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    113/298

    (L)JS3,Store)getErroressage+errorCode/

    $etrieve a string representation of a ;+0N+tore error !escribe! by the error%o!e parameter.

    • error%o!e 8 The error co!e for which we wish the teiel!s 8 escription of which fiel!s are in!eiel!s 8 escription of which fiel!s are in!e

  • 8/17/2019 Kolbans Worklight Book 2014 09

    114/298

    ◦ clear 

    ◦ localkeyge 8 'f a passwor! is supplie! an! encryption to be use!B a token is

    obtaine! as part of the encryption process. "here the token is generate! is controlle! by

    this parameter. The token can be generate! on the client trueD or on the server falseD.

    The initD metho! returns a promise.

    (L)JS3,Store)isPush5e4uired+doc/

    etermines whether the given !ocument has ha! changes ma!e to it which woul! be pushe! to the

    server. $eturns true if it woul! be pushe! an! false otherwise.

    • !oc 8 -ither a !ocument ob6ect or a !ocument i!

    The isPush$e)uire!D metho! returns a promise.

    (L)JS3,Store)load+/

    'nvoke the associate! a!apter to loa! the content of the collection from the !ata returne! from thea!apter.

    The loa!D metho! returns a promise.

    (L)JS3,Store)push+docs/

    Push the !ocuments in the collection that are flagge! as rea!y for a push to the a!apter. 0ptionallyB

    an array of !ocuments or a !ocument or a !ocument i! can be supplie!.

    The pushD metho! returns a promise.

    (L)JS3,Store)push5e4uiredCount+/etermine the number of !ocuments that will be pushe! to a back:en! through an a!apter.

    The push$e)uire!%ountD metho! returns a promise.

    (L)JS3,Store)remo$e+doc- options/

    This function will remove a !ocument from a collection an! optionally flag it for push to remove

    through the a!apter.

    • !oc 8 An array of !ocumentsB a single !ocument or a !ocument i!

    options◦  push 8 shoul! the removal also be pushe! through the a!apter trueD or 6ust remove!

    from the local collection falseD.

    The removeD metho! returns a Promise.

    (L)JS3,Store)remo$eCollection+/

    eletes all the !ocuments store! within a collection.

    The remove%ollectionD metho! returns a Promise.

    Page 11

  • 8/17/2019 Kolbans Worklight Book 2014 09

    115/298

    (L)JS3,Store)replace+doc- options/

    $eplace !ocuments within a collection with !ifferent versions.

    • !oc 8 A single !ocument or an array of !ocuments

    • options

    ◦ psuh 8 A flag that controls whether or not the replacement shoul! be pushe! through tothe back:en! through the a!apter.

    The replaceD metho! returns a Promise.

    (L)JS3,Store)toString+/

    *ogs the !ocuments in the collection to the !ebugger log by invoking "*.*ogger.!ebug.

    WL1De$ice

    WL)Device)get"et%orkInfo*callback+

    $etrieves network information for i0+ or An!roi! !evices. The single parameter is a callback

    function that is passe! an ob6ect that !escribes the properties. This function is only available for

    An!roi! an! i0+ !evices.

    The pr