7


WAP 网关 API

本章介绍了 Sun Java System Content Delivery Server WAP 网关 API。此 API 从 HTTP 头中检索 MSISDN、设备配置文件以及其他属性。基于用户名和密码的身份验证在 WAP 网关集成中不是必需的。

图 7-1 是与 API 和访问点进行交互的通用系统组件的简单表示。其中还包括一些未与 API 进行交互、却是全面理解体系结构所需的组件。

图 7-1 WAP 网关适配器体系结构


WAP 网关适配器的概述。此图以文本形式进行说明。

设备通过 WAP 网关将 WAP 请求发送到 Content Delivery Server。Content Delivery Server 中的 WAP 网关适配器从 WAP 网关解析 HTTP 头并获得 MSISDN。订户适配器使用 MSISDN 或唯一 ID 来访问用户配置。

有关所有类和方法的信息,请参见 $CDS_HOME/javadoc/cdsapi/index.html 中的 WAP 网关 API 的 Javadoc 工具的 HTML 输出。


7.1 WAPGatewayAdapter

公用的抽象 WAPGatewayAdapter 类定义从 HTTP 头获得 MSISDN 以及唯一设备 ID 的方法。它还用于定义检查是否支持或可以实现此方法的方法。

可以扩展此类并实现所有抽象方法。有关其他信息,请参见 $CDS_HOME/javadoc/cdsapi/index.html 中的 WAP 网关 API 的 Javadoc 工具的 HTML 输出。


7.2 使用 WAP 网关 API

Content Delivery Server 为以下 WAP 网关提供了 API 实现。

必须配置 WAP 网关,以将 MSISDN 或唯一设备 ID 转发到 Content Delivery Server。cdsapi.jar 中提供了 WAPGatewayAdapter 类。为方便起见,$CDS_HOME/dist/cds/staging/jar 目录中提供了所有 Content Delivery Server JAR 文件的副本。

要为任何其他 WAP 网关注册一个新类以扩展 WAPGatewayAdapter 类,请将类文件名添加到 $CDS_HOME/deployment/deployment-name/conf 目录中的 wapgateway.config 文件中。下面的示例语句说明了如何在 Content Delivery Server 中注册 Nokia Activ Server 2.0.1 适配器。


module.gateway.id=
com.sun.content.server.common.gateway.nokia.NokiaActivServerWAPGateway

 

使适配器可用于 Content Delivery Server 取决于所使用的应用服务器,以及是否已部署了该服务器。要使适配器可用,请执行以下操作:

1. 为适配器创建 JAR 文件。

2. 对于所有应用服务器,请将该 JAR 文件放在 $CDS_HOME/dist/cds/lib/external 目录中。

现在,该适配器将包含在所有以后的部署中。

3. 如果现有部署需要使用该适配器,请将该 JAR 文件放在每个部署的 $CDS_HOME/deployment/deployment-name/lib/external 目录中。

如果使用的是 WebLogic Server,则会为您处理类路径。

如果使用的是 Sun Java System Application Server,则会为每个部署更新类路径:

a. 在编辑 $CDS_HOME/deployment/deployment-name/sun/domains/cdsdomain/config/domain.xml 文件之前,先对其进行备份,以便从编辑期间可能引入的任何错误中恢复。

b. 编辑 domain.xml 并修改 java-config 元素,将 JAR 文件的绝对路径添加到 classpath-suffix 属性中。

c. 保存所做的更改。

4. 重新启动任何现有部署以识别新的 JAR 文件。


7.3 样例 WAP 网关适配器

以下代码示例显示了用于扩展 WAPGatewayAdapter 类的 SampleWAPGateway 的适配器的伪代码。


编码样例 7-1 使用 WAPGatewayAdapter 类的示例
package com.sun.content.server.service.gateway.sample;
 
import com.sun.content.server.service.gateway.WAPGatewayAdapter;
import com.sun.content.server.service.gateway.WAPGatewayException;
import javax.servlet.http.HttpServletRequest;
 
public class SampleWAPGateway extends WAPGatewayAdapter
{
  /* Method to check if the passed method is implemented in this
   * class or not. */
  public boolean doHandle(String method) throws WAPGatewayException
  {
    if (method.equals("getMSISDN"))
      return true;
    return false;
  }
 
  /* Gets the MSISDN from the header and returns as a string. */
  public String getMSISDN(HttpServletRequest request)
  {
    return request.getHeader("<key to retrieve>");
  }
 
  /* This method is not implemented. */
  public String getUniqueId(HttpServletRequest req)
throws WAPGatewayException
  {
    throw new WAPGatewayException("This method is not implemented");
  }
}