客户端服务软件包
通过指引wsdl编译器到应用服务器提供的wsdl上可自动生成客户端服务软件包。这个软件包包含许多类。我们需要修改的唯一类就是客户端stub类。同样地,服务器web 服务软件包也包含类tie,它可将web服务请求绑定到ejb方法上,客户端stub类为每个服务商业方法的每个客户端配备一个方法。
服务stub类的名称为 <servicename>servantinterface_stub,其中<servicename>就是服务名。我们看看类xactserviceservantinterface_stub 内的submitwork()方法:
在上述的代码中,我们在_send()之前立即添加了下面的单行:
如果没有待解决的客户端报告需要发送,attachpendingreporttomessage 就返回。否则,它将当前报告连在xml之后并将它当作文本附件添加到soap信息中。我们对其他的商业方法也作了同样的修改,在它们的每个_send()调用之前立即添加了上面的代码行。 信息驱动的 bean
现在我们可以记录客户端事务响应次数并将它们通过http/soap的运输,我们需要一条可以在应用服务器上处理这些报告的方法。最适合完成这个任务的就是信息驱动的ejb组件因为响应次数报告应该异步地搬运到用户事务上。web 服务类 tie将xml clientreport对象列队。下面的ejb代码可读取和处理这些报告:
通常,报告会登记到数据库中用于在线分析和报告。在本例中,我们将报告打印到控制台以便演示客户端如何接收它们的过程。方法 onmessage()使用serializer.clientreportxml() 创建来自列队等待的xml字符串的clientreport对象。我们在这里做一下解码工作以便可以将处理次数保存在事务处理工作流程中。
样品实现
用来运行样品应用的所有代码都可从resources处下载。我开发代码时使用的工具是sun one studio, enterprise edition update 1。 这个工具箱包括一个j2ee开发ide 和一个j2ee应用服务,它的web 服务设备采用了嵌入式的java web service developer pack 1.0_01。 resources 处有自由下载url的信息和到开发者文档的链接。
建立和配置服务器应用
这部分假设你已经了解sun one 应用框架的应用知识。另外,本指示假设你使用微软的windows系统。配置的完整源代码预先已经建立。web服务客户端和服务器软件包已经生成(并为了次数报告的连续化做好修改),但是下面的描述也包含了关于如何在sun one ide之内建立组件的一些背景知识。
要建立和配置服务器应用,首先,在windows 开始菜单中选择程序,再在程序中选择sun microsystems,然后依次选择sun one application server和 start application server项。
实用类似的windows 命令可启动ide。右击资源管理器中的“运行”键,点击安装的服务器,并保证应用服务的运行实例已经设置为默认服务器。
解压下载的工具包到某个目录下并右击ide资源管理器窗口的文件系统图标。使用mount/local directory 对话框,实现两个不同的安装命令:
<download directory>/metrics/metrics 打开payload软件包。
<download directory>/metrics/transactionserver 打开服务器ejb、 web 模块、和服务器应用组件。
ejbmodule_xact 为应用服务原型,它包括三个商业方法:submitwork()、 checkwork()、和getresult()。要创建同一目录下的transactionprocessor/xact_module可右击 ejb 然后依次选择new、jsp & servlet、和web module命令。创建transactionservice软件包中的web 模块可依次选择new、web services、和 web module 向导,然后选择ejb组件的java方法作为源程序。右击web module并选择create new web service项可自动创建transactionservice/xactservicegenserver。但是在右击之前请小心,因为它会关闭添加到类tie上的serialize 调用。
创建应用程序transactionserverapp 需要依次选择new、j2ee、和application命令。 右击空的应用,选择add modules 项,然后选择ejbmodule_xact 和xact_service web module项就可添加组件到应用程序上。
本部分给出了如何建立代码组件的一般思想。你需要将这些组件配置到你的应用服务上。在ide之内,右击transactionserverapp即可进行配置。检查一下应用服务系统控制台以保证它的配置正确。
通过指引wsdl编译器到应用服务器提供的wsdl上可自动生成客户端服务软件包。这个软件包包含许多类。我们需要修改的唯一类就是客户端stub类。同样地,服务器web 服务软件包也包含类tie,它可将web服务请求绑定到ejb方法上,客户端stub类为每个服务商业方法的每个客户端配备一个方法。
服务stub类的名称为 <servicename>servantinterface_stub,其中<servicename>就是服务名。我们看看类xactserviceservantinterface_stub 内的submitwork()方法:
| /* * implementation of submitwork */ public java.lang.string submitwork(java.lang.string string_1) throws java.rmi.remoteexception { try { streamingsenderstate _state = _start(_handlerchain); internalsoapmessage _request = _state.getrequest(); _request.setoperationcode(submitwork_opcode); xact.xactserviceservantinterface_submitwork_requeststruct _myxactserviceservantinterface_submitwork_requeststruct =new xact.xactserviceservantinterface_submitwork_requeststruct(); _myxactserviceservantinterface_submitwork_requeststruct.setstring_1(string_1); soapblockinfo _bodyblock = new soapblockinfo(ns1_submitwork_submitwork_qname); _bodyblock.setvalue(_myxactserviceservantinterface_submitwork_requeststruct); _bodyblock.setserializer(myxactserviceservantinterface_submitwork_requeststruct_soapserializer); _request.setbody(_bodyblock); _state.getmessagecontext().setproperty(httpclienttransport.http_soapaction_property, ""); serializer.attachpendingreporttomessage(_state.getmessagecontext()); _send((string) _getproperty(endpoint_address_property), _state); xact.xactserviceservantinterface_submitwork_responsestruct _myxactserviceservantinterface_submitwork_responsestruct = null; object _responseobj = _state.getresponse().getbody().getvalue(); if (_responseobj instanceof soapdeserializationstate) { _myxactserviceservantinterface_submitwork_responsestruct = (xact.xactserviceservantinterface_submitwork_responsestruct) ((soapdeserializationstate)_responseobj).getinstance(); } else { _myxactserviceservantinterface_submitwork_responsestruct =(xact.xactserviceservantinterface_submitwork_responsestruct)responseobj; } return _myxactserviceservantinterface_submitwork_responsestruct .getresult(); } catch (remoteexception e) { // let this one through unchanged throw e; } catch (jaxrpcexception e) { throw new remoteexception(e.getmessage(), e); } catch (exception e) { if (e instanceof runtimeexception) { throw (runtimeexception)e; } else { throw new remoteexception(e.getmessage(), e); } } } |
在上述的代码中,我们在_send()之前立即添加了下面的单行:
| serializer.attachpendingreporttomessage(_state.getmessagecontext()); |
如果没有待解决的客户端报告需要发送,attachpendingreporttomessage 就返回。否则,它将当前报告连在xml之后并将它当作文本附件添加到soap信息中。我们对其他的商业方法也作了同样的修改,在它们的每个_send()调用之前立即添加了上面的代码行。 信息驱动的 bean
现在我们可以记录客户端事务响应次数并将它们通过http/soap的运输,我们需要一条可以在应用服务器上处理这些报告的方法。最适合完成这个任务的就是信息驱动的ejb组件因为响应次数报告应该异步地搬运到用户事务上。web 服务类 tie将xml clientreport对象列队。下面的ejb代码可读取和处理这些报告:
| package testbean; import javax.jms.*; import javax.ejb.*; import payload.*; /** * created may 23, 2003 6:01:04 pm * code generated by the sun one studio ejb builder * @author brian */ public class testmdbbean implements javax.ejb.messagedrivenbean, javax.jms.messagelistener { private transient javax.ejb.messagedrivencontext context; /** * @see javax.ejb.messagedrivenbean #setmessagedrivencontext (javax.ejb.messagedrivencontext) */ public void setmessagedrivencontext (javax.ejb.messagedrivencontext acontext) { context=acontext; } /** * see section 15.4.4 of the ejb 2.0 specification */ public void ejbcreate() { } /** * @see javax.jms.messagelistener#onmessage(javax.jms.message) */ public void onmessage(javax.jms.message amessage) { textmessage msg = null; try { if (amessage instanceof textmessage) { msg = (textmessage) amessage; string crxml = msg.gettext(); //system.out.println("message bean: message"); //system.out.println(crxml); clientreport cr = serializer.clientreportxml(crxml); system.out.println ("took:" + string.valueof(cr.getclientelapsedms()) + " ms. for: " + cr.gettype().tostring()); } else { system.out.println("message of wrong type: " + amessage.getclass().getname()); } } catch (jmsexception e) { system.err.println("messagebean.onmessage: " + "jmsexception: " + e.tostring()); context.setrollbackonly(); } catch (throwable te) { system.err.println("messagebean.onmessage: " + "exception: " + te.tostring()); } } /** * @see javax.ejb.messagedrivenbean#ejbremove() */ public void ejbremove() { } } |
通常,报告会登记到数据库中用于在线分析和报告。在本例中,我们将报告打印到控制台以便演示客户端如何接收它们的过程。方法 onmessage()使用serializer.clientreportxml() 创建来自列队等待的xml字符串的clientreport对象。我们在这里做一下解码工作以便可以将处理次数保存在事务处理工作流程中。
样品实现
用来运行样品应用的所有代码都可从resources处下载。我开发代码时使用的工具是sun one studio, enterprise edition update 1。 这个工具箱包括一个j2ee开发ide 和一个j2ee应用服务,它的web 服务设备采用了嵌入式的java web service developer pack 1.0_01。 resources 处有自由下载url的信息和到开发者文档的链接。
建立和配置服务器应用
这部分假设你已经了解sun one 应用框架的应用知识。另外,本指示假设你使用微软的windows系统。配置的完整源代码预先已经建立。web服务客户端和服务器软件包已经生成(并为了次数报告的连续化做好修改),但是下面的描述也包含了关于如何在sun one ide之内建立组件的一些背景知识。
要建立和配置服务器应用,首先,在windows 开始菜单中选择程序,再在程序中选择sun microsystems,然后依次选择sun one application server和 start application server项。
实用类似的windows 命令可启动ide。右击资源管理器中的“运行”键,点击安装的服务器,并保证应用服务的运行实例已经设置为默认服务器。
解压下载的工具包到某个目录下并右击ide资源管理器窗口的文件系统图标。使用mount/local directory 对话框,实现两个不同的安装命令:
<download directory>/metrics/metrics 打开payload软件包。
<download directory>/metrics/transactionserver 打开服务器ejb、 web 模块、和服务器应用组件。
ejbmodule_xact 为应用服务原型,它包括三个商业方法:submitwork()、 checkwork()、和getresult()。要创建同一目录下的transactionprocessor/xact_module可右击 ejb 然后依次选择new、jsp & servlet、和web module命令。创建transactionservice软件包中的web 模块可依次选择new、web services、和 web module 向导,然后选择ejb组件的java方法作为源程序。右击web module并选择create new web service项可自动创建transactionservice/xactservicegenserver。但是在右击之前请小心,因为它会关闭添加到类tie上的serialize 调用。
创建应用程序transactionserverapp 需要依次选择new、j2ee、和application命令。 右击空的应用,选择add modules 项,然后选择ejbmodule_xact 和xact_service web module项就可添加组件到应用程序上。
本部分给出了如何建立代码组件的一般思想。你需要将这些组件配置到你的应用服务上。在ide之内,右击transactionserverapp即可进行配置。检查一下应用服务系统控制台以保证它的配置正确。
闽公网安备 35060202000074号