使用远程 Web Service API

您可以在应用程序中使用 IBM® Rational® Asset Manager Web Service。

关于此任务

注意: Web Service API 以及 HTTP 上载和载机制都是内部 API,不受支持。 使用它们的风险由您自己承担。

Rational Asset Manager 发布允许您使用存储库的 Web Service。 使用 Rational Asset Manager Web Services Descriptor Language (WSDL) 文件开发与 Rational Asset Manager 服务器交互的定制应用程序。

过程

如要使用 Web Service 与 Rational Asset Manager 服务器连接:

  1. 导航到 Rational Asset Manager Web 客户机中的扩展页面。
  2. 在 Web Service 中,单击 RAM1.wsdl 链接以下载该 WSDL 文件。
  3. 为了使用 Web Service,您必须通过 WSDL 生成客户机代理以便与服务器交互。
  4. 一旦为 WSDL 生成代理后,可访问以下 Web Service URL:http://server:port/com.ibm.ram.repository.web.ws.was/RAMServices,其中 server 是服务器的主机名,port 是端口号,com.ibm.ram.repository.web.ws.was 是 Web Service Web 应用程序,RAMServices 是可使用 Web Service 的位置。客户机在进行调用时应该启用重定向,因为 RAMServices 会自动将该调用重定向至适当的位置。

    客户机可访问 http://server:port/com.ibm.ram.repository.web.ws.was/RAMServices 来获取服务。用于调用 Web Service 的此单个位置会将客户机重定向到匿名服务器位置 http://server:port/com.ibm.ram.repository.web.ws.was/services/RAM1 或基本认证位置 http://server:port/com.ibm.ram.repository.web.ws.was/RAMSecure/services/RAM1,具体取决于请求中是否存在用户凭证。

    如果客户机倾向于直接访问匿名服务和基于基本认证的服务,那么它们可通过分别使用 http://server:port/com.ibm.ram.repository.web.ws.was/services/RAM1http://server:port/com.ibm.ram.repository.web.ws.was/RAMSecure/services/RAM1 端点来完成此任务。

  5. 连接至服务器:
    • 如果要以已登录用户身份进行连接,请使用 HTTP 基本认证提供用户名和密码。
    • 如果要以匿名方式进行连接,请不要提供用户名和密码。
  6. Rational Asset Manager 具有许可证发放模式,该模式为连接到服务器的每个用户提供一个许可证。如果您进行多次调用并要保持相同的许可证高速缓存,那么与服务器的连接和您的会话将保持相同的许可证。
  7. 使用在 Rational Asset Manager Javadoc 中找到的 API,该 Javadoc 位于帮助的“参考”部分。

结果

切记: 要使用 HTTPS SSL 安全连接进行连接,请确认服务器的公用密钥位于要使用 HTTPS 的客户机的密钥环中。

示例

用于调用 Web Service 的示例类:
public class RAMClient {
  public static final String RAM_LOCATION = "http://server:port/com.ibm.ram.repository.web.ws.was";

  public void doSearchAndDownload() throws Exception {
    String SECURE_PREFIX = "/RAMSecure"; // To be used when username and password are provided
    String RAM_WS_LOCATION = RAM_LOCATION + SECURE_PREFIX + "/services/RAM1";
    String USERNAME = "admin";
    String PASSWORD = "admin";

    // Construct WebSerivces stub
    RAM1 ramWebService = new RAM1ServiceLocator().getRAM1(new URL(RAM_WS_LOCATION));
    if (ramWebService instanceof Stub) {
      Stub axisStub = (Stub) ramWebService;
      // Set user name and password
      axisStub.setUsername(USERNAME);
      axisStub.setPassword(PASSWORD);
    }

    // Get constants for invoking WebServices
    Constants constants = ramWebService.getConstants();

    // Search for assets with name starting with 'soa' and owned by 'admin' user.
    String[] queries = new String[2];
    queries[0] = constants.getQUERY_NAME()+":(soa*)";
    queries[1] = constants.getQUERY_OWNER()+":(admin)";
    SearchResultSO searchResults = ramWebService.search(queries, null, true, 
      constants.getSORT_LAST_MODIFIED(), 0, -1, -1, false, Locale.getDefault().toString());

    // Download assets got from search
    String RAM_ASSET_LOCATION = RAM_LOCATION + SECURE_PREFIX + "/RAMAssetAccess.jsp?";
    SearchAssetInformationSO[] searchAssets = searchResults.getSearchAssets();
    for (int ac = 0; ac < searchAssets.length; ac++) {
      String assetID = searchAssets[ac].getGUID();
      String assetVersion = searchAssets[ac].getVersion();

      String encodedAssetID = URLEncoder.encode(assetID, "UTF-8");
      String encodedAssetVersion = URLEncoder.encode(assetVersion, "UTF-8");

      String assetLocation = RAM_ASSET_LOCATION + "assetid="+encodedAssetID+"&version="+encodedAssetVersion;
      downloadAssetUsingHTTPGet(assetLocation, USERNAME, PASSWORD);
    }
  }

  private void downloadAssetUsingHTTPGet(String assetLocation, String username, String password) {
    // Download asset
  }
}

反馈