如何将wsdl中定义的Soap Header添加到CXF中的Web服务客户端? [英] How do you add a Soap Header defined in a wsdl to a web service client in CXF?

查看:89
本文介绍了如何将wsdl中定义的Soap Header添加到CXF中的Web服务客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wsdl,它定义了在调用Web服务时需要传递的soap头。

I have a wsdl that defines a soap header that needs to be passed when calling the web service.

示例SOAP Header是:

The sample SOAP Header is:

<soapenv:Header>
   <AuthenticationInfo>
      <userName>User</userName>
      <password/>
   </AuthenticationInfo>
</soapenv:Header>

CXF的wsdl2java生成了一个AuthenticationInfojava类,我可以创建并填充用户名和密码,但我不知道在调用Web服务时将其传递给CXF客户端的正确方法。

CXF's wsdl2java generated an "AuthenticationInfo" java class that I can create and populate with a username and password, but I don't know the proper way to pass that to the CXF Client when calling the web service.

推荐答案

嗯,最简单的方法是创建一个 ArrayList Header 对象并添加所有参数或 Map< String,Object> 并将所有标题添加为 map.put(param1,param1)。

Well, the most simple way to do this would be create an ArrayList of Header objects and add all your parameters or a Map<String,Object> and add all your headers as map.put("param1",param1).

最后得到你的请求上下文并将这个地图的arraylist添加为

Finally get your request context and add this arraylist of map as

requestContext.put(MessageContext.HTTP_REQUEST_HEADERS,
soapHeaders); 

如果您尝试传递自定义soap标头,请参阅此链接

If you're trying to pass custom soap headers, refer THIS LINK.

一般此讨论中提到了陷阱。它可能对你有帮助。

The general pitfalls have been mentioned in THIS DISCUSSION. It might be helpful to you.

这篇关于如何将wsdl中定义的Soap Header添加到CXF中的Web服务客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆