Top Banner
Advanced Web Systems 2- Portal and Portlet A. Venturini
54

Advanced Web Systems 2- Portal and Portlet

Feb 03, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Advanced Web Systems 2- Portal and Portlet

Advanced Web Systems 2- Portal and Portlet

A. Venturini

Page 2: Advanced Web Systems 2- Portal and Portlet

Contents

What is a portlet?

Why portlets?

Portal and portlet architecture

Portlet vs. Sevlet

Portlet and Web application frameworks

Portlet modes and Windows states

Portlet features

Portlet APIs

Most of the slides taken from a presentation of:

Sang Shin, [email protected], www.javapassion.com

Page 3: Advanced Web Systems 2- Portal and Portlet

What is a Portlet?

Java technology based web component

Managed by a portal container

Generates a piece of markup called “fragment”

Adheres to certain rules such as no <html>

tags, for instance

Fragment generated by a Portlet aggregates

with that from other Portlets to form a portal

page

Fragment generated by a Portlet may

vary from one user to another depending

on the user configuration

Page 4: Advanced Web Systems 2- Portal and Portlet

Portlet Specifications

JavaTM Portlet Specification

First version: JSR 168

Second version: JSR 286

http://www.jcp.org/en/jsr/detail?id=286

Standard specificatitons defined by the major

portal vendors (ibm, sun, bea, …) for portlet

technologies

Page 5: Advanced Web Systems 2- Portal and Portlet

What does JSR-168 define?

Portlet API

Portlet Requests

Preferences

User information

Security

Deployment packaging

Portlet Container

Extension of servlet container

Contract between component and

container

Page 6: Advanced Web Systems 2- Portal and Portlet

What are out-of-scope of JSR 168?

These are out of scope of JSR 168: these are

handled by Portal server

Aggregation

Layout management

Page personalization and configuration

engines

Portal administration and configuration

Page 7: Advanced Web Systems 2- Portal and Portlet
Page 8: Advanced Web Systems 2- Portal and Portlet

What happens when clicking on a link?

when clicking on a portlet link, typically the

content of that portlet should change.

The other portlet, should keep their status

(typically not change there view, but sometimes

they do!)

Page 9: Advanced Web Systems 2- Portal and Portlet

Portal and Portlet Interaction

User Portal Portlet

container

Portlets

A B C

render

render

render

processAction

A

B C

A’

B’ C

Action on B Do action on B

Render A

Render B

Render C

These requests

may be done in

parallel

Scope of the Portlet specification Outside of the scope of the Portlet specification

Page 10: Advanced Web Systems 2- Portal and Portlet

Why Portlet? (Why can't we use Servlet?)

Page 11: Advanced Web Systems 2- Portal and Portlet

Why Portlets?

Servlet architecture does not define the

Desktop metaphor where markup aggregation

can occur

Servlet architecture does not define the

possible states and transitions of an included

Servlet or JSP

Servlet architecture does not define how the

state of one Servlet or JSP affects the display

of the other included Servlets or JSPs

Page 12: Advanced Web Systems 2- Portal and Portlet

Why Portlets?

Servlet architecture does not define a

personalization interface nor the idea

of persisting the personalization

information

Servlet architecture does not define

URL-rewriting functions to allow the

creation of links and actions targeted

to a specific form within the fragment

of a page (Portlet markup fragment)

Servlet architecture does not support

caching scheme of fragments

Page 13: Advanced Web Systems 2- Portal and Portlet

JSR 168 Value Proposition: Portability of Portlet Apps

JSR 168

Compliant

Portals

Write Once

Deploy to Many

Po

rtle

t In

terf

ace

Page 14: Advanced Web Systems 2- Portal and Portlet

Portal Architecture

With JSR 168 Support

Portal

User Agent Browser, Phone, PDA

Portlet Container

Portlet Portlet

Portlet

Network Aggregation

Personalization Security

Page 15: Advanced Web Systems 2- Portal and Portlet

Portal/Portlet Architecture

User

Configuration/

Personalization

Engine

Persistent Data Store

Portlet Dispatcher

Window Config Security

Portlet

Enterprise

Information

Systems

Remote

Execution

module

Portlet

Aggregation

Engine

Portlet

Portal server

Page 16: Advanced Web Systems 2- Portal and Portlet

Portal/Portal Server

A “specialized” web application that provides

value-added services such as

Personalization

Single Sign-On

Content aggregation from various sources

Secure search facilities

Localization of content

A Portal “page” represents a complete markup

document consisting of several Portlet

components

Portal server is the platform

Page 17: Advanced Web Systems 2- Portal and Portlet

Portlet Container

Portlets are deployed in a Portlet container

such that container can

Provides runtime environment for Portlets

Manage life cycle of Portlets

Provide persistent storage for storing Portlet

preferences

Cache the portlets

Receive requests from the portal to execute

requests on the portlet

Not responsible for contents aggregation

Page 18: Advanced Web Systems 2- Portal and Portlet

Similarity with Servlet

Both are Java technology based web components

Life-cycle is managed by a specialized container

Servlet by servlet container

Portlet by portlet container

Both generate dynamic content

Both interact with web client via a request/response

paradigm

Page 19: Advanced Web Systems 2- Portal and Portlet

Common Foundation between Servlets and Portlets

Deployment model

Classloading

Packaging and deployment

Lifecycle management

Session management

Request dispatching

Page 20: Advanced Web Systems 2- Portal and Portlet

Differences from Servlet

Portlets only generate markup fragments, not

complete documents

Portlets are not directly bound to a URL

Web clients interact with portlets through a portal

system

Portlets have a more refined request handling

action requests and render requests

Portlets have predefined states

portlet modes and window states

Portlets can exist many times in a portal page

Page 21: Advanced Web Systems 2- Portal and Portlet

Extra Features of Portlets

Portlets have means for accessing and

storing persistent configuration and

customization data

Portlets have access to user profile

information

Portlets have URL rewriting functions for

creating hyperlinks within their content

allow portal server agnostic creation of links and

actions in page fragments

Portlets can store transient data in the portlet

session in two different scopes

application-wide scope

the portlet private scope

Page 22: Advanced Web Systems 2- Portal and Portlet

Servlet Features Forbidden to Portlets

Setting the character set encoding of the response

Setting HTTP headers on the response

Accessing the URL of the client request to the portal

(!)

Page 23: Advanced Web Systems 2- Portal and Portlet

Servlet Features that are leveraged by Portlets

Portlets can leverage servlets, JSPs and JSP tag-

libraries for generating content

Content should be markup fragment

A portlet can call servlets and JSPs using a

request dispatcher

Page 24: Advanced Web Systems 2- Portal and Portlet

Integration between the two

Attributes set in the portlet request are available

in the included servlet request

Attributes set in the portlet session are accessible

from the servlet session and vice versa

Portlet and the included servlet or JSP share the

same output stream

Page 25: Advanced Web Systems 2- Portal and Portlet

Portlet and Web App. Frameworks

Page 26: Advanced Web Systems 2- Portal and Portlet

Portlet and Web App. Frameworks

Struts/JSF

Struts/JSF are built over Servlets

Struts/JSF is available for Portlets

APIs exposed to Struts/JSF developers

remain the same

Struts/JSF developers must be aware of the

markup fragment he has to produce

The markup fragment must follow the

rules

Generate Portlet URL

Page 27: Advanced Web Systems 2- Portal and Portlet

The Spring Framework

Spring is a Lightweight Application Framework

Where Struts, WebWork and others can be

considered Web frameworks, Spring addresses

all tiers of an application

Spring provides the plumbing so that you don’t

have to!

Page 28: Advanced Web Systems 2- Portal and Portlet

Spring Framework History

Started 2002/2003 by Rod Johnson and Juergen Holler

Started as a framework developed around Rod Johnson’s book Expert One-on-One J2EE Design and Development

Spring 1.0 Released March 2004

2004/2005 Spring is emerging as a leading full-stack Java/J2EE application framework

Page 29: Advanced Web Systems 2- Portal and Portlet

Why Spring Portlet MVC ?

Can be used in any JSR-168 compliant portlet

container

It promotes best practices such as coding to

interfaces and dependency injection

It supports multiple view technologies:

e.g. JSP, Velocity and FreeMarker.

It mirrors the Spring Web MVC framework. Easy to

convert.

It supports the action phase and render phase of a

portlet request – not hidden from the developer.

Spring provides support for all the application

layers!

Page 30: Advanced Web Systems 2- Portal and Portlet

Portlet Modes & Windows State

Page 31: Advanced Web Systems 2- Portal and Portlet

Portlet Modes

Indicates function that a portlet performs

Execute different tasks and generate different

content based on the function they perform

Portals must support three modes

VIEW

Portlet renders markup fragment in this mode

EDIT

Used to change per-user settings to customize

rendering

HELP

Used to display help information

Page 32: Advanced Web Systems 2- Portal and Portlet

Portlet Modes (Contd.)

Portals might support other custom modes

ABOUT

CONFIG

EDIT_DEFAULTS

PREVIEW

PRINT

Portals might support other vendor specific

modes

Page 33: Advanced Web Systems 2- Portal and Portlet

Windows State

Is an indicator of the amount of portal page space that

will be assigned to the content generated by a portlet

Provided by portlet container

Three states

NORMAL

MAXIMIZED

MINIMIZED

Custom states are possible

Page 34: Advanced Web Systems 2- Portal and Portlet

Portlet Features

Page 35: Advanced Web Systems 2- Portal and Portlet

Portlet Persistence

Portlets can store persistent data for a given

user in a PortletPreferences object

Preferences are read-write in the action phase

(processAction()) and read-only in render

phase

Usually user preferences are modified in EDIT

mode

Page 36: Advanced Web Systems 2- Portal and Portlet

User Profile Attributes

Can store information about user that can be

used to personalize content for that user

User profile information is represented as a

USER_INFO structure which is then mapped to

the real information in datastore

Portlet defines the attributes it wants to access

in the deployment descriptor

Page 37: Advanced Web Systems 2- Portal and Portlet

Portal context

Can provide information on

Portal vendor

Version

Used by portlets to find out more information

about additional extensions supported by

Portal

Page 38: Advanced Web Systems 2- Portal and Portlet

Security

Authentication is left to the underlying servlet

container

Authorization

Follows J2EE ‘roles’ model

Supports programmatic role checking

Page 39: Advanced Web Systems 2- Portal and Portlet

Session Management

Facade on top of the HttpSession

Two scopes: APPLICATION & PORTLET

PORTLET is a convenience namespacing

It’s common for portlets to appear more than

once in a page (i.e.: EU-News, US-News)

Servlets, JSPs and Portlets within a Portlet

Application share the same session

Session creation event notification is supported

Page 40: Advanced Web Systems 2- Portal and Portlet

Portlet Request Dispatcher

Portlets can include Servlets, JSPs and static

content during a render request

Similar to Servlet’s RequestDispatcher

Page 41: Advanced Web Systems 2- Portal and Portlet

Localization

Portlets can be localized by using resource

bundles

Resource bundles are specified in deployment

descriptor

Portlet can access resource bundle via

PortletContext.getResourceBundle() API

Page 42: Advanced Web Systems 2- Portal and Portlet

Caching

Expiration based caching

Declarative caching

Specify <expiration-cache> element in

deployment descriptor for the portlet

Programmatic caching

Modify EXPIRATION_CACHE property of

render response

Page 43: Advanced Web Systems 2- Portal and Portlet

Portlet URL

Portlets are always accessed through a Portal

Portlets do not have a direct URL mapping

Portlet URLs allow Portlets to create URLs that

target to themselves (through the Portal end-

point)

Page 44: Advanced Web Systems 2- Portal and Portlet

Portlet API's

Page 45: Advanced Web Systems 2- Portal and Portlet

Java Portlet API

javax.portlet.Portlet

javax.portlet.GenericPortlet

javax.portlet.ActionRequest

javax.portlet.ActionResponse

javax.portlet.RenderRequest

javax.portlet.RenderResponse

Page 46: Advanced Web Systems 2- Portal and Portlet

Portlet Life Cycle

Handle requests

Destroyed by container

Initialized by

container

init()

processAction()

destroy()

Notifies initialization of portlet by container.

processAction() notifies the Portlet about user's request for action.

render()

render() notifies the Portlet to generate the markup fragment

destroy() notifies the destruction of portlet by container. Should free up resources in this method.

Page 47: Advanced Web Systems 2- Portal and Portlet

Portlet Interface

1 public interface Portlet {

2 public void init(PortletConfig config) throws PortletException; 3 4 // Action Request: Invoked only when the URL is an action targeted 5 // to the portlet, it does not produce output 6 public void processAction( ActionRequest request, 7 ActionResponse response) 8 throws PortletException, IOException;

9 // Render Request: Invoked on every request to the portal, it 10 // produces output to create the portal page 11 public void render(RenderRequest request, 12 RenderResponse response) 13 throws PortletException, IOException;

14 public void destroy(); 15 }

Page 48: Advanced Web Systems 2- Portal and Portlet

GenericPortlet class

Implements Portlet interface

Render()--like service() in servlets, calls

specified render methods based on Portlet

mode

doView() for View mode

doEdit() for Edit mode

doHelp() for Help mode

Is extended by portlet developers

Override render methods as necessary

Page 49: Advanced Web Systems 2- Portal and Portlet

javax.portlet.GenericPortlet

protected void doView(...)

protected void doEdit(...)

protected void doHelp(...)

protected void processAction(...)

Page 50: Advanced Web Systems 2- Portal and Portlet

DoView()

doView() doEdit() doHelp()

HTML

Portlet

Render()

Page 51: Advanced Web Systems 2- Portal and Portlet

DoEdit()

Portlet

Edit Form

Render() doView() doEdit() doHelp() HTML

Page 52: Advanced Web Systems 2- Portal and Portlet

ProcessAction()

Portlet container

processAction() store() doView()

Page 53: Advanced Web Systems 2- Portal and Portlet

Other Interfaces/Classes

PortletConfig, PortletContext,

PortletSession

PortletPreferences interface

WindowState (MINIMIZED,

NORMAL & MAXIMIZED)

PortletMode (VIEW, EDIT & HELP)

PortletURL

PortletRequestDispatcher

Portlet Tag Library

Page 54: Advanced Web Systems 2- Portal and Portlet

PortletPreferences

Persistent read/write Portlet configuration

getValues(), setValues() to access

PortletPreferences

May modify attributes and store() in persistence

during processAction()

Normally, portlet preferences are per portlet/per

user

Persistency is managed by the portlet-container

Default values are defined in the portlet.xml

deployment descriptor