您的位置:首页 > 其它

Portal新特性实战 - 在WebSphere Portal上应用WSRP

2008-04-16 19:43 417 查看
本文介绍了WSRP 标准,并在两台服务器上分别部署远程 portlet 来验证通过 WSRP 进行的互操作。
概要

首先随同本文在IBM WebSphere Portal 5.1服务器上以WSRP协议发布本地Portlet为Remote Portlet,通过WSRP协议消费刚刚发布的Remote Portlet;然后在WSRP参考实现Apache WSRP4J上以WSRP协议发布本地Portlet为Remote Portlet,使用WSRP4J自带的WSRP Consumer测试刚刚发布的Remote Portlet;最后我们在WebSphere Portal服务器上消费WSRP4J上发布的Remote Portlet以检验WSRP在不同应用服务器间的交互性。








回页首
引言

OASIS Web Services for Remote Portlets 技术委员会从2002年开始制定WSRP 1.0标准,目的是开发一个允许门户之间、门户与其他应用之间,能够以即插即用的方式进行用户界面的交互的Web Service标准。

2003年9月3日,OASIS组织发布了WSRP:Web Services for Remote Portlets 1.0标准。WSRP使支持WSRP的容器和符合WSRP的任何门户之间能够进行Portlet级别的互操作性。它的定义包括Remote Portlet的一个WSDL(Web Services Description Language ,Web服务描述语言)接口、通过WSDL定义的一套Remote Portlet交互的语义,以及WSRP服务产生的标记片断的规则。

有了WSRP标准,企业门户不仅可以混合使用不同厂商的门户服务器,灵活地部署Portlets,使用WSRP将企业门户中各个门户服务器统一起来,充分利用到不同门户服务器的特有功能和产品特性。企业门户还可以通过WSRP远程调用合作伙伴提供的远程Portlet服务,把合作伙伴的远程Portlet直接放到本企业的门户界面中,使得企业和合作伙伴的沟通更加方便快捷。

WSRP给服务供应商带来了新的商机。服务供应商可以提供Remote Portlet服务,比如天气预报、股票、新闻、网上定票等服务,企业只需要通过Internet和WSRP协议就可以方便的在企业门户中使用到这些服务,不需要编写任何代码。

在WSRP服务最常见的应用模式中,WSRP 服务是包括表示层与应用程序逻辑的可视的远程门户服务;门户服务器既可以是Remote Portlet的提供者,也可以是Remote Portlet的消费者。门户服务器可以通过Internet,使用WSRP协议把本地Portlet暴露为Remote Portlet,这样门户服务器就是WSRP服务的提供者。门户服务器也可以通过WSRP通用代理跨过 Internet网络,使用WSRP协议调用远程的WSRP服务,这样门户服务器就是WSRP服务的消费者。

WSRP提供者也可以把WSRP服务作为Web Service注册到UDDI服务器上,而WSRP消费者可以到UDDI服务器上查找需要的WSRP服务,进而通过Portlet 代理访问远程WSRP服务。

图1 即插即用的WSRP服务




需要特别指出的是,WSRP服务的消费者也可以是普通的应用程序,通过WSRP协议访问后台WSRP Portlet服务,通过COM组件或者ActiveX控件显示WSRP服务返回的标记片断。IBM Workplace Client Technology(基于Eclipse Rich Client Platform)中将提供WSRP消费者Plug-in,把Remote Portlet集成到其用户界面中来。

本文适用于门户架构师、WebSphere Portal管理员,具有一些 Web Service、WebSphere Portal服务器方面的经验会有所帮助。








回页首
在WebSphere Portal上安装部署WSRP服务

2002年初,IBM在WebSphere Portal 4.0中提供了其专有技术RPWS,通过Web Service把Portlet发布为Remote Portlet;2004年初,IBM在WebSphere Portal 5.0 Fixpack 2开始提供WSRP的技术预览;2004年11月,IBM在WebSphere Portal 5.1中提供WSRP的全面支持。

1.安装Portlet

IBM在WebSphere Portal and Lotus Workplace Catalog网站上提供了叫做WebSphere Portal V5.1 Sample Code的应用(Portlet Application),其中有基于Struts框架的使用IBM Portlet API的portlets,也有使用JSR 168 API编写的portlets。任何人都可以通过IBM Portlet代码"1wp10004n" 检索并免费下载这个应用。下面我们在WebSphere Portal上面部署这个Portlet。解压缩下载的1wp10004n.zip文件,进入1wp10004n/Basic/JSR168目录,我们会看到jsrHelloJSP.war等4个war文件,这些war文件都是打包的JSR 168 Portlet例子应用。

在WebSphere Portal管理页面中选择Portlet 管理-> Web 模块,选择"安装"命令按钮,选择jsrHelloJSP.war文件,选择"下一步"开始安装即可。在Portlet 管理 ->Portlets可以检索到刚刚安装的Hello JSP (JSR 168)。最后我们把这个Portlet放到测试页面上。结果如图2。

图2 Hello JSP(JSR 168)运行结果




2.提供portlet

在WebSphere Portal管理页面中选择Portlet 管理-> Web 模块,搜索标题的开头为"Hello"的Portlet,在"Hello JSP(JSR 168)"小程序的右边有五个命令按钮,选择最左边的"提供portlet"按钮,就可以把这个Portlet发布为Remote Portlet。

图3提供portlet




在Portlet管理界面中我们看到"成功将portlet Hello JSP(JSR 168)提供为Web服务",并且这个Portlet显示出"已提供"的标记。

图4 已提供Portlet




我们刚刚安装了一个JSR 168 Portlet,通过WSRP把这个portlet提供为Remote Portlet。下面我们将消费这个Remote Portlet。

3.注册WSRP Producer

在WebSphere Portal管理页面中选择Portlet 管理->Web Service,选择新建Producer。输入标题,输入WPS 5.1的WSDL服务定义的URL,比如http://wps51.cn.ibm.com:9081/wps/wsdl/wsrp_service.wsdl

图5新建Producer




4.消费Remote Portlet

在WebSphere Portal管理页面中选择Portlet 管理->Web模块,选择"使用"命令按钮,鼠标左键点击刚注册的Web Service Provider。

图 6使用portlet




WebSphere Portal作为WSRP的消费者,通过WSRP协议检索WSRP提供者提供的Remote Portlet。在图7我们看到刚刚注册的"WSRP Producer on WP 5.1"提供了多个Remote Portlet,"选择"Hello JSP(JSR 168),确认,在图8中我们看到一个叫做RP[Hello JSP(JSR 168)]的Portlet,我们可以把这个Remote Portlet象本地Portlet一样部署到测试页面上,运行结果如图9所示。

图 7 选择Web service




图 8选择Web service的结果




图 9 包含Remote Portlet的测试页面











回页首
安装JSR 168参考实现Apache Pluto

Apache Software Foundation 在2004年12月22日发布了 Java Portlet Specification 1.0参考实现Pluto 1.0.1-rc2版本。版本号中的rc表示release candidate,rc2表示这个版本已经是第二个发布候选版本,离正式版本1.0.1的发布已经很近了。

1 安装Pluto二进制发行版本

Pluto提供了四种打包方式,其中最简单的打包方式是和Tomcat 5.5.4(Build Oct 29 2004)捆绑在一起的二进制发行版本,只要在Pluto下载网站下载pluto-1.0.1-rc2.zip文件,解压缩到指定目录就可以了。注意:pluto-1.0.1-rc1二进制发行版本采用的是Tomcat 5.0.28。

如果在启动Tomcat的时候提示启动系统找不到文件 -Djava.endorsed.dirs=,那么可以在命令行下面执行 set J***A_HOME=c:/jdk1.5.0

图 10 Pluto界面




2 安装Pluto源代码发行版本

Pluto另外一种常用的发行版本是源代码发行版本,目前,要在Pluto上自动部署新的portlet,必须使用这种版本。在Pluto下载网站下载pluto-src-1.0.1-rc2.zip文件,参考Pluto安装指南进行安装即可。

安装这种发行版本,事先要下载Tomcat、Marven,在部署的时候要求有Internet连接,部署程序会从Internet上下载需要的java package。

注意,pluto-src-1.0.1-rc2可以使用JDK 1.4.2进行部署,但是不能使用JDK 1.5进行部署。使用JDK 1.5会报如下错误:

pluto-src-1.0.1-rc2/portal/src/java/org/apache/pluto/portalImpl/om/common/impl/LanguageImpl.java:58: as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
(try -source 1.4 or lower to use 'enum' as an identifier)

3 使用Pluto源代码发行版本在在Pluto上部署Portlet

设置J***A_HOME、M***EN_HOME、PATH等环境变量。

set J***A_HOME=C:/j2sdk1.4.2 
SET M***EN_HOME=C:/apache/maven-1.0.2
SET PATH=%M***EN_HOME%/bin;%PATH%


拷贝WebSphere Portal V5.1 Sample Code中的jsrHelloJSP.war到c:/apache目录。

进入Pluto源代码发行版本的根目录,调用maven部署Portlet到Pluto。

CD C:/apache/pluto-src-1.0.1-rc2
maven deploy -Ddeploy=c:/apache/jsrHelloJSP.war


注意:下面的部署新的portlet操作在Pluto

1.0.1-rc2源代码版本版本中不能工作,但是可以在Pluto运行版本中可以正常工作。

进入Pluto的webapps目录,我们会看到有个jsrHelloJSP目录,这里就是部署后的Portlet目录。

Pluto部署代码在jsrHelloJSP/WEB-INF/tld目录下面增加了一个portlet.tld文件,同时在web.xml文件中增加了对做个portlet.tld文件的引用。

<taglib>
         <taglib-uri>http://java.sun.com/portlet</taglib-uri>
         <taglib-location>/WEB-INF/tld/portlet.tld</taglib-location>
</taglib>

我们需要手工删除部署后的web.xml文件中对于std-portlet.tld的引用内容:

<taglib>
         <taglib-uri>http://java.sun.com/portlet</taglib-uri>
         <taglib-location>/WEB-INF/tld/std-portlet.tld</taglib-location>
     </taglib>

部署Portlet到页面的方法参考Pluto安装指南即可。需要注意的是Pluto安装指南中application ID指的就是应用名称jsrHelloWorld,PortletID指的是web.xml文件中的portlet-guid参数值。

<init-param>
             <param-name>portlet-guid</param-name>
             <param-value>jsrHelloJSP.Hello JSP Portlet name</param-value>
         </init-param>








回页首
安装WSRP 参考实现Apache WSRP4J

1 安装WSRP4J

阅读WSRP4J安装文档,下载Tomcat 5(比如jakarta-tomcat-5.0.30版本),解压缩到c:/apache/ jakarta-tomcat-5.0.30-wsrp4j。

如果在启动Tomcat的时候提示启动系统找不到文件 -Djava.endorsed.dirs=,那么可以在命令行下面执行 set J***A_HOME=C:/j2sdk1.4.2或者把这一行加入到bin/startup.bat和bin/shutdown.bat里面。

注意:WSRP4J使用的Pluto不是最新的版本,所以WSRP4J要使用JDK 1.4.2,而不是最新的Pluto使用的JDK 1.5。

参考http://ws.apache.org/wsrp4j/contributing/cvs.html,使用cvs client下载WSRP4J源代码。

set path="C:/Program Files/CVS for NT";%path%
cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic login
    password: anoncvs
cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic checkout ws-wsrp4j

更改下面三个目录下面的build.properties.example文件的文件名为build.properties

ws-wsrp4j/build/
ws-wsrp4j/portlets/proxyportlet
ws-wsrp4j/portlets/wsrptest

修改上述三个文件build.properties,设置TOMCAT_HOME=C:/apache/ jakarta-tomcat-5.0.30-wsrp4j

安装WSRP4J到Tomcat 5:

set J***A_HOME=C:/j2sdk1.4.2
set path=%J***A_HOME%/bin;%path%
cd ws-wsrp4j/build
install-swing-consumer 
install-provider-pluto

最后显示下面字样,就是已经成功安装了基于Pluto的WSRP provider,并且安装了一个测试用Portlet-'wsrptest'。

prepare-producer:
Created dir: C:/Apache/jakarta-tomcat-5.0.30-wsrp4j/webapps/wsrp
…
prepare-provider-pluto:
Copying 13 files to C:/Apache/jakarta-tomcat-5.0.30-wsrp4j/webapps/wsrp
Copying 1 file to C:/Apache/jakarta-tomcat-5.0.30-wsrp4j/webapps/wsrp/WEB-INF/lib
…
BUILD SUCCESSFUL
Total time: 3 seconds

2 测试WSRP4J消费者程序

启动Tomcat,缺省Tomcat监听8080端口。

set J***A_HOME=C:/j2sdk1.4.2
Cd C:/apache/jakarta-tomcat-5.0.30-wsrp4j/bin
startup.bat

执行脚本C:/apache/ws-wsrp4j/tools/tunnel.bat以启动Apache Axis TCP Monitor,这个Monitor一般用于web service debug。通常Tomcat监听8080端口,tunnel脚本缺省监听8081端口并且向8080端口写数据。

set CLASSPATH=C:/apache/ws-wsrp4j/driver/SwingConsumer/lib/axis.jar
rem java org.apache.axis.utils.tcpmon [listening_port] [target_host] [target_port]
java org.apache.axis.utils.tcpmon 8081 localhost 8080

运行WSRP Consumer(消费程序,调用远程Remote Portlet),缺省WSRP Consumer通过8081连接WSRP Producer。

cd C:/apache/ws-wsrp4j/driver/SwingConsumer
run.bat

图 11 WSRP4J Consumer




3 在WSRP4J上发布新的Remote Portlet

从%Pluto_Home%/webapps目录下拷贝testsuite目录到%WSRP4J_Home%/webapps目录下。

从%Pluto_Home%/webapps/pluto/WEB-INF/data/portletentityregistry.xml文件中拷贝testsuite.TestPortlet1的定义到%WSRP4J_Home%/webapps/wsrp/WEB-INF/data/portletentityregistry.xml文件中。

<application id="3">
         <definition-id>testsuite</definition-id>
         <portlet id="1">
             <definition-id>testsuite.TestPortlet1</definition-id>
             <preferences>
                 <pref-name>TestName4</pref-name>
                 <pref-value>TestValue4</pref-value>
                 <read-only>true</read-only>
             </preferences>
         </portlet>
</application>

你也可以通过Pluto源代码的maven deploy命令在Pluto上面部署新的Portlet,然后把相应的目录(比如jsrHelloJSP)拷贝到%WSRP4J_Home%/webapps目录下,然后编辑相应的WSRP4J portlet注册文件。

4 为WSRP4J Consumer提供新的WSRP Portlet服务

接下来为WSRP Consumer配置要消费的Remote Portlet的handler、放置Remote Portlet的测试页面。在driver/SwingConsumer/persistence/portlets目录下面增加一个文件,org.apache.wsrp4j.consumer.driver.WSRPPortletImpl@WSRP4J_3_1.xml。

<?xml version="1.0"?>
<Portlet>
     <portlet-key>
         <portlet-handle>3.1</portlet-handle>
         <producer-id>1</producer-id>
     </portlet-key>
     <parent-handle>3.1</parent-handle>
</Portlet>

修改driver/SwingConsumer/persistence/pages/org.apache.wsrp4j.consumer.app.driver.PageImpl@WSRP4JTestPortlets.xml文件,

<?xml version="1.0" encoding="UTF-8"?>
<page pageID="1" title="WSRP4J Test"><portlet-key xsi:type="java:org.apache.wsrp4j.consumer.driver.PortletKeyImpl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<portlet-handle>3.1</portlet-handle>
<producer-id>1</producer-id>
</portlet-key></page>

重新启动WSRP服务和WSRP消费者程序,运行结果如下:

图12 WSRP Consumer测试新增加的Remote Portlet - Pluto testsuite




如果是把jsrHelloJSP portlet发布到WSRP4J上面,运行结果如下:

图 13 WSRP Consumer测试新增加的Remote Portlet - jsrHelloJSP











回页首
WebSphere Portal调用WSRP4J发布的Remote Portlet

现在我们已经有两个WSRP的支撑环境了,他们都能各自独立地发布和消费Remote Portlet。现在让我们测试一下他们的互通性。

1. 注册WSRP Producer

在WebSphere Portal管理页面中选择Portlet 管理->Web Service,选择"新建Producer"。输入标题,输入WSRP4J的WSDL服务定义的URL,比如http://localhost:8081/wsrp/wsdl/wsrp4j_service.wsdl。

图14 新建Producer




图15 成功创建Producer




2.消费Remote Portlet

在WebSphere Portal管理页面中选择Portlet 管理->Web模块,选择"使用"命令按钮,鼠标左键点击刚注册的Web Service Provider。 WebSphere Portal作为WSRP的消费者,通过WSRP协议检索WSRP提供者提供的Remote Portlet。在图16我们看到WSRP4J提供了多个Remote Portlet,"选择"Hello JSP portlet (JSR 168) 和WSRP Test Portlet。我们可以把这个Remote Portlet象本地Portlet一样部署到测试页面上,运行结果如图17所示



图 16 选择Web service




图17 WebSphere Portal消费WSRP4J提供的Remote Portlet




注意事项:

1.如果需要通过不同的IP地址和端口访问WSRP4J,需要修改WSRP4J的webapps/wsrp/wsdl/wsrp4j_service.wsdl文件中的主机名和端口号。

2. WebSphere注册WSRP4J为web service producer后,这个Producer的Registration handle 为192.168.200.132_1107045794015_2(例子)。相应的WSRP4J会产生一个两个文件登记WebSphere Portal为Consumer,这两个文件分别是org.apache.wsrp4j.producer.driver.RegistrationImpl@14647882.xml,和org.apache.wsrp4j.producer.provider.driver.ConsumerPortletRegistrationImpl@192.168.200.132_1107045794015_2.xml。

3. WebSphere Portal在"消费"WSRP4J提供的Remote Portlet的时候,WSRP会修改webapps/wsrp/WEB-INF/data/ portletentityregistry.xml文件。

比如这个文件中原始的关于jsrHelloJSP的注册信息如下:

<application id="5">
         <definition-id>jsrHelloJSP</definition-id>
         <portlet id="1">
             <definition-id>jsrHelloJSP.Hello JSP Portlet name</definition-id>
             <preferences>
                 <pref-name>TestName4</pref-name>
                 <pref-value>TestValue4</pref-value>
                 <read-only>true</read-only>
             </preferences>
         </portlet>
     </application>

在WebSphere Portal把jsrHelloJSP注册以后,WSRP4J会复制一份portlet的定义,并且指定新的portlet的id(比如192.168.200.132_1107046841484_0)。结果如下:

<application id="5">
         <definition-id>jsrHelloJSP</definition-id>
         <portlet id="192.168.200.132_1107046841484_0">
             <definition-id>jsrHelloJSP.Hello JSP Portlet name</definition-id>
             <preferences>
                 <pref-name>TestName4</pref-name>
                 <pref-value>TestValue4</pref-value>
                 <read-only>true</read-only>
             </preferences>
         </portlet>
         <portlet id="1">
             <definition-id>jsrHelloJSP.Hello JSP Portlet name</definition-id>
             <preferences>
                 <pref-name>TestName4</pref-name>
                 <pref-value>TestValue4</pref-value>
                 <read-only>true</read-only>
             </preferences>
         </portlet>
</application>

4. 通过WSRP注册的Portlet的标题是从该Portlet的portlet.xml文件中portlet-info->title标记中获得的。

<portlet-info>
   <title>Hello JSP portlet (JSR 168) Title</title>
   <short-title>Hello Title</short-title>
   <keywords>WSRP, Hello JSP</keywords>
         </portlet-info>

原文 http://www.ibm.com/developerworks/cn/websphere/library/techarticles/yangjiang/0502/wsrp.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐