Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User...

44
Mobile and IBM Worklight Best Prac6ces WebSphere User Group, Edinburgh, 24 th Sept 2013 Andrew Ferrier [email protected] Contribu6ons from: Nick Maynard Sean Bedford Jon Marshall and others….

Transcript of Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User...

Page 1: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Mobile  and  IBM  Worklight  Best  Prac6ces  

WebSphere  User  Group,  Edinburgh,  24th  Sept  2013    

Andrew  Ferrier  [email protected]  

 Contribu6ons  from:  

Nick  Maynard  Sean  Bedford  Jon  Marshall  and  others….  

 

Page 2: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Agenda  

•  Recap:  Web  2.0  &  Mobile  Landscape  •  Development  Time  

– Toolkits  &  Frameworks  

•  “Run”  Time  – RESTful  Services  and  WL  Adapters  – Worklight  Lifecycle  –  Build,  Test,  Deploy  

•  Updates/Other  Best  Prac<ces  

Page 3: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Web  1.0:  what  we  used  to  do  l  Sta6c  HTML  content,  liXle-­‐to-­‐no-­‐dynamicity  

l  Server-­‐side-­‐driven  content  l  Perhaps  with  a  small  amount  of  JavaScript  for  effects  or  form  valida6on  

l  Tradi6onally  wriXen  with  a  variety  of  technologies  –  Servlets,  JSPs,  PHP,  etc.  

Page 4: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Embrace  Web  2.0  

l  Server-­‐side-­‐driven  content  

l  J2EE,  Servlets,  JSPs,  PHP,  etc.  

l  Rich  client-­‐side  JavaScript  

l  XHRs  for  data  over  RESTful  Services  

l  JSON  Payloads  

Page 5: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Hire  the  Skills  Needed!    (The  Programming  Model)  

Page 6: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Understand  the  Mobile  Landscape  

Page 7: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Understand  Worklight  

Na6ve  Shell  

Web  Code  

<!DOCTYPE  html  PUBLIC  <html>  <!  -­‐  -­‐  created  2003-­‐12-­‐1  <head><6tle>XYZ</6tle  </head>  </body>  </html>  

Device  APIs  

Page 8: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Understand  Worklight  En

terp

rise

Bac

kend

Sys

tem

s &

C

loud

Ser

vice

s

Worklight  Server  

User authentication and mobile trust

Mashups and service composition

JSON Translation

Adapter Library for backend connectivity

Stat

s A

ggre

gatio

n

Unified Push Notifications

Client-Side App Resources

Direct Update

Mobile Web Apps

Device  Run<me   Cross-Platform Compatibility Layer

Encrypted and Syncable Storage

Runtime Skinning

Server Integration Framework

Reporting for Statistics and Diagnostics

App

licat

ion

Cod

e

HTML5, Hybrid, and Native Coding

Optimization Framework

Integrated Device SDKs

3rd Party Library Integration

Bui

ld E

ngin

e

Worklight  Studio  

Worklight  Console  

Push /SMS Management

Reporting and Analytics

App Version Management

Public App Stores

Worklight  Applica<on  Center  

Development Team Provisioning

App Feedback Management

Enterprise App Provisioning and Governance

Blackberry

Android

iOS

Windows Phone

Java ME

Windows 8

SDKs

Mobile Web

Desktop Web

1 2 3

4

5

Page 9: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

TOOLKITS  AND  FRAMEWORKS  

Page 10: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Use  a  Toolkit  

•  JavaScript-­‐based  libraries,  wri3en  in  JavaScript,  used  on  top  of  JavaScript  itself  

•  Why?  – Smooth  out  the  JavaScript’s  rough  edges  – Add  addi6onal  features,  UI  widgets,  etc.  

Page 11: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Use  Dojo  

•  The  largest  players  in  the  market  are  

•  Generally,  IBM  ‘prefers’ Dojo  – Shipped  with  IBM  Worklight,  WebSphere  Feature  Pack  for  Web  2.0  and  Mobile,  etc..  

Page 12: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Why  Dojo?  •  Enterprise-­‐grade  toolkit  and  feature  set  •  Stronger  support  for  structuring  large  applica6ons  – e.g.  Class  system  (dojo/declare)  

•  BeXer  focus  on  interna6onaliza6on,  accessibility,  etc.  

•  But  jQuery  is  a  supported  choice  too  for  Worklight  and  s6ll  a  sensible  choice  

Page 13: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Consider  using  framework(s)  

•  Coding  without  a  JS  toolkit  in  2013  is  like  entering  the  program  in  binary  

•  Frameworks  sit  on  top  of  a  toolkit,  but  gives  you  other  things  that  are  missing.   HTML   CSS   JS  

Toolkit  

Framework  

Your  Applica6on  

Page 14: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Consider  using  framework(s)  

•  For  example,  a  framework  might  give  you:  – Endpoint  management  (stubbing)  – State  /  session  management  – Responsive  Design  Benefits  (e.g.  dojox/app)  – Templa6ng  – Single-­‐page  architecture  support  – Standardised  error-­‐handling  –  (…  other  applicaFon-­‐level  stuff)  

Page 15: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Framework  Op6ons  •  For  Dojo:  

– Dojo  itself  -­‐  dojox/mobile,  dojox/app,  dojox/mvc  

–  issw/mobile  &  issw/pocMobile  –  Your  own  custom  framework  

•  Not  as  bad  an  idea  as  it  sounds!  

•  For  jQuery:  – Angular  (MVW),  mustache  (templa6ng),  RequireJS  (code  loading),  Knockout  (MVC),  Backbone  (MVC),  Handlebar  (templa6ng)  etc...  

Page 16: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Prefer  Single  Page  Architecture  hXp://x.com/page1      

Submit  

hXp://x.com/page2        

HTTP  Server  

hXp://x.com/page1      

Submit  

HTTP  Server  

MPA   SPA  

Page  1   Page  2   Page  2  Page  1  

Page 17: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Prefer  Single  Page  Architecture  •  (…  for  mobile  at  least)  •  Only  one.html  page  •  Improves  performance  •  Dojo  Mobile  has  this  concept  built  in  –  dojox/mobile/View!

•  Reuse  this  concept  for  Hybrid  too  

Page 18: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Understand  Debugging  Op6ons        

•  iOS  6+:  Web  Inspector  (Physical  &  Emulated  Phone)  

•  Android  4.x:  Chrome  Remote  Debugging  

•  Desktop  Browser  with  Debugging  Support  –  Chrome,  Firefox  +  Firebug  (plain  or  Worklight  simulator)  

•  Worklight  logging  

•  Etc…  

Page 19: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

RESTFUL  SERVICES  AND  WL  ADAPTERS  

Page 20: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

RESTful  Services  

•  The  world  (at  least  UIs)  are  moving  to  simpler  services  – A  RESTful  style  -­‐  plain  HTTP  GET,  PUT,  POST,  DELETE  

–  JSON  as  the  data  format  

•  Prac6cally  mandatory  for  consump6on  by  Web  2.0  clients  

GET http://mycorp.com/customer/1234 { “name”: “Fred Bloggs”, “address”: “123 Anytown” }

 

Page 21: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

RESTful  Best  Prac6ces  for  Mobile  Web  

•  Use  verbs  liberally:  GET,  PUT,  POST,  DELETE  –  hXp://mycorp.com/services/createCustomer  

•  Keep  them  stateless  (independent)  •  Don’t  send  data  that’s  not  needed  

–  Keep  payloads  small  –  Combine  related  services  

•  Think  about  cacheability  •  Think  about  pagina6on  /  querying  /  sor6ng  

Page 22: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

WL  Adapters  

•  WL  adds  adapter  framework  –  Server-­‐side  JS  and  XML  components  

–  Client-­‐side  invoca6on  using  JS  API  

•  Supports  HTTP,  JMS,  SQL,  and  Cast  Iron  adapter  types  – Most  common  use  is  HTTP  adapter  to  integrate  with  JSON/REST  or  SOAP/HTTP  

Page 23: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

WL  Adapters  -­‐  REST  &  HTTP  

•  You  could  use  RESTful  services  directly  from  WL  container  with  conven6onal  XHRs,  but  you  lose:  – WL’s  authen<ca<on  mechanism  for  services  

– The  ability  to  use  the  WL  server  as  a  “choke  point”  

– WL  Logging/Audi6ng  – Analy6cs  integra6on  –  Tealeaf  usage  is  easier  

Page 24: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Re-­‐expose  even  RESTful  services  

•  Even  for  services  already  exposed  over  REST,  re-­‐expose  them  using  the  WL  HTTP  Adapter.  – This  is  compara6vely  straighqorward  to  do.  

•  You  can  also  use  SOAP  services  from  WL  – Abili6es  are  limited  at  the  moment  so  for  more  sophis6cated  scenarios,  consider  an  ESB  (e.g.  Cast  Iron)  

Page 25: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Consider  Service  &  Adapter  Versioning  

•  For  RESTful  Services:    URL:  /maps/version/2/map?...    Custom  HTTP  Header:  X-­‐Version  2.1    Media  Types/Content  NegoFaFon:  applica6on/

json;version=1  

•  Versioning  Worklight  Adapters  requires  renaming  them  

Page 26: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

LIFECYCLE  

Page 27: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Library  Systems  

•  Worklight  can  work  with  most  version  control  systems  that  integrate  with  Eclipse  

•  Common  choices:  – Ra6onal  Team  Concert  (packaged  w/  WL  as  IBM  Mobile  Development  Lifecycle  Solu6on)  

– Git  – Subversion  

Page 28: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Library  Systems  2  

•  There  are  files  that  must  be  excluded  as  they  are  part  of  WL  generated  resources,  see  here:  –  hXp://pic.dhe.ibm.com/infocenter/wrklight/

v6r0m0/index.jsp?topic=%2Fcom.ibm.worklight.help.doc%2Fdevref%2Fr_integra6ng_with_source_contro.html    

Page 29: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Building  –  Web  Components  

•  You  will  want  to  automate  your  build  (minifica6on)  

•  Worklight  Hybrid:  Consider  a  pre-­‐build  approach  for  your  web  code.  – Faster  dev  6me  turnaround  

•  Mobile  Web:  Consider  running  a  build  every  6me,  using  e.g.  Dojo  Build: http://dojotoolkit.org/reference-guide/1.9/build/  

•  Running  jslint  /  jshint  to  catch  JS  errors  

Page 30: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Building  

•  Then  build  WL  project  itself  •  WL  provides  the  <app-builder>  and  <adapter-builder>  ANT  tasks  – Only  builds  the  Server  por6on  of  the  projects  -­‐  the  .war  customisa6on  file,  the  .wlapp  file,  and  the  .adapter  files.  

–  You  will  need  to  build  the  .apk  and  .ipa  files  using  plaqorm-­‐na6ve  process.  

Page 31: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Building  

•  During  build,  externalise  certain  things:  – worklightServerRootUrl  in  application-descriptor.xml  

– server/conf/worklight.properties!– maxConcurrentConnectionsPerNode  for  adapters  

– domain,  port  for  the  backend  service  in  adapter.xml  

Page 32: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Deploying  

•  Deploy  the  .war  using  relevant  applica6on  server  method  – Whenever  server/conf/*  changes  

•  Deploy  the  .wlapp  and  .adapter  server-­‐side  por6ons  of  the  applica6on  using  <app-deployer>  and  <adapter-deployer>  ANT  tasks.  

Page 33: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Deployment  Topology  

•  Op6ons  include:  – WebSphere  ApplicaFon  Server  ND  -­‐  familiar  

– WAS  Liberty  Profile  –  simpler,  newer  

•  Consider  HTTPS,  load  spraying  

Page 34: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Deploying  to  Phones  

•  You  s6ll  need  to  get  the  na6ve  applica6on  (.ipa,  .apk,  etc.)  onto  your  user’s  phones.  – Dev  Time/Small/Adhoc  Projects:  Manual  install  – Tes<ng  lifecycle:    AppCenter  -­‐  comes  with  WL  server  edi6ons  

•  Install  via  AppCenter  Web  or  AppCenter  App  

– B2C:  public  App  Stores  (Apple  App  Store,  Google  Play  Store)  

– B2E:  IBM  Endpoint  Manager  or  similar  

Page 35: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Tes6ng  

•  Typically  you’ll  want  to  test:  – Manual  UI  on  physical  phones  

•  Coverage  across  devices  – Automated  UI  -­‐  mocking  framework  and  automated  test  tool  

•  V6.0  -­‐  Mobile  Test  Workbench  for  Worklight  

–  (Worklight)  Adapters  /  (Mobile  Web)  REST  Services  -­‐  load  /  performance  /  func6onal  tests  -­‐  just  HTTP  

Page 36: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Ques6ons?  

Andrew  Ferrier  [email protected]  hXp://dojo6psntricks.com    

Page 37: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

UPDATES  

Page 38: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Two  Ways  to  Update  -­‐  Method  1  

•  Update  your  web  code  only  

•  Don’t  change  the  version  number  of  the  applica6on  

•  Redeploy  .wlapp  only  •  Implicitly  encourages  a  

“Direct  Update”  next  6me  client  connects.  

Page 39: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Two  Ways  to  Update  -­‐  Method  2  

•  Method  2:  – Update  web  code  and  custom  na6ve  code  

– Do  update  the  applica6on  version  number  

– Re-­‐release  via  binary  method  (App  Store,  etc.)  

Page 40: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Upda6ng  Worklight  Itself  

•  Upgrade  all  studio  instances  and  WL  environments  

•  All  apps  at  all  exis6ng  applica6on  versions  need  to  be  re-­‐built  (.war/.wlapp/.adapter)  

•  Re-­‐release  an  app  using  method  2  – Gets  new  Device  Run6me  onto  end-­‐users’  phones  

•  But  end-­‐users  can  con6nue  using  old  app;  wire  protocol  is  backward-­‐compa6ble  

Page 41: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

OTHER  TIPS  &  BEST  PRACTICES  

Page 42: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Client-­‐side  Worklight  

•  Hybrid  App:  Don’t  op6mize  for  size  of  the  client  like  you  would  do  for  Mobile  Web  

•  Nevertheless,  there  is  s6ll  a  browser  control  underneath  

•  Use  WL.Logger.{debug,error}  API,  logging  in  development  environment  is  customizable,  &  log  the  username  on  errors  

Page 43: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Client-­‐side  Worklight  

•  Understand  handling  errors  on  client-­‐side,  in  par6cular  adapter  invoca6ons:  –  hXp://www.ibm.com/developerworks/websphere/techjournal/

1212_paris/1212_paris.html?ca=drs-­‐    

•  Use  connectOnStartup: false,  with  WL.Client.Connect()  aver  startup  -­‐  gives  more  startup  control  – Must  be  done  for  use  of  direct  updates,  push  no6fica6ons,  authen6ca6on,  adapter  use  

Page 44: Mobile’and’IBM Worklight’ BestPrac6ces’ · Understand’Worklight’ Worklight-Server-User authentication and mobile trust Mashups and service composition JSON Translation

Server-­‐side  Worklight  JavaScript  

•  Discourage  use  of  more  than  one  adapter  –  Cannot  share  JavaScript  code  (can  share  Java  though)  

•  Again,  understand  how  to  handle  errors  from  adapter  invoca6ons  (same  ar6cle).  

•  Again,  use  WL.Logger  API  -­‐  has  various  levels  of  logging,  can  be  configured  on  server.  Log  the  username  on  errors.  – Note:  Log  level  control  is  currently  limited  with  WAS