Getting started with XPages and modernization: Cutting edge XPages modernization Who Am I? – A Member of the London Developer Coop (londc.com) – Four developers based in London • • • • Ben Poole Julian Woodward Mark Myers (me) Matt White – Developer from a support background – 12+ years on Domino, 15+ years in IT – Speaker at 3x Lotuspheres, 3x UKLUGs, 1x ILUG, 1 X BLUG What won’t we will be doing? – This is not an X-Pages introduction, as there are already hundreds of them – http://xpages101.net/ – http://notesin9.com/ – http://www10.lotus.com/ldd/ddwiki.nsf/dx/Tutorial-intro-toXPages.htm What we will be doing? – Showing you how to make Xpage applications as cutting edge as possible with 3rd party frameworks*. – Giving you example Code to take home and try for your self! * This session is extended from one I worked on with Martin Vereecken, Mark Leusink and Matt White for Blug Why 3rd Party? Q) IBM provides a perfectly good frame work called OneUI what's wrong with it? A) Nothing, OneUI has lots of advantages: – Professional and corporate looking – Easy to get started with – Native integration with XPages But… – All sites built using it tend to look the same so don’t WOW people (users now judge internal apps against the apps they use at home). – IBM updates are far slower than dedicated framework providers. – Difficult to customise. – Code is less than efficient (have a look yourself). OK so what is a Framework? – A Package that comprises of CSS, images and often Javascript – They Provide: – More diversity in the look and feel of applications – Faster evolution and adaptability – More FREE plugins and resources – Often greater buy in from internals development teams (they will have heard of them) How do I use one? – Import the CSS/JS files into the files resources of your NSF or Drag & drop to WebContent folder via Package Explorer, Then you can just reference them as resources in your XPages – You may need/want to disable OneUI – Create a new theme for your application and remove the "extends“ property: it will stop loading extra Dojo css-files – Optional if you want a clean slate you can disable Dojo as well by editing xsp.properties: xsp.client.script.libraries=none – Beware that server interaction (e.g. view pagers) will no longer work – If you disable OneUI or Dojo then it's likely that you won't be able to use the Extension Library Show me the code – I’m going to walk through a simple contacts application – Using jQueryUI, KendoUI and Twitter Bootstrap to see the differences. – Single Form with different data types, validation requirements – View of data using a table or grid – A chart showing contacts by their country – You can download the apps from – http://londc.com/ldc.nsf/XPagesFrameworks.rar jQuery UI – A suite of free widgets built on top of jQuery – The Domo app is also using another suite on top of that called JQWidgets – JQWidgets costs $699 for enterprise or $399 per developer – Modular like Dojo, so you need to know which JS files to include on each page jQuery UI: Demo Kendo UI – Is not free - $699 per developer – Just web is $399, Mobile is $199 or charts are $399 – Made up of a collection of widgets – Great charting – Not responsive per se, different frameworks for Web vs Mobile – Very easy to implement – Start to finish 3.5 hours Kendo UI: Demo Twitter Bootstrap – Open Source – – – – – Current darling of the Internet Supported by Twitter Uses jQuery so lots of plugins are available Very easy to customize Well documented – You have to develop your own XPages versions of controls (e.g. Date Picker, pager etc) – Based on CSS3 / HTML5 so doesn't look great in older browsers (IE8) – In the demo we’re going to see – Header Nav – Standard view customised with CSS - pager shows naff HTML from XPages / OneUI – Opening document from row click (new row methods in 9.0) – Validation (using built in functions) – Theme to control different fields (date picker) – Charts Using Google JS API 22 Twitter Bootstrap: Demo Choosing a Framework – What devices are you supporting? – Just IE? – Chrome / Safari / Firefox? – Mobile? – Is development time important? – No time? Use OneUI with the Extension Library controls – Do you have a design team? – Let a designer create a theme for your company – Are you happy with Dojo or do you want to use jQuery? – There are a lot of other frameworks out there – Sencha Touch, ExtJS (An upcoming darling), MooTools Final Thoughts – If you are buying a framework will you be OK if the company goes under? – Maintainability (see old Domino Apps)? – Is the desirer for cutting edge a one time push or a constant pressure? Resources Code: http://londc.com/ldc.nsf/XPagesFrameworks.rar JQueryUI http://jqueryui.com/ http://jqwidgets.com/ KendoUI http://kendoui.com Twitter Bootstrap http://twitter.github.com/bootstrap/ Questions How To Contact Me: Mark Myers Email: Mark@londc.com | Twitter: @stickfight | Skype: Stickfight | Blog: stickfight.co.uk Getting Started with Java: Starting Java in Domino Who Am I? – A Member of the London Developer Coop (londc.com) – Four developers based in London • • • • Ben Poole Julian Woodward Mark Myers (me) Matt White – Developer from a support background – 12+ years on Domino, 15+ years in IT – Speaker at 3x Lotuspheres, 3x UKLUGs, 1x ILUG, 1 X BLUG What we will be doing? – Showing Classic Domino Devs and Core Java people how to get Java things working on Domino and other IBM Stacks (time permitting) Why? – To help remove the biggest impediment on IBM stack development: “It works everywhere else how do I get it working on Domino/WAS?” – To enable you to hire/use People with Standard Java Skills for IBM stack development with as little pain as possible. Getting java libraries to work – Java’s current power lies in the millions upon millions of existing libraries – Even new languages are designed to be able to take advantage of them (e.g. Scarla) – However getting them to work seamlessly is often time consuming Getting java libraries to work – There are 4 basic ways to store java libraries on domino – In agents or code libraries – Directly in the NSF ( nearly always via the package explorer) – In the ext directory on the server . – OSGi – Getting java libraries to work: Inside agent's and domino code libraries Pros – Allows segregation - you can use versions of libs that would clash with existing libs used elsewhere – Libs are guaranteed to be there - rather than depending on the server being set up correctly – Helps prevent issues on older systems - a developer cleaning up/upgrading elsewhere is less likely to change them. – Cons – Slow - Every time the agent loads all the libs have to be loaded into memory – Memory hungry - multiple agents with the same jars all load them. – Memory limit - very large libs actually can crash the agent on load Getting java libraries to work: Directly in the NSF – Pros – Shallow learning curve for Pure Java developers introduced to Domino – Much better caching of JAR files – Cons – Introduces the conflicting Jar version issues that plague other Java platforms + IBM (hsssss) Getting java libraries to work: Directly in the NSF - XAgents An alternative to Traditional Agent - XAgents: XPages written so they run as agents – JARs and Java code attached directly to the database – Much better caching of JAR files – No UI, except for print statements (“write”, actually) – See: – http://www.wissel.net/blog/d6plinks/shwl-7mgfbn – http://www.mindoo.com/web/blog.nsf/dx/17.07.201110 1855KLEBRW.htm Getting java libraries to work: in the ext directory – Pros – Fast preloaded and libs are shared across all databases on the server. – Cons – Not Automatically deployed – files have to be manualy copied for ever server and replica – Contents wiped out on server upgrade – Requires good communication between devs and Admins (see next slides) Ext deployment zip #1 – A large number of Domino apps I develop solutions for seem to need a few jar files and more often than not these end up in the ext lib on the server (be that for speed/memory or conflict reasons) – Such apps are a sod to deploy for administrators particularly multi replica ones so I went and asked a top admins and this is the suggestion. Ext deployment zip 2 – EXT-XXXXXXXX-YYYYMMDD.ZIP – where XXXXXXXX is the name of the application (maybe a version number for the developer) and YYYYMMDD is the date the zip was added (yes include it despite the fact it will be in the files section as admin’s tend to store these things on the file system) – This file should contain: – An ‘Ext’ directory that contains the jar files you require – A java.policy file and any other files that need modifying containing the changes required – A “readme.txt” with you descriptions and justifications for the changes (enough justification so that the admin can take it to a manager if permission is needed) OSGi – Formally the Open Service Gateway Initiative now a trademark used to define the specifications for a module system and service platform ie. a nice way of deploying Apps – Definitive Presentation is SHOW112 by Paul Fiore: http://www.slideshare.net/fiorep/dominoosgi-development java.policy #1 – The java.policy file is a global default policy file shared by all of the Java programs running in the Java Virtual Machine it contains default permissions for all of the Java programs – Found in /IBM/Lotus/Notes/jvm/lib/security – Domino is rare in that this file often needs modifying, most commonly for external connections or altering how class loading is done – For development or debugging but NEVER EVER for live – grant { permission java.security.AllPermission; }; – Grants all permissions to all libs Example of a Troublesome Library – DOCX4J – Excellent Microsoft Document generation Library – Particularly good for when you want to generate documents based of existing Work Document templates – http://www.docx4java.org/trac/docx4j Example of a Troublesome Library docx4J + dependencies = 16.7 Meg Bundle Jar The Package contains 24 jars Example of a Troublesome Library: Attempt 1 1) All jars Loaded into a normal Script Library or directly into an Agent for POC 2) Agent run…. 3) Wait…..wait…..wait….. 4) OUT OF MEMORY….Agent crashes – Result: FAIL Example of a Troublesome Library: Attempt 2a 1) Bundle Jar added to the webContent\WebINF\LIB directory in the Package explorer* 2) Agent Code moved to Java Class in Package explorer* 3) Trigger Placed on Xpage 4) Xpage loaded and produces a old style “Error 500” with nothing in the Logs 5) After a clean and a rebuild it is discovered that ALL xpages are giving “Error 500” Result: WTF *An Example of this is shown in the Social business session Later Example of a Troublesome Library: Attempt 2b 1) As soon as the buddle Jar is removed all xpages start working again…. 2) Bundle is broken down to it individual Jars..which are added one at a time 3) Turns out that is a log4J-X.X.X.jar is loaded into the root of the db, it conflicts with Domino’s custom log4J, but Docx4J wont use Domino’s custom log4j…. Result: FSS.. Example of a Troublesome Library: Attempt 3a 1) Administrator Grovelled too and Bundle file is put on development server with a temporally “Grant All”…server restarted 2) Original Agent Saved without Java Library…Wont Save?? 3) Developer remembers that if you are using the ext directory then the Jar files must be on all machines that might use them….files coped to local machine and notes restarted 4) Code Works … Result: Horray Example of a Troublesome Library: Attempt 3b 1) Administrator Demands that we have individual settings in Java.Policy file 2) Grant All removed, Agent run and each security request dealt with. e.g. The Error “java.security.AccessControlException: access denied (java.lang.RuntimePermission getClassLoader)” Would require the line “permission java.lang.RuntimePermission "getClassLoader"; “ Example of a Troublesome Library: Attempt 3c The Error “error Access Denied (javax.xml.transform.TransformerFactory write)” Would require the line permission java.util.PropertyPermission "javax.xml.transform.TransformerFactory", "write"; Others reflect the quirks of the given library and you have to talk to the Library creators e.g. The Error “java.lang.IllegalAccessError: Class com.sun.xml.bind.v2.runtime.reflect.Accessor$FieldReflection can not access a member of class org.docx4j.relationships.Relationship with modifiers "protected" Needs permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; Web sphere Issues – ddd The top reason for Java Libraries not Working correctly in Websphere applications is the application being set to load Parent Classes First Web sphere Issues – Always have a second box (even if it’s a desktop pc) to ensure that the problem has not been fixed with a fix pack – IBM will always ask that you have all fix packs installed before doing ANYTHING – Websphere is a complex series of apps in its own right and sometimes they clash, Favourite example of a misleading error: http://www01.ibm.com/support/docview.wss?uid=swg24 032860 Summery – At least 30% of the time it WONT be your code and you are not doing anything daft. – If you are starting to get frustrated, start afresh with the simplest “hello world” you can for that library. – A second pair of eyes can save you from costly “face palms” – If you think it might be a genuine IBM issue and you can, open a PMR early while you investigate so that by the time you are truly stuck and need help IBM have finished with their red tape. Questions How To Contact Me: Mark Myers Email: Mark@londc.com | Twitter: @stickfight | Skype: Stickfight | Blog: stickfight.co.uk Getting Started with Java: org.openntf.domino The lotus.domino package on steroids Who Am I? – A Member of the London Developer Coop (londc.com) – Four developers based in London • • • • Ben Poole Julian Woodward Mark Myers (me) Matt White – Developer from a support background – 12+ years on Domino, 15+ years in IT – Speaker at 3x Lotuspheres, 3x UKLUGs, 1x ILUG, 1 X BLUG What is org.openntf.domino –It’s a project to wonderful wonderful people to stop domino Java being the laughing stock of the java world –By Nathan T Freeman, Jesse Gallagher, Tim Tripcony, Paul Withers, Declan Lynch and Rene Winklemeyer –https://github.com/OpenNTF/org.openntf.domino –http://www.openntf.org/internal/home.nsf/project.xsp?action=openDocument& name=OpenNTF%20Domino%20API *Quoted from the OpenNTF Website Project goals (1) * –Eliminate ham-fisted Exception handling in lotus.domino API by allowing static exception delegation –Modernise getters / setters to use Java standard interfaces –Modernise collection objects to implement Iterators where appropriate –Implement Maps & Collections using Domino data objects (e.g. Document implements Map) –Using MIME storage, allow any Serializable content to be stored in an Item –Correct methods which have dangerous side-effects (e.g.: View.isFolder() which builds the index if it didn’t already exist) *Quoted from the OpenNTF Website Project goals (2) * –Provide useful global convenience settings like alwaysUseJavaDates and alwaysStoreGMTTime –Provide useful static utility methods like incinerate(), toDxl() and toUnid(String) –Have some operations that currently throw Exceptions unnecessarily instead simply return null (e.g.: Database.getDocumentByUnid()) –Provide coherent content assist via Javadoc annotations and retention of parameter names in byte code *Quoted from the OpenNTF Website Current Java Recycling Exceptional –The entire Domino Java API implements just one exception type: NotesException –… and does so indiscriminately (does everything really have to throw an exception?) –The class also exposes non-standard attributes like .text rather than, say, getMessage() –org.openntf.domino normalises this behaviour (e.g. standard sub-classes like InvalidNotesUrlException) Logging –Adopts standard java.util.logging approach –Brings OpenLog into this world (see OpenLogHandler) –Usable logging properties out of the box Document == Map –Documents now with added Map! –… and also with added MIMEBean. So, this is cool: –List<String> aListNotAVector = new ArrayList<String>(); –aListNotAVector.add("See?"); –doc.replaceItemValue("SomeField", aListNotAVector); –… but this is even cooler: –doc.replaceItemValue("ThatDocOverThere", db.getDocumentByUnid(123…)); Wait… what? MIMEBean? –Java objects easily support serialization via the Serializable interface –Instead of coupling a complex form full of fields to an Xpage (or indeed any other object), why not store and retrieve the object itself? –For example, assuming our class MyObject implements Serializable, we could simply save an object created using this class thus: doc.replaceItemValue("SaveState", myObject); –Read more about MIMEBean from its originator, Tim Tripcony: –http://www.timtripcony.com/blog.nsf/d6plinks/TTRY-8NKTPN Content Assist –Far better to see this: –… than this! Fixing stuff –doc.hasItem(null) no longer kills servers! –Vector dodgyVector = new Vector(); –dodgyVector.add(null); –doc.replaceItemValue(dodgyVector); –… no longer blights Document.save() calls with spurious errors Standard Modern Java –Getters –Setters –Proper collections (forget while(doc != null…) –Use of generics –http://en.wikipedia.org/wiki/Generics_i n_Java –No more manual memory management –Proper JavaDoc + annotations == useful content assist The Future – More, better Java – Cool stuff like automatically saving / restoring documents from XML or JSON files in one fell swoop – Transactions support – Wider back-end support As we have Time! – As IBM pushes Connections and WAS more and more we as domino developers will have to deal with them more and more. – Letts take a quick looks at a couple of basic requirements that you have taken for granted in Domino all these year and how you would do them in WAS/Connections Setting up a WAS db2 connection Open up the WAS admin console, and select “JDBS Providers” Setting up a WAS db2 connection Make sure “db2jcc.jar” “db2jcc_license _cu.jar” Are on the server, you should if Connections is on there Setting up a WAS db2 connection You can Check the location in “Websphere Variables” Setting up a WAS db2 connection Create a Data source and link to the JDBC Provider Setting up a WAS db2 connection Create a Data source and link to the JDBC Provider You will also want to select a authentication alias Setting up a WAS db2 connection Create a Data source and link to the JDBC Provider Setting up a WAS db2 connection Example of a WORKING META-INF\persistence.xml <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name=“danNotes" transactiontype="RESOURCE_LOCAL"> <jta-data-source>jdbc/DanNotesDS</jta-data-source> <class>com.dannotes.settings</class> </persistence-unit> </persistence> Setting up a WAS db2 connection Finally we have something to connect to from java private static final EntityManagerFactory emf; emf = Persistence.createEntityManagerFactory("danNotes"); Questions How To Contact Me: Mark Myers Email: Mark@londc.com | Twitter: @stickfight | Skype: Stickfight | Blog: stickfight.co.uk Social business: Activity streams Connections integration, etc. Who Am I? – A Member of the London Developer Coop (londc.com) – Four developers based in London • • • • Ben Poole Julian Woodward Mark Myers (me) Matt White – Developer from a support background – 12+ years on Domino, 15+ years in IT – Speaker at 3x Lotuspheres, 3x UKLUGs, 1x ILUG, 1 X BLUG Connections Caveats – The methods shown in this session are one of many methods of integration rather than specific best practices – Niklas Heidloff (http://heidloff.net) and Mark Leusink (http://linqed.eu) provide the best examples. – These methods use as few toolkits such as Social Business toolkit/Social business SDK, social enabler as possible. – Real life has taught that the best integration environment to build is one where you can get all data if required (Gather all data using service accounts) then compile a result and display to the user. – Example: Java Agent Atom Feed A few different Java feed parsing libraries to choose from: – ROME – http://rometools.org – Apache Abdera – http://abdera.apache.org – Apache Wink – http://incubator.apache.org/wink – All require several additional libraries – Apache Commons libraries – Java StAX support – Etc. – Handle HTTP connections as well as parsing – Authentication too – An excellent test client: – DEV HTTP Client (Chrome Plugin) https://chrome.google.com/webstore/detail/ aejoelaoggembcahagimdiliamlcdmfm Example: Java Agent Get Atom Feed © 2013 IBM Corporation Example: Java Agent Submit Back to Atom Feed Most Atom services (particularly IBM) give examples of what XML they want rather than examples of the code you should use, so we will do the same This is a IBM Connections Blog entry in raw XML: <?xml version="1.0" encoding="utf-8"?> <entry xmlns="http://www.w3.org/2005/Atom"> <author><name>I Am Funny</name></author> <title type="text">Great Duck Joke</title> <content type="text">Q: What has webbed feet and fangs? A: Count Duckula</content> </entry> © 2013 IBM Corporation Example: Java Agent Submit Back to Atom Feed An amazingly useful line when you are debugging or testing as it outputs the XML so you can check it against what you should be sending © 2013 IBM Corporation Example: Java Agent Submit Back to Atom Feed Getting this URL is often the hardest part of dealing with Atom © 2013 IBM Corporation Example: Useful Extra Lines Add “registerTrustManager” and you can connect to SSL Ports Nice simple login, you just need the user name, password and the root domain you are logging on to © 2013 IBM Corporation Domino Integrating with IBM Connections Before we start we need to get a database ready to call Java from XPages Move to Package Explorer © 2013 IBM Corporation Domino Integrating with IBM Connections In The WEB-INF directory Right click and create a new folder © 2013 IBM Corporation Domino Integrating with IBM Connections Call it “src” in lower case © 2013 IBM Corporation Domino Integrating with IBM Connections Next add this folder to the projects build path Right click on the root of the project and select “Properties” © 2013 IBM Corporation Domino Integrating with IBM Connections On the “Source” tab click “Add folder” and add the folder you have created © 2013 IBM Corporation Domino Integrating with IBM Connections You will see the Folder has moved Right click and select “New” → “Other” Then Select “Java” → “Class” © 2013 IBM Corporation Domino Integrating with IBM Connections Create the new Java Class © 2013 IBM Corporation Domino Integrating with IBM Connections OK, Java class created, lets get it some libraries © 2013 IBM Corporation Domino Integrating with IBM Connections If you are not allowed to use the EXT directory on the server, the you will need to create a new “lib” folder © 2013 IBM Corporation Domino Integrating with IBM Connections © 2013 IBM Corporation Domino Integrating with IBM Connections Update (or ask your administrator to) the java.policy file on your server to contain the following grant { permission java.lang.RuntimePermission "getClassLoader"; }; © 2013 IBM Corporation Domino Integrating with IBM Connections Now we will add the Atom client code function You need to pass the session into this function as it can’t get its own If you need to you can login here (as described previously) © 2013 IBM Corporation Domino Integrating with IBM Connections Create a New Script Library © 2013 IBM Corporation Domino Integrating with IBM Connections Set it as a Normal “Server JavaScript” Library © 2013 IBM Corporation Domino Integrating with IBM Connections Create a SSJS function to call your Java and pass the results back Pass the “sessionAsSigner” here to give yourself administrator rights © 2013 IBM Corporation Domino Integrating with IBM Connections – Pulling it together Create a Custom Control © 2013 IBM Corporation Domino Integrating with IBM Connections Give it a Name © 2013 IBM Corporation Domino Integrating with IBM Connections Now you can add a repeat control that calls the SSJS function, which in turn calls the Java The Rest of the surrounding boring code is in the demonstration db © 2013 IBM Corporation Domino Integrating with IBM Connections – Pulling it together Create a New Xpage Library © 2013 IBM Corporation Domino Integrating with IBM Connections – Pulling it together Add the duckstates_cc custom control © 2013 IBM Corporation Domino Integrating with IBM Connections – Pulling it together © 2013 IBM Corporation Domino Integrating with IBM Connections Now that you have an XPage, you need to present it to Connections as a Open Social widget the easiest way of doing this is with a simple domino page. © 2013 IBM Corporation Domino Integrating with IBM Connections Features like “dynamic-height” are harder to get working using this method (rather than a embedding the widget in connections) but if you have a static sized widget it is the simplest. © 2013 IBM Corporation Integrating with IBM Connections And add it to your Connections installation © 2013 IBM Corporation Integrating with IBM Connections © 2013 IBM Corporation The Activity Stream – Just another Atom feed: – https://xxx.com/connections/opensocial/basic/ rest/activitystreams/@me/@all – Excellent example: http://www.lbenitez.com/2012/05/how-topost-events-into-opensocial.html The Activity Stream { "generator": { "image": { "url": "/homepage/nav/common/images/iconProfiles16.png"}, "id": "demoapp", "displayName": "Demo Application", "url": "http://www.ibm.com/" }, "actor": { "id": "@me" }, "verb": "post", "title": “Example Title", "content": " You have created a new Activity Stream.", "updated": "2013-05-08T12:00:00.000Z", "object": { "summary": “rhubarb rhubarb", "objectType": "note", "id": “rr13", "displayName": " rhubarb rhubarb ", "url": "http:// rhubarb.com/rhubarb.xml", }, } The Activity Stream Sanity Saver Do NOT use Rational Application Developer – If you want to use a IDE that has good Websphere integration I recommend MyEclipse Blue by Genuitec http://www.myeclipseide.com/blue/ Questions How To Contact Me: Mark Myers Email: Mark@londc.com | Twitter: @stickfight | Skype: Stickfight | Blog: stickfight.co.uk