Reputation: 89
I am currently implementing soap service and I need to call one soap service (Service B) from another soap service (Service A). From service A, how to set the HTTP headers not SOAP headers of out going soap request to service B.
Currently I am using JaxWsDynamicClientFactory as follows,
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(localhost/services/test?wsdl");
results = client.invoke(new QName(namespace,operation), service parameters);
Upvotes: 1
Views: 1361
Reputation: 2122
You can add headers using the CXF RequestContext. For example, to add a header named Header-Name
with the value 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);
Upvotes: 3