Ar*@!+$es to this. getting IBM connections to do what you want
-
Upload
mark-myers -
Category
Technology
-
view
1.581 -
download
1
description
Transcript of Ar*@!+$es to this. getting IBM connections to do what you want
UKLUG 2012 – Cardiff, Wales September 2012
Presenter: Mark MyersCompany: London Devloper Co-op
getting connections to do what you want
ICON UK 2013"Ar*@!+$es to this"
UKLUG 2012 – Cardiff, Wales
Who am I? – Mark Myers
• A Member of the London Developer Co-op (londc.com) A group of UK based developers
• Ben Poole• Julian Woodward• Mark Myers (me)• Robin Willis• Matt White
• Developer from a support background• 12+ years on Domino, 15+ years in IT• Speaker at 3x Lotuspheres, 4x UKLUGs, 1x ILUG,
1x BLUG
UKLUG 2012 – Cardiff, Wales
Why this presentation and why that title?
• IBM have given us a new platform. And with it a new framework.
• It still has a Beta feel about it, • Due to its constructions is very much a
patchwork with some areas working inconsistently and varying wildly between versions
UKLUG 2012 – Cardiff, Wales
Fair Enough but Still, why that title?
• Support are using a “hot brick” tactic on areas when you a forced to use undocumented features e.g. dojo.i18n.getLocalization
• Connections is designed for a certain use case and just like Domino before it clients are not sticking to it but you still need to deliver on their needs.
We can hack domino to do what ever we want. Time to do the same with connections
UKLUG 2012 – Cardiff, Wales
So what are we dealing with?
What is IBM Connections from a Developers point of view?
UKLUG 2012 – Cardiff, Wales
So what are we dealing with?
• An IBM Websphere server• With N number of ‘normal’ apps on it• Glued to a DB2 server (normally)
No need to get excited
UKLUG 2012 – Cardiff, Wales
A Websphere server with Connections 4.0 installed (amongst other things)
UKLUG 2012 – Cardiff, Wales
You can find out which URL’s match to which applications
You would of course never use a Java Decompiler such as the one found at http://jd.benow.ca/ to workout how these apps actually work
UKLUG 2012 – Cardiff, Wales
Loads of JDBC connections
UKLUG 2012 – Cardiff, Wales
I break customisation into 3 levels
• By GUI• By XML (not done in this presentation)• By Native app
Lets do this one
UKLUG 2012 – Cardiff, Wales
Tools (Your IDE)
• Rational Application Developer for WebSphere Software (NEVER EVER!!) • http://www-03.ibm.com/software/
products/us/en/application/
• Myeclipse Blue• http://www.myeclipseide.com/blue/
UKLUG 2012 – Cardiff, Wales
Native Websphere App time!!
• When all else fails this option will let you do ANYTHING you want.
• A Necessity for Connections environments with no Domino servers
• Other than a few IBM quirks, the following is all standard java apps stuff, good to know and very very reusable
UKLUG 2012 – Cardiff, Wales
What are WAR and EAR files
• A .War file (Web application ARchive) is a file used to distribute a collection of JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static Web pages (HTML and related files) and other resources that together constitute a Web application.
• An .Ear (Enterprise ARchive) is Basically a normal War file wrapped in a configuration wrapper.
• On the Ear file features remember you are on a shared server and you can not make any assumptions as to what is happening
UKLUG 2012 – Cardiff, Wales
Making a Native Connections App
Easiest way of ensuring compatibility is to select a
matching Runtime
In MyEclipse/RAD do “File” “New” Web Project
Just Accept defaults
UKLUG 2012 – Cardiff, Wales
Making a Native Connections App
In MyEclipse/RAD do “File” “New” Enterprise Application Project
UKLUG 2012 – Cardiff, Wales
Making a Native Connections App
Selecting this means that unless you wish to
customize the deployment you are done
Select the App(s) you want to be packaged in
this Ear
UKLUG 2012 – Cardiff, Wales
Making a Native Connections App
This gives you the following 2 project
structures
UKLUG 2012 – Cardiff, Wales
Making a Native Connections App
Select your EAR file project and do “File” “Export”
UKLUG 2012 – Cardiff, Wales
The Questions Domino Developers ask when starting Native Java Apps
• How do I connect to a database?• Where is my “when Opened in a browser”?• Agents!, I need them! Where are they?
UKLUG 2012 – Cardiff, Wales
The Great Database Chase• When we moved from Domino to Connections we
went from the easy going world of NOSQL and constantly being in a database context to Relational databases and defining our own contexts (most likely DB2)
• There are lots of different ways of linking your applications to databases (in Java)• Hibernate• JPA• EJB3
• I'm going to Use JPA (Java Persistence API) as I find it the best and most easy-going• http://en.wikipedia.org/wiki/Java_Persistence_API
UKLUG 2012 – Cardiff, Wales
Why Use all this? Why not read/write direct using SQL?• Eliminates all of the 'hand' mapping in Java from a
SQL ResultSet to a Java Object greatly reducing the amount of mapping work.
• Avoids low level JDBC and SQL code. You just deal with Java Classes
• Provides high end performance features such as caching and sophisticated database and query optimizations.
There are lots of fighting over if you should use a ORM (Object-relational mapping) framework such as JPA, but frankly, its quick, reliable and does not give you grief
UKLUG 2012 – Cardiff, Wales
The Great Database Chase
JDBC config on Server
JDBC config on Server
JDBC Mapped to
Persistence unitIn
Persistence.xml
JDBC Mapped to
Persistence unitIn
Persistence.xml
Persistence Unit used by
Entity Manager helper
Persistence Unit used by
Entity Manager helper
Entity Manager
used code to do stuff
Entity Manager
used code to do stuff
Entity Manager
Calls Entity Manaager
Entity Manager
Calls Entity Manaager
UKLUG 2012 – Cardiff, Wales
JDBC connections are setup on the WAS server
This actually provides the link to the database and you don’t need to deal
with Authentication
UKLUG 2012 – Cardiff, Wales
Setting up a WAS db2 connection
Open up the WAS admin console, and select “JDBS
Providers”
UKLUG 2012 – Cardiff, Wales
Setting up a WAS db2 connection
Make sure
“db2jcc.jar”
“db2jcc_license_cu.jar”
Are on the server, they should be if
Connections is on there
UKLUG 2012 – Cardiff, Wales
Setting up a WAS db2 connection
You can Check the location in
“Websphere Variables”
UKLUG 2012 – Cardiff, Wales
Setting up a WAS db2 connection
Create a Data source and link to the JDBC Provider
UKLUG 2012 – Cardiff, Wales
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
UKLUG 2012 – Cardiff, Wales
Setting up a WAS db2 connection
This will mean that the
application does not have to contain any
authentication details
(meaning the same app can be deployed to dev and live)
UKLUG 2012 – Cardiff, Wales
Persistence.xml
Now we can link our application to the database definition on the server
When dealing with websphere the transaction-type will
always be “RESOURCE_LOCAL”
UKLUG 2012 – Cardiff, Wales
EntityManagerHelper.java
UKLUG 2012 – Cardiff, Wales
Table/Class Data Access Object
UKLUG 2012 – Cardiff, Wales
Finally use the data in code
UKLUG 2012 – Cardiff, Wales
Don’t worry this is all done with wizards
UKLUG 2012 – Cardiff, Wales
Lets have a Look at the Datbase
UKLUG 2012 – Cardiff, Wales
Where is my “when Opened in a browser”?
The Web.xml is the core of your application configuration, just about everything is started from here
UKLUG 2012 – Cardiff, Wales
Agents!, I need them! Where are they?
• There are lots of different ways of providing this feature, and lots of pro and cons for each way.
• I am going to show you Quartz from http://quartz-scheduler.org/
UKLUG 2012 – Cardiff, Wales
Setting up a Scheduled Job
Down load the Quartz package from the website un zip it and copy the Jar files in the /webroot/WEB-INF/lib
UKLUG 2012 – Cardiff, Wales
Setting up a Scheduled Job
In the Properties of the Project, in the Java Build Path, add the /webRoot/Web-INF/lib as a “class folder”
UKLUG 2012 – Cardiff, Wales
Setting up a Scheduled Job
In your Web.xml add a new servlet, with the value<load-on-startup> = 1
UKLUG 2012 – Cardiff, Wales
Setting up a Scheduled Job
Setup a new Class that the servlet will call
UKLUG 2012 – Cardiff, Wales
Setting up a Scheduled Job
In the “init” method for the new servlet you have made, add one of the many varieties of Quartz Scheduler see http://quartz-
scheduler.org/documentation
UKLUG 2012 – Cardiff, Wales
Further Reading on Native Apps
As you are now just writing Native Java Apps + IBM quirks the number of available libraries and tools you can use is mind blowing
Some Recommended areas to read up on:•Jersey: The easiest way to do REST services in pure java. http://jersey.java.net/•Annotations http://javapapers.com/core-java/java-annotations/•Abdera: Best Atom Service reader and generator http://abdera.apache.org/
UKLUG 2012 – Cardiff, Wales
Questions?
If we have time then we can keep going!
?
UKLUG 2012 – Cardiff, Wales
None Native integration (Domino)
UKLUG 2012 – Cardiff, Wales
Tools• DEV HTTP CLIENT
• https://plus.google.com/104025798250320128549/posts
• FireBug• https://getfirebug.com/
UKLUG 2012 – Cardiff, Wales
Example: Java Agent Atom FeedA 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.
Handles HTTP connections as well as parsing
Authentication too
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Example: Java Agent Get Atom Feed
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
<?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>
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:
UKLUG 2012 – Cardiff, Wales
© 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
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Example: Java Agent Submit Back to Atom Feed
Getting this URL is often the hardest part of dealing with Atom
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Example: Useful Extra LinesAdd “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
UKLUG 2012 – Cardiff, Wales
© 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
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Domino Integrating with IBM Connections
In The WEB-INF directory
Right click and create a new folder
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Domino Integrating with IBM Connections
Call it “src” in lower case
UKLUG 2012 – Cardiff, Wales
© 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”
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Domino Integrating with IBM Connections
On the “Source” tab click “Add folder” and add the folder you have created
UKLUG 2012 – Cardiff, Wales
© 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”
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Create the new Java Class
Domino Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
OK, Java class created, lets get it some libraries
Domino Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
If you are not allowed to use the EXT directory on the server, the you will need to create a new “lib” folder
Domino Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Domino Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Update (or ask your administrator to) the java.policy file on your server to contain the following
Domino Integrating with IBM Connections
grant {
permission java.lang.RuntimePermission "getClassLoader";
};
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
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)
Domino Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Create a New Script Library
Domino Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Set it as a Normal “Server JavaScript” Library
Domino Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Pass the “sessionAsSigner” here to give yourself administrator rights
Create a SSJS function to call your Java and pass the results back
Domino Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Domino Integrating with IBM Connections – Pulling it together
Create a Custom Control
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Give it a Name
Domino Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Now you can add a repeat control that calls the SSJS function, which in turn calls the Java
Domino Integrating with IBM Connections
The Rest of the surrounding boring code is in the demonstration db
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Domino Integrating with IBM Connections – Pulling it together
Create a New Xpage Library
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Domino Integrating with IBM Connections – Pulling it together
Add the duckstates_cc custom control
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Domino Integrating with IBM Connections – Pulling it together
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
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.
Domino Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
© 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 and quickest
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
And add it to your Connections installation
Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
© 2013 IBM Corporation
Integrating with IBM Connections
UKLUG 2012 – Cardiff, Wales
And to just round up:the Activity Stream
Its Just another Atom feed:
https://xxx.com/connections/opensocial/basic/rest/activitystreams/@me/@all
Excellent example: http://www.lbenitez.com/2012/05/how-to-
post-events-into-opensocial.html
UKLUG 2012 – Cardiff, Wales
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", }, }
UKLUG 2012 – Cardiff, Wales
The Activity Stream
Working Post Example (for you to copy)
UKLUG 2012 – Cardiff, Wales
Questions?
How To Contact Me:Mark Myers
Email: [email protected] | Twitter: @stickfight | Skype: Stickfight | Blog: stickfight.co.uk
?