问题描述
我有一个 wsdl,它定义了一个在调用 Web 服务时需要传递的soap 标头.
I have a wsdl that defines a soap header that needs to be passed when calling the web service.
示例 SOAP 标头是:
The sample SOAP Header is:
<soapenv:Header>
<AuthenticationInfo>
<userName>User</userName>
<password/>
</AuthenticationInfo>
</soapenv:Header>
CXF 的 wsdl2java 生成了一个AuthenticationInfo"java 类,我可以创建并填充用户名和密码,但我不知道在调用 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.
推荐答案
嗯,最简单的方法是创建一个 Header
对象的 ArrayList
并添加您的所有参数或 Map
并将所有标题添加为 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).
最后获取您的请求上下文并将此地图数组列表添加为
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.
在这个讨论中已经提到了一般的陷阱.可能对你有帮助.
这篇关于如何将 wsdl 中定义的 Soap Header 添加到 CXF 中的 Web 服务客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!