realMethods框架的Axis客户端的java实现

来源:互联网 发布:linux安装多版本jdk 编辑:程序博客网 时间:2024/04/30 04:33
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

  概述

  本文介绍了realMethods框架如何实现Axisjava客户端代码(用javaAxis作WebService的提供者,服务请求者用java)。

  编写java客户端代码访问WebService

  本文以一个图书管理系统为例,展示如何使用java编写客户端代码访问WebService(在图书管理系统中主要需要维护的是一个叫Book的对象)。

  首先启动realMethods4.0的AIB,接着装载由library领域模型转换的xml文件,在AIB中选择“DelegateToSessionFaçadeviaWebService”,并且选择BMP场景,最后产生基于领域模型的代码,所有产生的文件输出在d:/library目录上,产生代码后的目录结构如下所示:

  附件:1112321415174-1.jpg(34K)

  realMethods框架为Book产生了增加、修改、删除、根据主键ID查询Book特定的一条记录和查询Book的所有记录这五种基本操作。web层使用struts框架,web层的Action子类通过Delegate访问业务逻辑,(EJB),而Delegate中的代码是通过Axis访问EJB的, 在d:/library/Axis目录中就是realMethods生成的使用部署描述符WSDD描述被发布的web服务(web服务在这里就是EJB实现的业务逻辑代码),下面就是realMethods生成的描述web服务Book的部署描述符:

  Axis/wsdd/"

  xmlns:java="http://xml.apache.org/Axis/wsdd/providers/java">

  java:EJB">

 

 

 

 

 

 

 

 

  xmlns:urn="urn:library"

  qname="urn:BookBO"

  type="java:com.library.bo.BookBO"

  serializer="org.apache.Axis.encoding.ser.BeanSerializerFactory"

  deserializer="org.apache.Axis.encoding.ser.BeanDeserializerFactory"

  encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

 

  xmlns:urn="urn:library"

  qname="urn:BookPrimaryKey"

  type="java:com.library.primarykey.BookPrimaryKey"

  serializer="org.apache.Axis.encoding.ser.BeanSerializerFactory"

  deserializer="org.apache.Axis.encoding.ser.BeanDeserializerFactory"

  encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

  上面描述了一个名称为urn:BookService的web服务。TypeMapping(类型映射)元素定义如何在java类(或基本数据类型)和XML之间进行来回转换。第一个TypeMapping元素定义了urn:BookBO和java:com.library.bo.BookBO的类型映射。

  接下来我要描述客户端代码如何访问上面发布的web服务。

  Delegate中的代码就是我在这里要描述的Axis客户端代码,下面是代理通过Axis访问增加一条Book的web服务:

  packagecom.library.delegate;

  importjava.util.*;

  importjavax.xml.namespace.QName;

  importorg.apache.Axis.encoding.ser.BeanSerializerFactory;

  importorg.apache.Axis.encoding.ser.BeanDeserializerFactory;

  importorg.apache.Axis.encoding.XMLType;

  importcom.framework.business.Axis.*;

  importcom.framework.business.bo.*;

  importcom.framework.business.delegate.*;

  importcom.framework.business.pk.*;

  importcom.framework.common.exception.*;

  importcom.framework.integration.log.*;

  importcom.library.Axis.*;

  importcom.library.ejb.*;

  importcom.library.locator.*;

  importcom.library.primarykey.*;

  importcom.library.bo.*;

  importcom.library.to.*;

  /**

  *Bookbusinessdelegate.

  *

  *ThisclassimplementstheBusinessDelegatedesignpatternforthepurposeof:

  *

      *

  1. Reducingcouplingbetweenthebusinesstierandaclientofthebusinesstierbyhidingallbusiness-tierimplementationdetails
  2.   *

  3. ImprovingtheavailableofBookrelatedservicesinthecaseofaBookbusinessrelatedservicefailing.
  4.   *

  5. Exposesasimpler,uniformBookinterfacetothebusinesstier,makingiteasyforclientstoconsumeasimplejavaobject.
  6.   *

  7. HidesthecommunicationprotocolthatmayberequiredtofulfillBookbusinessrelatedservices.
  8.   *

  *

  *@authoramanda

  */

  publicclassBookBusinessDelegate

  extendsBaseBusinessDelegate

  implementsIBookBusinessDelegate

  {

  //************************************************************************

  //PublicMethods

  //************************************************************************

  /**

  *DefaultConstructor

  */

  publicBookBusinessDelegate()

  {

  }

  /**

  *ConstructorwithaIBookBO

  *@parambusinessObject

  *@exceptionIllegalArgumentExceptionThrownwhentheparametersarenull.

  */

  publicBookBusinessDelegate(IBookBObusinessObject)

  throwsIllegalArgumentException

  {

  //Callbaseclass

  super(businessObject);

  }

  /**

  *BookBusinessDelegateFactoryMethod

  *

  *ReturnsasingletoninstanceofBookBusinessDelegate().

  *Allmethodsareexpectedtobeself-sufficient.

  *

  *@returnBookBusinessDelegate

  */

  staticpublicBookBusinessDelegategetInstance()

  {

  if(singleton==null)

  {

  singleton=newBookBusinessDelegate();

  }

  return(singleton);

  }

  /**

  *CreatestheprovidedBO.

  *@parambusinessObjectIBookBO

  *@returnIBookBO

  *@exceptionProcessingException

  *@exceptionIllegalArgumentException

  */

  publicIBookBOcreateBook(IBookBObusinessObject)

  throwsProcessingException,IllegalArgumentException

  {

  if(businessObject==null)

  {

  StringerrMsg="BookBusinessDelegate:createBook(IBookBObusinessObject)-nullbusinessObjectprovided.";

  FrameworkDefaultLogger.error(errMsg);

  thrownewIllegalArgumentException(errMsg);

  }

  try

  {

  //createtheFrameworkAxisSOAPParameterparameters

  FrameworkAxisSOAPParameterparameter=newFrameworkAxisSOAPParameter("businessObject",businessObject,newQName("urn:BookService","BookBO"));

  ArrayListparameters=newArrayList();

  parameters.add(parameter);

  //maketheSOAPcall

  businessObject=(IBookBO)ApacheAxisHelper.makeAxisCall("create",parameters,"BookService",getTypeMappings("BookMaps"),voQName);

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击