• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Web 服务的测试模型与代码摘录[2]

发布: 2010-4-15 10:32 | 作者: 不详 | 来源: 领测测试网采编 | 查看: 27次 | 进入软件测试论坛讨论

领测软件测试网

  Web 服务的测试模型与代码摘录[2]   软件测试

  if(action.equalsIgnoreCase("BUY"))

  System.out.println("BUYING quantity: "+ quantity + " of symbol:" + symbol);

  // Invoke method to execute trade here.

  else if(action.equalsIgnoreCase("SELL"))

  System.out.println("SELLING quantity: "+ quantity + " of symbol:" + symbol);

  // Invoke method to execute trade here.

  else

  {

  System.out.println("INVALID action: "+ action);

  throw new SOAPFaultException(new QName( "http://StockTrade/execute", "ServerFailed" ),

  "Invalid Action:" + action,

  null,

  detail);

  }

  return true;

  }

  代码摘录:Stock Trade Web Services

  该段摘录的代码是Stock Trade Web Services的“execute()”方法的实现代码。该方法首先验证输入参数的有效性,验证成功才执行功能。举例说明,如果参数action是空值,它就会抛出一个SoapFaultException异常,用faultstring参数(第二个参数)说明造成异常的原因。为了举例说明,在对参数 symbol进行相似的验证之后,Web Services给出了处理机。在实际的情况下,商业逻辑应该在此位置中实现:

  try{

  // Setup the global JAXM message factory

  System.setProperty("javax.xml.soap.MessageFactory",

  "weblogic.webservice.core.soap.MessageFactoryImpl");

  // Setup the global JAX-RPC service factory

  System.setProperty( "javax.xml.rpc.ServiceFactory",

  "weblogic.webservice.core.rpc.ServiceFactoryImpl");

  StockTrade_Impl ws = new StockTrade_Impl();

  StockTradePort port = ws.getStockTradePort();

  boolean returnVal = port.execute(action, symbol, quantity);

  System.out.println("The webservice got back the following result:" + returnVal);

  }catch(Exception e) {

  }

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/

TAG: web Web WEB 代码 服务 模型 摘录


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网