Write a portlet service by defining the interface, writing
the service implementation, making the service accessible for IBM
portlets, and registering the service.
The service provider interfaces can be used to write portlet services
for IBM portlets as well as for Standard portlets. The IBM Portlet
API has been deprecated for IBM® WebSphere® Portal Version
6.1, but is still supported. No new functionality will be added and
it is recommended that you use the Standard portlet API. For backward-compatibility,
the service provider interfaces from the org.apache.jetspeed.portlet.service.spi packages
are supported. For writing new portlets services, however, you should
use only the service provider interfaces described in this text.
Defining the interface
This
step is not required if you want to implement your service against
an existing interface. Defining a portlet service interface requires
the same careful considerations as defining any public API interface.
A portlet service interface must extend the PortletService interface
defined in the com.ibm.portal.portlet.service package.
The following is an example interface for the HelloWorldService .
Writing the service implementation
The
service implementation must implement the PortletServiceProvider interface
of the com.ibm.portal.portlet.service.spi package
to be able to make use of the portlet service life cycle methods
in addition to your service interface. The PortletServiceConfig parameter
of the init() method allows you, for example, to access the configuration
of the service (see Registering the service
for more information).
Making the service accessible for
IBM portlets
This step is optional. If you want your portlet
service to be available for IBM portlets, you need to create an additional
service interface that extends org.apache.jetspeed.portlet.service.PortletService and
provides the same functionality.
You can have a single implementation that is registered
for both interfaces and implements both. If the service methods take
arguments that are classes or interfaces from the portlet API, the
method signatures are different for the two service interfaces. You
can still use a common implementation for both interfaces by using
the APIConverterFactory class of the com.ibm.portal.portlet.apiconvert package.
This class includes methods that wrap objects from the IBM portlet
API, such as PortletRequest and PortletSession,
and implement the corresponding standard portlet API objects on the
service side, so that you can re-use your service implementation for
standard portlets.
Registering the service
Put all service interface and implementation classes into a JAR
file.
Place the JAR file in the wp_profile_root/PortalServer/config directory.
Register the new portlet service with the WP PortletServiceRegistryService resource
environment provider in the WebSphere Integrated Solutions Console.
Create an entry to register the implementation in the JNDI directory.
The name for this entry is jndi.service_interface and
the value is service_implementation. The fully
qualified service interface name can then be used to lookup the service.
If you provide a service interface for IBM portlets, create an
entry to register the implementation for this interface as well. The
name for this entry is service_interface and the
value is service_implementation. Services that
are registered this way are not retrieved from JNDI, but from the
PortletContext interface of the IBM portlet API.
Optional: Provide configuration parameters for
the implementation. The name for this entry is service_implementation.parameter
and the value is the required parameter value.
Restart WebSphere Portal to
activate the new settings.
In the following example, HelloService is
the name of the portlet service, HelloServiceIBM is
the name of the interface for IBM portlets, and the message configuration
parameter is set with the value Greetings.
Note: The
colon (:) used in previous versions of WebSphere Portal to designate JNDI
entries with jndi: is not supported for resource
environment providers. Use jndi. instead.
To
register this portlet service, add the following property names and
values to the PortletServiceRegistryService:
Property name
Value
jndi.sample.portletservice.HelloService
sample.portletservice.HelloServiceImpl2
sample.portletservice.HelloServiceIBM
sample.portletservice.HelloServiceImpl2
sample.portletservice.HelloServiceImpl2.message
Greetings
Tip: To check whether your service
has been registered successfully, use the application server dumpNamespace tool.
The following command, executed from the was_profile_root/bin directory,
will list all portlet service entries in JNDI:
dumpNamespace -port bootstrap_port -root server -startAt portletservice
Using the WebSphere Integrated Solutions Console, you can find the
bootstrap port of your portal server in the "End Points" section of
the settings for the server "WebSphere_Portal".