I am using the following CXF client to invoke a SOAP web service:
QName serviceQName = new QName("Namespace", "ServiceName");
String urlString = "https:endpoint?wsdl";
QName portQName = new QName("Namespace", "PortName");
service = Service.create(serviceQName);
service.addPort(portQName, SOAPBinding.SOAP12HTTP_BINDING, urlString);
Dispatch<Source> sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
BindingProvider bindingProvider = sourceDispatch;
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, urlString);
bindingProvider.getRequestContext().put(TLSClientParameters.class.getName(), tlsParams);
Source result = sourceDispatch.invoke(new StreamSource(exchange.getIn().getBody(InputStream.class)));
And i get the following error:
javax.xml.ws.soap.SOAPFaultException: An error occurred when verifying security for the message
The solution was to add a SOAP action and some HTTP headers as shown below:
bindingProvider.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "myRequestAction");
Map<String, List<String>> requestHeaders = new HashMap<>();
requestHeaders.put("HeaderName", Arrays.asList("HeaderValue"));