商讯信箱
用户名: @
密  码:   注册|忘记密码
登录
个人用户经销商
您的位置:首页 > 技术频道 > 正文


查找桩

  清单1. 服务接口是由叫做AmazonSearchPort_Stub.java 的桩类实现的,Web service客户端将会使用这个桩类。

public class AmazonSearchService_Impl extends com.sun.xml.rpc.client.BasicService implements AmazonSearchService { private static final QName serviceName = new QName("http://soap.amazon.com", "AmazonSearchService"); private static final QName ns1_AmazonSearchPort_QNAME = new QName( "http://soap.amazon.com", "AmazonSearchPort"); private static final Class amazonSearchPort_PortClass = javapro.amazon.AmazonSearchPort.class; public java.rmi.Remote getPort( QName portName, Class serviceDefInterface) throws javax.xml.rpc.ServiceException { // implementation elided } public java.rmi.Remote getPort( Class serviceDefInterface) throws javax.xml.rpc.ServiceException { // implementation elided } public javapro.amazon.AmazonSearchPort getAmazonSearchPort() { String[] roles = new String[] {}; javapro.amazon.AmazonSearchPort_Stub stub = new javapro.amazon.AmazonSearchPort_Stub( handlerChain); return stub; } }
  

    为了使重要的数据更加显而易见,我们省略了很多实现代码。注意,正是getAmazonSearchPort() 方法创建了AmazonSearchport_Stub(就是桩)的一个实例。桩是使用handlerChain进行初始化的(参见清单2)。

信息结构
  清单2. AmazonSearchPort_Stub是使用handlerChain初始化的桩。我们传递给方法一个AuthorRequest结构,而该方法返回一个ProductInfo结构。

 
public class AmazonSearchPort_Stub extends com.sun.xml.rpc.client.StubBase implements javapro.amazon.AmazonSearchPort { public AmazonSearchPort_Stub( HandlerChain handlerChain) { super(handlerChain); _setProperty(ENDPOINT_ADDRESS_PROPERTY, "http://soap.amazon.com/onca/soap3"); } public ProductInfo authorSearchRequest( AuthorRequest authorSearchRequest) throws java.rmi.RemoteException { try { StreamingSenderState _state = _start( _handlerChain); InternalSOAPMessage _request = _state.getRequest(); _request.setOperationCode( AuthorSearchRequest_OPCODE); AmazonSearchPort_AuthorSearchRequest_ RequestStruct requestStruct = new AmazonSearchPort_AuthorSearchRequest_ RequestStruct(); requestStruct.setAuthorSearchRequest( authorSearchRequest); SOAPBlockInfo _bodyBlock = new SOAPBlockInfo( ns1_AuthorSearchRequest_AuthorSearchRequest_ QNAME); _bodyBlock.setValue (requestStruct); _bodyBlock.setSerializer( ns1requestStruct_SOAPSerializer); _request.setBody(_bodyBlock); _state.getMessageContext().setProperty( HttpClientTransport.HTTP_SOAPACTION_PROPERTY, "http://soap.amazon.com"); _send((String) _getProperty( ENDPOINT_ADDRESS_PROPERTY), _state); AmazonSearchPort_AuthorSearchRequest_ ResponseStruct responseStruct = null; Object _responseObj = _state.getResponse(). getBody().getValue(); if (_responseObj instanceof SOAPDeserializationState) { responseStruct =( AmazonSearchPort_AuthorSearchRequest_ ResponseStruct) ((SOAPDeserializationState)_responseObj). getInstance(); } else { responseStruct = ( AmazonSearchPort_AuthorSearchRequest_ ResponseStruct) _responseObj; } return responseStruct.get_return(); } 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); } } } }

  同样,您可以安全地忽略这里的很多代码;它就是实现细节。然而,注意传递给该方法的是一个AuthorRequest结构,而该方法返回的是一个ProductInfo结构。此外还要注意,我们将会发送请求至的URL被设置为带有下列调用的方法的一部分:

setProperty
HttpClientTransport.
HTTP_SOAPACTION_PROPERTY,
"http://soap.amazon.com");
1 2 3 4 5 6
【内容导航】
第1页: 描述服务 第2页: 向下直到桩
第3页: 配置元素 第4页: 特性列表
第5页: 查找桩 第6页: 创建客户端
©版权所有。未经许可,不得转载。
[责任编辑:李宁]
[an error occurred while processing this directive]