J2EE Web服务客户端质量报告(四)
时间:2010-12-06
客户端服务软件包
通过指引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()调用之前立即添加了上面的代码行。
J2EE Web服务客户端质量 |