如何在header中添加参数,我通过axis2调用webservice

时间:2016-06-08 12:11:14

标签: web-services soap header axis2

  

我使用Axis2 RPCServiceClient来调用Web服务。并且对服务的所有调用必须包括3个参数:UserName,Password和reqID。 reqID是我生成的GUID参数。

     

reqID需要放入标题。

     

当我使用soapUI测试服务时,通过Http Analyzer,我发现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]

1 个答案:

答案 0 :(得分: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.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS,list);