服務器Web 服務軟件包
服務器Web 服務軟件包可自動生成。在Sun ONE Studio中,Web模塊的創建只要選擇一組EJB Java方法即可,並且Web服務軟件包的類可由Web模塊創建。
該軟件包包含許多類和接口。這裡最關鍵的一個就是<ServiceName>ServantInterface_Tie 類,在這個類中服務名就是<ServiceName> 。類Tie是Web服務模塊最上面的堆棧;它將引入的服務調用綁定到創建它的EJB組件上。我們只需修改類Tie就可以添加次數紀錄。
Tie包括許多方法,但是我們只需修改與EJB商業方法invoke_<X>關聯的那一個方法。在方法invoke_<X>中,<X>表示EJB商業方法的名稱。我們添加一個 import Payload.*; 到類 Tie上,並對每個商業方法作了一個小小的修改。讓我們看看下面的方法 invoke_SubmitWork() :
/*
* This method does the actual method invocation for operation: SubmitWork
*/
private void invoke_SubmitWork(StreamingHandlerState state) throws Exception {
TransactionService.XactServiceGenServer.
XactServiceServantInterface_SubmitWork_RequestStruct
myXactServiceServantInterface_SubmitWork_RequestStruct = null;
Object myXactServiceServantInterface_SubmitWork_RequestStructObj =
state.getRequest().getBody().getValue();
/* Line added to generated method: */
Serializer.queueFirstAttachmentText(state.getMessageContext());
if (myXactServiceServantInterface_SubmitWork_RequestStructObj
instanceof SOAPDeserializationState) {
myXactServiceServantInterface_SubmitWork_RequestStruct =
(TransactionService.XactServiceGenServer.
XactServiceServantInterface_SubmitWork_RequestStruct)
((SOAPDeserializationState)
myXactServiceServantInterface_SubmitWork_RequestStructObj)
.getInstance();
} else {
myXactServiceServantInterface_SubmitWork_RequestStruct =
(TransactionService.XactServiceGenServer.
XactServiceServantInterface_SubmitWork_RequestStruct)
myXactServiceServantInterface_SubmitWork_RequestStructObj;
}
java.lang.String result =
((TransactionService.XactServiceGenServer.XactServiceServantInterface)
getTarget()).SubmitWork
(myXactServiceServantInterface_SubmitWork_RequestStruct.getString_1());
TransactionService.XactServiceGenServer.
XactServiceServantInterface_SubmitWork_ResponseStruct
myXactServiceServantInterface_SubmitWork_ResponseStruct =
new TransactionService.XactServiceGenServer
.XactServiceServantInterface_SubmitWork_ResponseStruct();
SOAPHeaderBlockInfo headerInfo;
myXactServiceServantInterface_SubmitWork_ResponseStruct.setResult(result);
SOAPBlockInfo bodyBlock = new SOAPBlockInfo
(ns1_SubmitWork_SubmitWorkResponse_QNAME);
bodyBlock.setValue(myXactServiceServantInterface_SubmitWork_ResponseStruct);
bodyBlock.setSerializer
(myXactServiceServantInterface_SubmitWork_ResponseStruct_SOAPSerializer);
state.getResponse().setBody(bodyBlock);
}
我們添加了一個單行到invoke_SubmitWork()上:
Serializer.queueFirstAttachmentText(state.getMessageContext());
getMessageContext()返回實現接口javax.xml.rpc.handler.soap.SOAPMessageContext 的對象。該對象提供對當前SOAP信息的訪問。我們傳遞實現接口SOAPMessageContext 的對象到Payload.Serializer中的一個靜態方法上。該靜態方法從第一個信息附件中獲取XML字符串並將它排隊等待次數處理器EJB組件的調用。
我們對每個invoke_<X>方法作了同樣的修改。