2016-06-08 59 views
0

我使用Axis2 RPCServiceClient来调用Web服务。所有对该服务的调用都必须包含3个参数:UserName,Password和reqID。 reqID是由我生成的GUID参数。如何将参数添加到标题中,我通过axis2调用webservice

reqID需要放入标题。

当我使用soapUI测试服务时,通过Http分析器,我可以发现reqID包含在带有SOAPAction,Content-type,User-Agent和Authorization的请求标头中。

如何将reqID添加到标头中?

`RPCServiceClient client = new RPCServiceClient(); 
    Options option = client.getOptions(); 
    option.setAction("http://localhost:8080/api/Getbooks"); 
    EndpointReference erf = new EndpointReference(serviceAddress); 
    option.setTo(erf);  

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); 
    auth.setUsername("test"); 
    auth.setPassword("test"); 
    auth.setPreemptiveAuthentication(true); 

    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);' 

    [![this is request headers][1]][1] 

回答

0

创建org.apache.axis2.client.ServiceClient

的实例

创建org.apache.axis2.client.Options的实例

创建一个HTTP客户端头

Header header = new Header(); 
    header.setName("Request-Id"); 
    header.setValue(UUID.randomUUID().toString()); 
    List list = new ArrayList(); 
    list.add(header); 

options.setPr operty(org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS,list);

相关问题