技术开发 频道

Java Web 服务: Axis2 WS-Security 基础

  样例应用程序

  示例代码中提供的应用程序(见 下载)基于我在 “Axis2 数据绑定” 中用于演示 Axis2 数据绑定方法的示例。对于本文以及有关 Axis2 WS-Security 支持的后续文章,我将这个示例精简到三个操作:getBook、addBook 和 getBooksByType。为了保持简单性,只提供了 Axis Data Binding (ADB) 版本的代码,但是这并不是在 Axis2 中使用 WS-Security 的必需要求 — Rampart 可以独立于代码使用的数据绑定技术实现 WS-Security,因此它可以处理 Axis2 支持的所有形式的数据绑定。

  示例代码的根目录为 jws04code。在该目录内部,将找到 Ant build.xml 和 build.properties 文件,以及为示例应用程序提供服务定义的 library.wsdl 文件,用于配置客户端登录的 log4j.properties 文件,以及一些属性定义 XML 文件(全部命名为 XXX-policy-client.xml 或 XXX-policy-server.xml)。build.properties 文件配置示例应用程序的操作。清单 2 展示了这个属性文件的附带版本:

  清单 2. 附带的 build.properties 文件

# set axis-home to your Axis2 installation directory
axis
-home=PATH_TO_AXIS2_INSTALLATION
#
set the connection protocol to be used to access services (http or https)
protocol
=http
#
set the name of the service host
host
-name=localhost
#
set the port for accessing the services (change this for monitoring)
host
-port=8080
#
set the base path for accessing all services on the host
base
-path=/axis2/services/
#
set the name of the policy file to be used by the client
client
-policy=plain-policy-client.xml
#
set the name of the policy file to be used by the server
server
-policy=plain-policy-server.xml

  在尝试使用示例应用程序前,需要编辑 build.properties 文件并将实际路径设置为 Axis2 安装(添加了 Rampart,如前一小节所述)。如果对服务器使用了不同的主机或端口号,还需要修改 host-name 和 host-port 值。我将在本文后面讨论其余的值。

0
相关文章