JSR – 168 Portlet Spec
Sean P. GogginsIEEE Certified Software Development Professional
http://www.computer.org/certification
http://www.goggins.com http://www.clutchsoftware.com
Sean P. Gogginshttp://www.clutchsoftware.com
Agenda
1. Portal & Portlet Architecture & Strategy2. Pluto3. Our First Portlet4. The API Cliff’s Notes 5. EXO Portal… Plus, Deploy our Portlet in Portal
Two6. Jetspeed… Plus, Deploy our Portlet in Portal
Three!7. Liferay – My Favorite Portal
Sean P. Gogginshttp://www.clutchsoftware.com
A note on the “Moon Guy”
He means I have a Pre Baked Demo I can do…Stop me if I skip one you want to see
Sean P. Gogginshttp://www.clutchsoftware.com
Elements of Portal (ificaton)
�Perhaps a definition of "Portals" from Javaworld.com might also be useful -– A portal is a Web-based application that provides
personalization, single sign-on, and content aggregation from different sources, and hosts the presentation layer of information systems. Aggregation is the process of integrating content from different sources within a Webpage. A portal may have sophisticated personalization features to provide customized content to users. Portal pages may have different sets of portlets creating content for different users.
Sean P. Gogginshttp://www.clutchsoftware.com
What is Portalification?
http://www.pythonline.com
Sean P. Gogginshttp://www.clutchsoftware.com
What is a Portlet?
�A portlet is a Java technology based web component, managed by a portlet container, that processes requests and generates dynamic content. Portlets are used by portals as pluggable user interface components that provide a presentation layer to Information Systems.
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet and Portal TogetherStatic View
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet and Portal TogetherDynamic View
Sean P. Gogginshttp://www.clutchsoftware.com
Why Build a Portal?
�To solve some specific business need�Usually associated with content
aggregration
Sean P. Gogginshttp://www.clutchsoftware.com
Steps in building a Portal
�Gather Requirements– Portal’s require a more comprehensive architecture
than standard web or J2EE apps
�Build an Information Architecture– Content– User Interface– Portlets– Search Engine– Taxonomy
Sean P. Gogginshttp://www.clutchsoftware.com
Taxonomy Creation and Maintenance
Categorize ContentCategorize ContentAssetsAssets
Label andLabel andPersonalizePersonalize
IndexIndex
Inventory Inventory Content Content
Sean P. Gogginshttp://www.clutchsoftware.com
� Define the strategy
� Create an organization focused on taxonomy creation
� Define purpose and intended use (users) of taxonomy
� Prioritize needs:
– Concepts if you’re inventing
– Processes if you’re low skill service based
– Competencies if you’re high skill service based
� Decide basic metaphor for structuring information
� Choose a methodology/approach to building the taxonomy
� Classify information assets and categorize them
� Verification
� Implement Technology Support (JSR-168 compliant Portal?)
� Maintain
Steps in Building a Taxonomy
Sean P. Gogginshttp://www.clutchsoftware.com
Building Portal Metadata – Dublin Core
RightsCoverageRelation
LanguageSourceIdentifier
FormatTypeDate
ContributorPublisherDescription
SubjectCreatorTitle
http://dublincore.org/documents/dces/http://dublincore.org/documents/dcmi-type-vocabulary/
Sean P. Gogginshttp://www.clutchsoftware.com
Look and Feel
�Most portlets are customized using Skins– Jetspeed– EXOPortal– Liferay
�Search is an important part of any portal effort these days.
Sean P. Gogginshttp://www.clutchsoftware.com
JSR-168 / Java Portlets
�Javax.portlet package�Like other java applications
– Addition of portlet classes– Addition of portlet.xml deployment descriptor– WAR file deployment
�Different than other java applications– Portal handles the layout, aggregation,
personalization and single sign on
Sean P. Gogginshttp://www.clutchsoftware.com
Why not use servlets & .jsp’s?
�Absence of personalization interface and support for persistence of personalization information in servlet architecture
�Servlet architecture doesn’t define aggregation on the desktop
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet & Servlet both
�End in “let”�Are java components�Have container managed lifecycles
– Servlet container (tomcat)– Portlet container (pluto)
�Generate dynamic content�Manage sessions�Share a deployment and class loading paradigm
Sean P. Gogginshttp://www.clutchsoftware.com
But only PortletsPortletsPortlets
�Generate Fragments (not complete documents)
�Have container managed, predefined states– Window States– Portlet Modes
�Are not directly bound to a URL
Sean P. Gogginshttp://www.clutchsoftware.com
…and Only Servlets…
�Can set the URL client request�Can set HTTP headers in responses�Can establish response character encoding
Sean P. Gogginshttp://www.clutchsoftware.com
Portal Page
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet Architecture
Sean P. Gogginshttp://www.clutchsoftware.com
WSRP
�OASIS Standard – Web Services for Remote Portals
�Portals that support WSRP can display Portlets from other WSRP enabled Portals
Sean P. Gogginshttp://www.clutchsoftware.com
Integrating Existing Applications into the Portal
�Write a thin web service and develop a portlet for that application
�Write a WSRP layer on top of the application and have the application host itself as a portlet producer
�Application rewrite, factoring business logic and persistence out of the legacy app.
Part Two
Pluto
Sean P. Gogginshttp://www.clutchsoftware.com
Installing Pluto
Sean P. Gogginshttp://www.clutchsoftware.com
Installing Plutohttp://portals.apache.org/pluto/install.html
�CVS Client – I just used Eclipse� Install Maven� Install Tomcat�Edit build.properties file�Add %MAVEN_HOME%\bin directory to
path�Root Directory of PLUTO Project�Execute `maven fullDeployment`�Check it out!
Sean P. Gogginshttp://www.clutchsoftware.com
Installing Plutohttp://portals.apache.org/pluto/install.html
�Build.properties settings– maven.tomcat.home=c:/tomcat5.0– maven.tomcat.version.major=5
Sean P. Gogginshttp://www.clutchsoftware.com
If your Maven Build Works
Sean P. Gogginshttp://www.clutchsoftware.com
Interesting Eclipse Plugins –Where Portal Construction is Going
•For Eclipse Generation of Portlets•http://plutoeclipse.sourceforge.net/
•Maven Eclipse Plugin–http://maven.apache.org/reference/plugins/eclipse/properties.html
Sean P. Gogginshttp://www.clutchsoftware.com
JSR-168 Establishes
�Portlet Container – Pluto is the reference implementation
�Portlet API– Requests– Preferences– User Information– Deployment Packaging
�Relationship between portlet and portletcontainer
Sean P. Gogginshttp://www.clutchsoftware.com
Portal – Just Another Web App
�WEB-INF (Familiar to Servlet & JSP folks)– Web.xml– Portlet.xml
�Pluto Specific Deployment Directory– $TOMCAT_HOME/webapps/pluto/data
• Portletentityregistry.xml – portlet & portlet app definitions
• Pageregistry.xml – Describes how the portal page looks
Sean P. Gogginshttp://www.clutchsoftware.com
Using Ant for War FilesInit
<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="dist.dir" value="dist"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="lib.dir" value="lib"/>
<property name="web-inf.dir" value="WEB-INF"/>
<target name="init">
<mkdir dir="${build.dir}"/>
<mkdir dir="${classes.dir}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${lib.dir}"/>
</target>INIT
Sean P. Gogginshttp://www.clutchsoftware.com
Using Ant for War FilesCompile
<target name="compile" depends="init">
<javac destdir="${classes.dir}" deprecation="true" debug="true" optimize="false">
<src>
<pathelement location="${src.dir}"/>
</src>
<classpath>
<fileset dir="${lib.dir}">
<include name="*.jar">
</include>
</fileset>
<fileset dir="${tomcat.shared.lib.dir}">
<include name="*.jar">
</include>
</fileset>
</classpath>
</javac>
</target>
COMPILE
Sean P. Gogginshttp://www.clutchsoftware.com
Using Ant for War FilesWar
<target name="war" depends="compile">
<war destfile="${dist.dir}/${war.name}.war" webxml="WEB-INF/web.xml">
<classes dir="${classes.dir}"/>
<lib dir="${lib.dir}"/>
<webinf dir="${web-inf.dir}"/>
</war>
</target>
WAR
Sean P. Gogginshttp://www.clutchsoftware.com
Pageregistry.xml
Portal Application Id.portletId
Sean P. Gogginshttp://www.clutchsoftware.com
portletentityregistry.xml
Portal Application Id
Portlet Id
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet Errors
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet Errors – Did you Deploy?
maven deploy -Ddeploy=FULL_PATH_TO_YOUR_PORTLET_WAR
Part Three
Build our First Portlet
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet Modes
�Mandatory support for– View– Edit– Help
�JSR-168 supports custom, vendor defined portlet modes
Sean P. Gogginshttp://www.clutchsoftware.com
Window State
�Three States defined in JSR-168– Normal– Maximized– Minimized
�Custom states supported
Sean P. Gogginshttp://www.clutchsoftware.com
Build our First PortletDefine Project Structure
Define our ConstructionFile structures, etc.
Sean P. Gogginshttp://www.clutchsoftware.com
Build our First PortletCode the Java
package com.clutchsoftware.portlets;
import java.io.IOException;
import java.io.Writer;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
public class CardinalsOne extends GenericPortlet
{
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException
{
System.out.println("TEST OUTPUT");
response.setContentType("text/html");
Writer writer = response.getWriter();
writer.write("Help, I'm a portlet, and I'm trapped in a portal framework!");
}
}
Code the Java
Sean P. Gogginshttp://www.clutchsoftware.com
Build our First PortletBuild the web.xml
Build the XML
Sean P. Gogginshttp://www.clutchsoftware.com
Build our First PortletPortlet.xml
Build the XML
Sean P. Gogginshttp://www.clutchsoftware.com
Build our First PortletAnt Build Script
Run the ant build script
Sean P. Gogginshttp://www.clutchsoftware.com
Build our First Portlet
Perform the PLUTO Deployment
Sean P. Gogginshttp://www.clutchsoftware.com
Build our First Portlet
Edit the portletentityregistry.xml file
Make sure this is the same as your class name in your java file
Sean P. Gogginshttp://www.clutchsoftware.com
Build our First Portlet
Edit the pageregistry.xml file
Sean P. Gogginshttp://www.clutchsoftware.com
Build our First Portlet
Part Four
An API Tour
Sean P. Gogginshttp://www.clutchsoftware.com
GenericPortlet
�Base class for java portlet specification�Implements Portlet and PortletConfig
interfaces of the portlet API�Key methods
– doDispatch()– doView()– doHelp()– doEdit()
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet Interface
� init()� processAction(ActionRequest, ActionResponse)� render(RenderRequest, RenderResponse)� destroy()
«interface»PortletRequest
«interface»ActionRequest
«interface»RenderRequest
«interface»PortletResponse
«interface»ActionResponse
«interface»RenderResponse
Sean P. Gogginshttp://www.clutchsoftware.com
RenderResponse object –Content Types
� Portlets can produce content using the RenderResponse writer or it may delegate generation of content to a servlet or .jsp
� Set content type– public void setContentType(String type);
� Get Default Content Type for the Portal– public String getResponseConentType();
� List of all supported content types– public java.util.Enumeration getResponseContentTypes()
Sean P. Gogginshttp://www.clutchsoftware.com
RenderResponse object –Writing Content to a Portal Page
� Where portlets can write– Output stream– Writer
� Most use getWriter() method on the RenderResponse object– public java.io.PrintWriter getWriter() throws
java.io.Exception;
Sean P. Gogginshttp://www.clutchsoftware.com
PortletURL
�A portlet can create a URL that targets itself inside the portlet container – PortletURL’s
�Key methods on RenderResponse– createRenderURL()– createActionURL()
�Key PortletURL object methods– setParameter(String name, String value)– setParameters(java.util.Map parameters)– setSecure() [true to enable security, false to disable it]
Sean P. Gogginshttp://www.clutchsoftware.com
What does a Portlet Have to Implement?
�GenericPortlet’s– getTitle()– doView()– Constructor
Sean P. Gogginshttp://www.clutchsoftware.com
Lifecycle of a Portlet
�Creation of the portlet– Loading the classes– Invocation of constructor– init()
�Processing Requests– render()– processAction()
�Death of a Portlet– destroy()
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet RequestsRequest Attributes
�Request Attributes – Pass java objects
between portlets, servlets& JSP’s
– PortletRequest Attributes are identical to HTTPServletRequestattributes
«interface»PortletRequest
«interface»ActionRequest
«interface»RenderRequest
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet RequestsRequest Properties
�Request Properties– Allows access to
container or server properties
– Vendor dependent– Not portable across
implementations
«interface»PortletRequest
«interface»ActionRequest
«interface»RenderRequest
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet RequestsRequest Parameters
�Request Parameters– Name value pair– String object name– One or more String
object values
«interface»PortletRequest
«interface»ActionRequest
«interface»RenderRequest
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet RequestsRequest Security
�Request Security– getAuthType()– getRemoteUser()– isUserInRole()– getUserPrincipal()
«interface»PortletRequest
«interface»ActionRequest
«interface»RenderRequest
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet ResponsesPortletResponse Base Interface
�Three methods– setProperty(String key,
String value)– addProperty(String key,
String value)– encodeURL()
«interface»PortletResponse
«interface»ActionResponse
«interface»RenderResponse
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet ResponsesRenderResponse Interface
�Numerous Methods– createActionURL()– createRenderURL()– setContentType()– setTitle()– getNamespace()– getLocale()– ….
«interface»PortletResponse
«interface»ActionResponse
«interface»RenderResponse
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet ResponsesActionResponse Interface
�Numerous Methods– setWindowState() throws
WindowStateException– setPortletMode() throws
PortletModeException– sendRedirect()– setRenderParameter()– setRenderParameters()
– ….
«interface»PortletResponse
«interface»ActionResponse
«interface»RenderResponse
Sean P. Gogginshttp://www.clutchsoftware.com
PortletContext
�PortletConfig Interface provides access– getPortletContext()
�PortletContext– getServerInfo() – Returns a string that
provides the name and version number of the portlet container
– getMajorVersion() / getMinorVersion() –Return major and minor versions of the portletAPI
Sean P. Gogginshttp://www.clutchsoftware.com
Portlet Sessions
�PortletSession Object– Obtained through a PortletRequest object– A façade over HTTPSession
�getPortletSession()
Part Five
EXO Portal
Sean P. Gogginshttp://www.clutchsoftware.com
EXO Portlet Deployment
Sean P. Gogginshttp://www.clutchsoftware.com
Build.xml Modifications for EXO
Sean P. Gogginshttp://www.clutchsoftware.com
Result – One WAR for Each Portal
Sean P. Gogginshttp://www.clutchsoftware.com
Seeing the EXO Deployment
Sean P. Gogginshttp://www.clutchsoftware.com
EXO – Deployment Eclipse Plugin
�Demo
Sean P. Gogginshttp://www.clutchsoftware.com
General Thoughts on EXO-Portal
�Deployment documentation is unclear– Reasonably well organized– Not written by somebody who understands
• How to use a spell checker• The English language
�LocalHost deployment on Tomcat crashed and/or exhibited non-deterministic behavior frequently.
Part Six
Jetspeed
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!Basic Requirements
� It is expected that the user is familiar with both the Apache Maven project tool and the Apache Ant build tool.
�Ant 1.5 or higher�Maven 1.0 or higher�Java 1.4 or higher�Servlet 2.3:
Tomcat 4.1.xorTomcat 5.x
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!CVS Checkout Instructions
�Web Access�http://cvs.apache.org/viewcvs/jakarta-jetspeed-2/�Anonymous CVS Access
– This project's CVS repository can be checked out through anonymous (pserver) CVS with the following instruction set. When prompted for a password for anonymous, simply press the Enter key.
– cvs -d :pserver:[email protected]:/home/cvspublic login cvs -z3 -d :pserver:[email protected]:/home/cvspublic co jakarta-jetspeed-2
– Updates from within the module's directory do not need the -d parameter.
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!Building Jetspeed -1
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!Building Jetspeed -2
Building Jetspeed 2If you are using the default Hypersonic database, this procedure requires two terminal sessions. If you are using another database, skip the immediate section below on Terminal Session #1.
�������������� ��������������������� �������������������������� ��������������������������
Terminal session #2, build the portal and all components and unit test Jetspeed-2:
�������������� ������ !������"����������� �������������� ���������#�� !��
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!Building Jetspeed -3
http://portals.apache.org/jetspeed-2/getting-started.html
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!Building Jetspeed -4
Deploying Jetspeed into TomcatWe only cover deploying to Tomcat 4 and Tomcat 5. Step #1 below is optional if you are NOT using the default Hypersonic database.
1. If you are using the Hypersonic SQL database, make sure you have terminated the test HSQLserver. Then in the same terminal, start the production Hypersonic database by typing
maven start.production.server
2. (in seperate window/terminal session)
cd ${jetspeed-2-home}
3. maven quickStart
This will recreate the DB to deploy into. WARNING This will drop all the tables and data in the production database.
4. Start up Tomcat. With a browser, go to:
http://localhost:8080/jetspeed
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!Building Jetspeed -5
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!Portlet Deployment – 1
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!Portlet Deployment – 2
Ya put your .war filed portlet in here…
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!Portlet Deployment – 3
<fragment id="88" type="portlet" name="dodgers::DodgersDone">
<property layout="TwoColumns" name="row" value=“4" />
<property layout="TwoColumns" name="column" value="0" />
</fragment>
Notice the Syntax similarity with pluto –dodgers.DodgersDone
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!Portlet Deployment – 4
Documentation Says – You don’t need to Restart tomcat for the changes to be recognized•Half True
•If you don’t, it does show the portlet frame•But, the portlet doesn’t work until you restart tomcat
Sean P. Gogginshttp://www.clutchsoftware.com
Portlets on Jetspeed!Portlet Deployment – 5
Sean P. Gogginshttp://www.clutchsoftware.com
Jetspeed – General Thoughts
�Jetspeed 1 is relatively stable, but not JSR-168 compliant
�Jetspeed 2 is unstable– Portlets work and minutes later… don’t work– Sometimes the container won’t start…. And
then it will�Like Pluto, there is no binary download
available yet.
Part Seven
Miscellaneous Notes & My Favorite Open Source Portal – Liferay
Sean P. Gogginshttp://www.clutchsoftware.com
Open Source Portlets
http://sourceforge.net/projects/portlet-opensrc
Sean P. Gogginshttp://www.clutchsoftware.com
Liferay
� I’ve been running a Liferay Portal 24/7 for two years using Jboss & Oracle
�Decent Eclipse setup instructions available�Quite the Resource Pig�Requires knowledge of J2EE beyond servlets &
.jsp’s to operate�Learning curve is steeper, but the flexibility and
stability far exceed other portals I’ve shown here tonight.
Sean P. Gogginshttp://www.clutchsoftware.com
Liferay Deployment