2016-06-08 60 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);

相關問題