IBM Remote and Local Inter­Portlet Communication Using WSRP and JSR286 Eventing

flashyfarctateInternet και Εφαρμογές Web

30 Ιουλ 2012 (πριν από 4 χρόνια και 4 μήνες)

682 εμφανίσεις





Remote and Local
Inter
-
Portlet
Communication Using
WSRP

and JSR286
Eventing


Supported
with IBM Rational Application
Developer v8.0.1, WebSphere Application Server
v7.0.0.11 and WebSphere Portal Server v7.0





Jaspreet Singh

01 February 2011







2

Tab
le
of

Contents

INTRODUCTION

................................
................................
................................
................................
.........

3

W
HY AND WHEN
WSRP?

................................
................................
................................
...........................

3

U
SECASE FOR SAMPLE
APPLICATION

................................
................................
................................
..........

4

CREATING PORTLETS

................................
................................
................................
.............................

4

P
ORTLET
1:

E
VENT
S
OURCE
P
ORTLET

................................
................................
................................
........

4

P
ORTLET
2:

E
VENT
T
ARGET
P
ORTLET

................................
................................
................................
........

7

CONFIGURING PORTLETS

................................
................................
................................
.....................

9

P
ORTLET
1:

A
DDING INPUT FORM

................................
................................
................................
...............

9

P
ORTLET
1:

E
NABLE EVENT PUBLISHI
NG

................................
................................
................................
...
13

P
ORTLET
2:

E
NABLE
E
VENT PROCESSING

................................
................................
................................
..
19

P
ORTLET
2:

O
UTPUT FORM G
ENERATION

................................
................................
................................
...
21

DEPLOYING PORTLETS
................................
................................
................................
.........................

32

P
ORTLET
1:

P
UBLISH TO
IBM

W
EB
S
PHERE
A
PPLICATION
S
ERVER V
7.0
................................
....................
32

P
ORTLET
2:

P
UBLISH TO
W
EB
S
PHERE
P
ORTAL V
7.0

................................
................................
..................
33

CONFIGURATIONS ON WE
BSPHERE PORTAL

................................
................................
...............

34

A
DDING
IB
M

W
EB
S
PHERE
A
PPLICATION
S
ERVER V
7.0

AS
WS

P
RODUCER

................................
..............
34

C
ONSUMING THE REMOTE
PORTLET APPLICATION

................................
................................
.....................
36

C
REATING PORTAL PAGE

................................
................................
................................
...........................
39

A
DDING PORTLETS TO PO
RTAL PAGE

................................
................................
................................
.........
42

W
IRING

................................
................................
................................
................................
.....................
46

R
ESULT
................................
................................
................................
................................
......................
47

SUMMARY

................................
................................
................................
................................
..................

48

RESOURCES

................................
................................
................................
................................
..............

48



3

Introduction

Inter
-
portlet communication or IPC is integral to most of portal applicat
ion. In
simple terms, it is a concept using which portlets on same or different portal
pages can communicate or interact with each other.
In the JSR 286 specification,
IPC has been accommodated using eventing.

W
eb
S
ervices
R
emote
P
ortlets
(WSRP)

specificat
ion defines the
w
eb services that generate mark
-
up fragments
within a portal application.
And
WSRP defines a set of common interfaces that
allows portals to display remotely
-
running portlets inside their pages without any
programming.


This article is for
intermediate to advanced audience who is fairly conversant
around basic concepts
,

such as portlet development, portlet specifications,
Web
Services Remote Portlets (
WSRP
), and so on
.
Through this article, we will see
how IBM Rational Application Developer
(RAD)
v8.0.1 can be used to create
portlets
targeting WebSphere Application Server
v7.
0
.x

and WebSphere Portal
Server
v7.0
. We will
examine

how these portlets interact with each other using
WSRP specification.
We will also figure out
how

the
portlets that
run on
IBM
WebSphere Application Server

ultimately are pushed onto a
IBM WebSphere
Portal

server to logically complete the concept of portal using these portlets.

The motivation for such a usecase is an increasing usage

where in a lot of portlet
developmen
t is happening on
IBM WebSphere Application Server

for a variety of
reasons.

Why
and

w
hen WSRP?

Portlet container
,

which is the implementation of portlet specifications
,

is present
i
n both WebSphere Application Server

and WebSphere Portal Server.

This
mea
ns

that one can create portlets and deploy them onto
either of these two
servers.
An increasingly common scenario is development of portlets on
IBM
WebSphere Application Server

and consuming it on a
IBM WebSphere Portal

through

the WSRP specification.

Dev
eloping and testing portlets on
IBM WebSphere Application Server

has some
interesting implications.

1.

It offers a light
-
weight development and test environment which has a low
turnaround time.

2.

It is ideal for portlets that are high on CPU or memory consumpt
ion.

3.

It is useful in case the remote connection is chatty or non
-
existent.

4.

It can be used in situations where different portlets are owned and
controlled by independent teams.

5.

In case portlet quality does not mean over all portal quality, one can run
the
portlet remotely till some time and then move it over to portal when
ready

However, portlets
through the

WSRP
have following

limitations:

1.

IBM extensions in
IBM WebSphere Portal

like specific SPI, API, features
like credential vault, personalization
, and s
o on

are not available.

2.

Also, in case the portlet is very lightweight, the network latency and
administration



4

Usecase
f
or
s
ample
a
pplication

The idea
to use an usecase
is to keep things simple and focus on
knowing the
tools
and ways
that help in
getting W
SRP to work
for
your advantage.


We will create a portlet targeting a
IBM WebSphere Application Server

v7
.0

and
another one targeting a
IBM WebSphere Portal
v7
.0
.
And t
hese
portlets
will
be
come

part of a portal page on
IBM WebSphere Portal

v7
.0

using WSRP.
Finally, we will see how these two portlets interact with each other using JSR286
eventing.
This is a classic case of a remote and a local portlet talking to each
other using inter
-
portlet communication.

Creating Portlets

Portlet 1:
Event Source Portlet

T
o

create
an e
vent source or event publisher

portlet:


1.

Click

File

>
New

>
Project
.





5

2.

Select
Portlet Project
,

and c
lick
Next
.

3.

Enter

the
values
as shown in the following
figure

to
create a JSR286 faces
portlet for
IBM WebSphere Application Server

v7
.0
. The
target runtime
can be
IBM WebSphere Application Server

v7.
0, or later versions
.




Note:
T
he portlet
s

that are
deployed on
IBM WebSphere Application Server

and are

exposed
through

WSRP

also
require

a WSRP Producer.
Before
selecting the

IBM WebSphere Appl
ication Server
, make sure
its

corresponding WSRP producer is available and
installed on it.

S
ee resources
section f
or more information

about
WSRP producer
.



6

4.

Click
finish
. T
he
portlet
JSP

file

opens up in the editor view.
M
odify the
default text
as

show
n

in

the following
figure
.




7

Portlet 2:
Event
Target

Portlet

The second portlet
that we will create
is the event target or event processor.
To
create an event target portlet:

1.

Click

File

>
New

>
Project
.


2.

Select
Portlet Project
,

and c
lick
Next
.

3.

Enter

the valu
es to create a JSR286 faces portlet for
IBM WebSphere
Portal

v7
.0
.




8

4.

Click
finish
. T
he portlet
view
JSP
file
opens up in the editor view.
M
odify the default text
as

show
n

in the following
figure
.







9

Configuring Portlets

Portlet 1: Adding input form


To add input form:

1.

Open
the

WAS7
EventSourceView.jsp

file
.

2.

In the Page Data View,
select
Scripting Variables

>
param

>
New

>
Param Scope Variable
.





3.

Enter

the
parameter
name as
shown in the figure.




4.

The newly created request parameter
displays

in t
he Page Data View
.



10



5.

Select the
greetingMessage

param variable and drag it onto
WAS7EventSource
View.jsp

file.

6.

A feedback message
is

displayed
if you hover
over
the
droppable area.

7.

D
rop the param variable onto
WAS7EventSource
View.jsp

file.

The
Insert
Jav
aBean

dialog displays.







11


8.

Select
Inputting data
.




12

9.


Click
Finish

to generate the input form.




13


Portlet 1: Enable

event publishing

To add publishing event:

1.

Open the
WAS7EventSource
View.jsp

file.

2.

Open
Portlet

drawer from the
Palette
.

3.

Select
Event So
urce Trigger
,
and
dr
ag

it on to the input text box
“{greetingMessage}”.

The
Insert Event Source Trigger

wizard displays.




14

4.

Click

New Event

to create a new event definition for publishing.

The
Event


Enable this Portlet to Publish events

wizard displays.






15

5.

Enter the
Event Name
, and

c
lick
Finish

to complete the event definition
creation.




16

6.

Complete the
fields
of the
Insert Event Source Trigger

wizard as
shown

in the figure
.

7.

Click
Finish
.




8.


The newly create
d

event that the source portlet is publish
ing,
displays

in
the

Enterprise E
xplorer

view
.





17


9.


The
WAS7EventSource
View.jsp

file

gets modified.





10.


This is how the
JSP
code looks like:





18


11.


Delete

the
Submit

button that
was
generated earlier.

The modified code
should look as follows:






12.


Ch
eck
the
pagecode.
WAS7EventSource
View.java

files
. The action method
mapped to the
Submit

button should look like as follows:





19


Portlet 2: Enable Event processing

To enable event processing:

1.

Select

the
WP7EventTarget

portlet node in the
Enterprise Explor
er

view
.


2.

Right
-
click and select
Event
>
Enable this Portlet to Process Event
.

The Enable this Portlet to Process Event wizard displays.




20

3.

Enter

the
e
vent
n
ame
, and c
lick
Finish
.




21

4.

The newly create
d

event that the
target
portlet is
processing
,
lists

in

the
Enterprise Explorer view
.





Portlet 2: Output form generation

To generate output form:

1.

In Enterprise Explorer view
, select
New
>
Class

to create a new java
bean in com.ibm.
wp
7eventtarget package
.

T
he

New Java Class wizard
displays.




22

2.

Enter
MyGre
etingsBean

as class name.

3.

Click
Finish

to create the class.





23

4.

The newly
create
d

Java
class open
s

in the editor view.

5.

Create a string object
greetings
.





24

6.

Right
-
click

in the
MyGreeting
s
Bean.java

class
, and select

Source

>

Generate Gette
rs and Setters
.




25

7.

Select the
greetings

check box.





26

8.

Click
Ok

to generate the getter and setter.





9.

Open
the
WP7EventTarget
View.jsp

file
in editor view.

10.


Select
Page Bean
,

and
select
New

>
JavaBean
.




27

11.


In Add JavaBean

window
,
enter

mygreetingsBean

as Java Bean
name
.

12.


Click
Finish
.




28

13.


Select the newly created page bean object in Page Data
view
, and drag it
onto
WP7EventTarget
View.jsp

file.






29

14.


Select the
Displaying data

check box as shown in
the figure.





30

15.

The output form gets generated in
WP7EventTarget
Vi
ew.jsp

file.






31

16.

Open the
WP7EventTarget
Portlet.java

class in the editor view and modify
it as shown in the following screen

capture
. This code binds the incoming
event value with the bean value which is displayed on the portlet view
JSP
file
.




17.

Open t
he
faces
-
config.xml

file and modify the
scope of the
pc_
WP7EventTarget
View

bean to session
.




32

Deploying Portlets

Portlet 1: Publish to
IBM WebSphere Application Server

v7
.0

To publish the portlet:

1.

Select
WAS7EventSource

in Enterprise Explorer view
, right
-
click and
select

Run on Server

to
publish the portlet.




33

2.
After the portlet is
published, internal

IBM

R
ational
A
pplication
D
eveloper
browser

displays
the portlet

in it
.



Portlet 2: Publish to W
ebSphere
P
ortal

v7
.0

To publish the portlet:

1.

Select

the

portlet project
WP7EventTarget

in Enterprise Explorer view
,
right
-
click and
select
Run on Server

to
publish the portlet.

After you
publish the portlet
, internal
IBM Rational Application Developer

browser

displays
the portlet
. You
can
also right
-
click on t
he portlet view
JSP file
to
publish the portlet.





34

Configurations on WebS
phere portal

Adding
IBM WebSphere Application Server

v7
.0

as
WS

Producer

As mentioned earlier, if you have a WSRP Producer already installed on your
IBM
WebSphere Application Serve
r
, the moment you publish your portlets, they are
available to be consumed remotely.

In this section we will see how this is done
.

To add WSRP producer:

1.

R
ight
-
click on the
IBM WebSphere Portal

v7
.0

server instance in Servers
view
, select
Open Portal
to dis
play the
IBM WebSphere Portal

v7.0
administration

console.





35

2.

Navigate to
Administration

>
Web Services
.

3.

Select the
New Producer
.






4.

Enter

the title and
location

of ws
dl on
IBM WebSphere Application Server

v7
.0

to add the
IBM WebSphere Application Ser
ver

v7
.0

as a web service
producer.




36

Consuming

the

remote portlet application

1.

The remote portlet application is to be consumed into
IBM WebSphere
Portal

v7
.0

next.

2.

Navigate to the
Web Modules
, and s
elect
Consume
.





37

3.

Select the web services producer
th
at
you
have
created

earlier
.








38

4.
A
ll remote portlets that are available for consumption

are listed on the
page
. Select the
WAS7EventSource

portlet and
click
Ok
.

The remote
source portlet
WAS7EventSource

on
IBM WebSphere Application Server

v7
.0

is no
w available for addition to any
IBM WebSphere Portal

v7 page.





















39

Creating p
ortal
p
age

To create
a portal page for housing both the remote source and local target
portlet
:

1.

Open the

IBM WebSphere Portal

v7 admin
istration

console

and select

Administration

>
Manage Pages
.

2.

Select
Content Root

>
Home

page
.

3.

S
elect
New Page
.




40

4.

Enter
WSRPEventing

as page
title

and click
Ok

to create the portal page.




41

5.

The newly created portal page will
be added to
the
existing pages

list
.























42

Adding
p
ortlets
to
portal page


To add
the
remote source and local target portlets to the newly created
portal page
:


1.
Select
Edit Page Layout

icon for
WSRPEventing

page
.





43

2.

Cl
ick

Add portlets
.




44

3.

S
earch or locate the remote source portlet
WAS7EventS
ource

and
select the check box next to it.

4.

Click Ok

to add the portlet to the page.




45

5.

Similarly,
click

Add portlet
,

and locate local target portlet
WP7EventTarget

and add it to the page.




46


Wiring

After

add
ing

the portlets to the page, wire them
to s
tart

events brokered

by the
portal.
To wire portlets:

1.

Select the
Wires

tab
.

2.

In the drop down boxes, select the values as shown
in the figure
.
Select

the source portlet, event it is sending, the target page, target portlet and
the value it is receiving.

3.

S
e
lect
add (
+
)
button at the end of the row to add the wire.




4.

The added wire
displays.





47

Result

1.

To see the portlets in action, navigate to
WSRPEventing

page under
Home

menu
.

2.

Enter
Jaspreet

in the
message
box for
WAS7EventSource

portlet.


3.

Click

Submit
.








48

4.

The page refresh
es

to
show the same string appear in
WP7EventTarget

portlet.




Summary

In this
article
,

we saw how
a portlet hosted on IBM WebSphere Application
Server communicate
s

with another portlet hosted on IBM WebSphere Portal
,

using WSRP.
W
e also
observed

how
IBM

Rational Application Developer
in
conjunction with IBM WebSphere Application Server and IBM WebSphere
Portal
makes interaction between
a remote and local portlet

easy and quick.


Resources

1.

IBM WSRP 2.0 Producer for IBM WebSphere Application Server 7.0 available
on the Portal Catalog