Stock Quote - 配置和运行


配置样本
运行样本

存在两个 Stock Quote 客户机,Java 2 Standard Edition(J2SE)版本和 Java 2 Enterprise Edition(J2EE)容器管理的版本。如果您要充分利用 J2EE 容器服务的功能,请运行 J2EE 版本。

配置样本

要完成此样本的配置,请在服务器上部署 JAX-RPC Web Service 样本应用程序。如果尚未部署样本应用程序,请参阅重建和部署 WebServicesSamples.ear 文件的指示信息。

运行样本

验证在客户机运行前服务器是否已启动。

Stock Quote 样本包含两个客户机和单个部署在服务器上的企业 bean。 一个客户机是简单 J2SE 客户机。您可在名为 GetQuote 的程序中找到它。 另一个是 Java 2 Enterprise Edition(J2EE)客户机。您可在 GetQuoteClient.jar 中找到它。

运行 J2SE Stock Quote 简单客户机
运行 J2EE Stock Quote 应用程序客户机

Stock Quote 客户机

Stock Quote 客户机查询 StockQuote 企业 bean,以从 Web 检索当前股票行情。“股票行情”Web Service 可返回固定值,如果因特网连接有效,可返回当前股票行情。Stock Quote 客户机的第一个参数是目标端点 URL,它指定要使用的 Web Service。第二个参数是股票代号。 使用 XXX 值可以不使用因特网连接而获取固定价格。

运行 J2SE Stock Quote 简单客户机

J2SE Stock Quote 客户机不是容器管理的客户机。

要获取有关调用 J2SE WebSphere 客户机的更全面的指示信息,请参阅信息中心中有关开发瘦应用程序客户机代码的主题。

要从 WebSphere Application Server 运行 J2SE Stock Quote 简单客户机,根据您的操作系统,执行下列步骤:

  1. 启动服务器。
  2. 打开命令提示符。
  3. 发出下列命令:

    在 Windows 平台上:

    cd profile_root\bin
    setupCmdLine
    cd install_root\bin
    setupCmdLine

    在 Linux、UNIX 和 z/OS 平台上:

    cd profile_root/bin
    . ./setupCmdLine.sh
    cd install_root/bin
    . ./setupCmdLine.sh

    在 iSeries 平台上:

    cd profile_root/bin
    . ./setupCmdLine
    cd install_root/bin
    . ./setupCmdLine

  4. 发出下列命令:

    在 Windows 平台上:

    "%JAVA_HOME%\bin\java" %WAS_LOGGING% -classpath "%WAS_CLASSPATH%;%WAS_HOME%\samples\lib\WebServicesSamples\simpleClients.jar;%WAS_HOME%\runtimes\com.ibm.ws.webservices.thinclient_7.0.0.jar" samples.stock.GetQuote <URL> <symbol>

    在 Linux、UNIX 和 z/OS 平台上:

    "$JAVA_HOME/bin/java" $WAS_LOGGING -classpath "$CLASSPATH:$WAS_CLASSPATH:$WAS_HOME/samples/lib/WebServicesSamples/simpleClients.jar:$WAS_HOME/runtimes/com.ibm.ws.webservices.thinclient_7.0.0.jar" samples.stock.GetQuote <URL> <symbol>

    在 iSeries 平台上:

    java $JAVA_PARM -classpath "$CLASSPATH:$WAS_CLASSPATH:$WAS_HOME/samples/lib/WebServicesSamples/simpleClients.jar:$WAS_HOME/runtimes/com.ibm.ws.webservices.thinclient_7.0.0.jar" samples.stock.GetQuote <URL> <symbol>

    其中:
    <URL> 是服务端点地址 http://<host_name>:<port>/StockQuote/services/xmltoday-delayed-quotes 其中 <hostname> 是主机名(缺省值为 localhost),而 <port> 是端口号(缺省值为 9080)。
    <symbol> 是股票代号

    Stock Quote 客户机在 Windows 上成功运行将显示下列输出:

    C:\>"%JAVA_HOME%\bin\java" %WAS_LOGGING% -classpath "%WAS_CLASSPATH%;%WAS_HOME%\samples\lib\WebServicesSamples\simpleClients.jar;%WAS_HOME%\runtimes\com.ibm.ws.webservices.thinclient_7.0.0.jar" samples.stock.GetQuote http://localhost:9080/StockQuote/services/xmltoday-delayed-quotes XXX
    XXX: 55.25
     
    C:\>"%JAVA_HOME%\bin\java" %WAS_LOGGING% -classpath "%WAS_CLASSPATH%;%WAS_HOME%\samples\lib\WebServicesSamples\simpleClients.jar;%WAS_HOME%\runtimes\com.ibm.ws.webservices.thinclient_7.0.0.jar" samples.stock.GetQuote http://localhost:9080/StockQuote/services/xmltoday-delayed-quotes DELL
    DELL: 23.67
     
    

运行 J2EE Stock Quote 应用程序客户机

J2EE 应用程序 GetQuoteClient.jar 是 Stock Quote 客户机的容器管理的版本。

在以下步骤中,变量 install_root 表示 WebSphere 安装根目录。

要从 WebSphere Application Server 运行 J2EE 应用程序 Stock Quote 客户机,根据您的操作系统执行下列步骤:

  1. 启动服务器。
  2. 打开命令提示符。
  3. 输入以下命令:

    在 Windows 平台上:

    cd <profile_root>\bin
    setupCmdLine

    在 Linux、UNIX 和 z/OS 平台上:

    cd <profile_root>/bin
    . ./setupCmdLine.sh

    在 iSeries 平台上:

    cd <profile_root>/bin
    . ./setupCmdLine

    其中 <profile_root> 表示概要文件安装目录。
  4. 转到目录 install_root/samples/lib/WebServicesSamples
    其中:
    install_root 是 WebSphere Application Server 安装根,或者如果重建了样本,那么是概要文件安装根。
  5. 发出下列命令:

    在 Windows 平台上:

    <install_root>\bin\launchClient ApplicationClients.ear -CCjar=GetQuoteClient.jar [<URL>] <symbol>

    在 Linux、UNIX 和 z/OS 平台上:

    <install_root>/bin/launchClient.sh ApplicationClients.ear -CCjar=GetQuoteClient.jar [<URL>] <symbol>

    在 iSeries 平台上:

    <install_root>/bin/launchClient ApplicationClients.ear -CCjar=GetQuoteClient.jar [<URL>] <symbol>

    其中:
    <URL> 是服务端点地址 http://<host_name>:<port>/StockQuote/services/xmltoday-delayed-quotes 其中 <hostname> 是主机名(缺省值为 localhost),而 <port> 是端口号(缺省值为 9080)。
    <symbol> 是股票代号

    以下示例表明 J2EE 应用程序 Stock Quote 客户机的两次运行成功:

    C:\WebSphere\AppServer\samples>\WebSphere\AppServer\bin\launchClient \WebSphere\AppServer\samples\lib\WebServicesSamples\ApplicationClients.ear -CCjar=GetQuoteClient.jar IBM
    IBM WebSphere Application Server, Release 7.0
    J2EE Application Client Tool
    Copyright IBM Corp., 1997-2008
    WSCL0012I: Processing command line arguments.
    WSCL0013I: Initializing the J2EE Application Client Environment.
    [3/29/06 14:55:22:359 CST] 0000000a  W UOW=null source=com.ibm.ws.ssl.config.SSLConfig org=IBM prod=WebSphere component=Application Server thread=[P=720609:O=0:CT]
              CWPKI0041W: One or more key stores are using the default password.
    WSCL0035I: Initialization of the J2EE Application Client Environment has completed.
    WSCL0014I: Invoking the Application Client class com.ibm.websphere.samples.webservices.stockClient.GetQuote
    IBM: 83.36
     
    C:\WebSphere\AppServer\samples>\WebSphere\AppServer\bin\launchClient \WebSphere\AppServer\samples\lib\WebServicesSamples\ApplicationClients.ear -CCjar=GetQuoteClient.jar XXX
    IBM WebSphere Application Server, Release 7.0
    J2EE Application Client Tool
    Copyright IBM Corp., 1997-2008
    WSCL0012I: Processing command line arguments.
    WSCL0013I: Initializing the J2EE Application Client Environment.
    [3/29/06 15:00:04:062 CST] 0000000a  W UOW=null source=com.ibm.ws.ssl.config.SSLConfig org=IBM prod=WebSphere component=Application Server thread=[P=2171:O=0:CT]
    CWPKI0041W: One or more key stores are using the default password.
    WSCL0035I: Initialization of the J2EE Application Client Environment has completed.
    WSCL0014I: Invoking the Application Client class com.ibm.websphere.samples.webservices.stockClient.GetQuote
    XXX: 55.25
      

参阅 Stock Quote 技术说明和查看 Java 源代码,以了解更多的客户机和应用程序工作原理。