我目前正在实施肥皂服务,我需要从另一个肥皂服务(服务A)拨打一个肥皂服务(服务B)。从服务A,如何设置HTTP标头而不是SOAP服务B的SOAP标头。
目前我正在使用JaxWsDynamicClientFactory,如下所示,
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(localhost/services/test?wsdl");
results = client.invoke(new QName(namespace,operation), service parameters);
答案 0 :(得分:3)
您可以使用CXF RequestContext添加标头。例如,要添加名为Header-Name
的标头,其值为headerValue
:
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(localhost/services/test?wsdl");
@SuppressWarnings("unchecked")
Map<String, List<String>> headers = (Map<String, List<String>>) client.getRequestContext()
.get(Message.PROTOCOL_HEADERS);
if (headers == null) {
headers = new TreeMap<String, List<String>>(
String.CASE_INSENSITIVE_ORDER);
client.getRequestContext().put(Message.PROTOCOL_HEADERS, headers);
}
headers.put("Header-Name", Collections.singletonList("headerValue"));
results = client.invoke(new QName(namespace,operation), service parameters);