【问题标题】:how to add a parameter into header, I call webservice by axis2如何在header中添加参数,我通过axis2调用webservice
【发布时间】:2016-06-08 12:11:13
【问题描述】:

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

需要reqID放入header中。

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

如何将reqID添加到header中?

   `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]

【问题讨论】:

    标签: web-services soap header axis2


    【解决方案1】:

    创建 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);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 2011-10-27
      • 2013-06-06
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 2017-05-04
      相关资源
      最近更新 更多