Device Manager


通过管理 API 构建应用程序


本部分中描述了以下主题:

简介

使用 dmapi.jar 文件中包含的管理 API 或从 WSDL 文件生成的 API 可以开发您的应用程序。管理 API 包括用于 Web 服务的代理和用于输入输出参数的支持类。支持类是用作代理方法的输入输出参数的 JavaBeans。

有关管理 API 的 Javadoc 信息位于 DeviceManager/api/doc 目录中。您还可以参阅 DeviceManager/api/wsdl 目录中的 WSDL 文件。

设置环境

要编译应用程序,必须已安装有 WebSphere 环境,如 WebSphere Application Server、Rational Application Developer 或 WebSphere Application Client。

必须使用 JRE 1.4.2(或更高版本)并将 dmapi.jar 文件与以下 WebSphere 运行时文件添加到类路径:

对于运行在 J2EE 容器中的受管客户机,您应当配置客户机部署描述符(web.xml、ejb-jar.xml 或 application-client.xml)。 要获取示例,请参阅安装在 DeviceManager/api/j2ee 目录中的 application-client.xml 版本。 受管客户机作为 Web 归档文件 WAR、EJB JAR 或应用程序客户机 JAR 文件的一部分打包。要了解更多信息,请参阅 WebSphere 信息中心中有关“开发 Web Service 客户机”部分。

要在 J2EE 环境中运行受管客户机应用程序,只需在类路径中有 dmapi.jar 文件。WebSphere 容器提供对所有其他必需类的访问。 如果应用程序运行在 WebSphere 应用程序客户机环境中,请使用 launchClient 实用程序。

要使用 java 命令运行非受管客户机应用程序,需要调用 WebSphere setupCmdLine 脚本,然后使用以下命令:(为了便于阅读,该命令以多行显示。实际使用时只需一行。)

对于 Windows:

"%JAVA_HOME%\bin\java" "-Xbootclasspath/p:%WAS_BOOTCLASSPATH%"
-Djava.security.auth.login.config="%WAS_HOME%\properties\wsjaas_client.conf"
-Djava.ext.dirs="%WAS_EXT_DIRS%;%JAVA_HOME%\jre\lib\ext" -classpath "%WAS_CLASSPATH%;dmapi.jar"
fully_qualified_class_name_to_run  your_application_parameters

对于 AIX、Linux 和 Solaris:

"$JAVA_HOME/bin/java" "-Xbootclasspath/p:$WAS_BOOTCLASSPATH"
-Djava.security.auth.login.config="$WAS_HOME/properties/wsjaas_client.conf"
-Djava.ext.dirs="%WAS_EXT_DIRS%:%JAVA_HOME%\jre\lib\ext"   -classpath "$WAS_CLASSPATH:dmapi.jar
fully_qualified_class_name_to_run  your_application_parameters

注:在某些环境中,WAS_BOOTCLASSPATH 变量为空,因此应忽略 -Xbootclasspath 参数。

对 Web Service 调用进行编程

要使用 dmapi.jar 调用 Device Manager 服务器上的 Web Service,请执行以下步骤:

  1. 实例化代理。

  2. 可以选择设置本地化语言环境。

  3. 可以选择调用 setEndpoint 方法来配置 Device Manager 服务器的目标。

  4. 按需要构造输入参数。

  5. 调用一个或多个代理方法来调用 Web 服务。

  6. 捕获所有产生的异常。

使用以下样本作为如何在 Device Manager 数据库中创建 Software 对象的指导。

import com.tivoli.dms.api.*;
import com.tivoli.dms.api.proxy.*;
      try {
   //Instantiate proxy
SoftwareManagerProxy proxy = new SoftwareManagerProxy();
   //proxy.setLocale(new Locale("fr","FR"));
   //proxy.setEndpoint(new URL("http://server_name/dmserver/services/SoftwareManagerService"));


   //create Software object
      //The software package must exist on the Web
      //server for createSoftware to be successful.
Software sw = new Software();
      sw.setSoftwareType("WINCE_PACKAGE");
      sw.setSoftwareURL("http://server/testsw.pkg");

   //create Software on Device Manager server
   long swid = proxy.createSoftware(sw,null,null);
} catch (DeviceManagerException e) {
   System.out.println("Exception occurred in api - " + e);
}

要使用从 WSDL 文件(受管客户机环境)生成的 API 来调用 Device Manager 服务器上的 Web Service,请执行以下步骤(使用以下代码作为指南):

  1. 确保生成的 API 类在类路径中。

  2. 确保客户机部署描述符文件位于 WEB-INF 目录或 META-INF 目录中。

  3. 实例化 InitialContext 方法。

  4. 使用 JNDI 查询以查找服务工厂。

  5. 使用工厂 getSoftwareManagerService 方法获取服务端点接口(SEI)。或者,可以传递 URL 以配置 Device Manager 服务器的目标。

  6. 构造输入参数。

  7. 调用存根方法来调用 Web 服务。

  8. 捕获所有产生的异常。

样本代码:

import com.tivoli.dms.api.*;
import javax.naming.*;
import javax.rmi.RemoteException;
import java.net.URL;
import java.net.MalformedURLException;
public static void main(String[] args) {
  javax.naming.InitialContext ic = null;
  SoftwareManagerService sw_sei = null;
  SoftwareManagerServiceService sw_factory = null;
		
      try {
     //Use JNDI lookup to get factory
    ic = new javax.naming.InitialContext();
    sw_factory = (SoftwareManagerServiceService)ic.lookup("java:comp/env/service/SoftwareManagerServiceService");
			
  } catch (NamingException nme) {
        nme.printStackTrace();			
return;
  }


      try {
       //get access to SEI
      sw_sei = sw_factory.getSoftwareManagerService(new URL("http://hostname:80/dmserver/services/SoftwareManagerService"));
			
      //The SEI is also the stub which we can use to set the uid/pw
         //The userid/password can also be set in the deployment descriptors
SoftwareManagerServiceSoapBindingStub stub = (SoftwareManagerServiceSoapBindingStub)sw_sei;
stub._setProperty(SoftwareManagerServiceSoapBindingStub.USERNAME_PROPERTY, "frankb");
stub._setProperty(SoftwareManagerServiceSoapBindingStub.PASSWORD_PROPERTY, "xxxx");
			
      //We can also use the stub to set the Locale as a property. It can also be set in
          //the deployment descriptor.
      //The Handler is registered in webservicesclient.xml and will get the Locale from
      //the MessageContext
      stub._setProperty("Locale", java.util.Locale.GERMAN);
			
      //Create Software
      //The software package must exist on the Web
      //server for createSoftware to be successful.
Software sw = new Software();
      sw.setSoftwareType("WINCE_PACKAGE");
      sw.setSoftwareURL("http://server/testsw.pkg");
      long swid = sw_sei.createSoftware(sw, null, null);
      System.out.println("created se - " + swid);
  } catch (DeviceManagerException dme) {
      System.out.println("dme - " + dme.getMessage());
  } catch (RemoteException rme) {
      rme.printStackTrace(); 
  } catch (MalformedURLException mue) {
      mue.printStackTrace(); 
  } catch (ServiceException se) {
      se.printStackTrace();
  }
			
}

在非受管客户机环境中,可用以下代码代替 JNDI 来访问服务端点接口(Service Endpoint Interface,SEI)。

SoftwareManagerServiceServiceLocator locator = new  SoftwareManagerServiceServiceLocator();
SoftwareManagerService sw_sei = locator.getSoftwareManagerService(new URL(http://hostname:80/dmserver/services/SoftwareManagerService"));

生成客户机绑定的 Rational Application Developer 向导还可生成替代以上代码的代理。 该代理称为:

com.tivoli.dms.api.SoftwareManagerServiceProxy

在这种情况下,除代理名称不同之外,编码类似于 dmapi.jar 案例。

异常

所有代理和存根方法都抛出异常 com.tivoli.dmapi.DeviceManagerException。

Device Manager 服务器上的数据库包含 Devices、Jobs、Software、DeviceJobs 和 NamedQuery 的记录。每条记录都由在服务器上生成的唯一标识(deviceID、jobID、softwareID 和 queryID)来识别。此标识是一个只读属性。如果在创建对象时指定 ID 属性,则抛出异常。

缺省情况下,异常消息文本以服务器的语言环境返回。如果正在使用 dmapi.jar,则可以更改此文本的语言环境,方法是通过使用 setLocale 方法将客户机的语言环境传递到代理。Web 服务的全球化主题提供了有关该功能的更多信息。

输入参数的验证发生在 Device Manager 服务器上。

生成异常的典型错误包括下列错误:


相关信息