I'm trying to consume a SOAP webservice that expects WS-Security and WS-Adressing headers as SOAPHeaders. Similar to Java SOAP-WS client horror I was not able to get all these headers in my request.
I'm using CXF and have generated a webservice stub using the cxf-codegen plugin. I tried to add the WSS headers using WSSA4J interceptors (based on the cxf documentation here):
//WS-Security
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
Map<String,Object> outProps = new HashMap<String,Object>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
// Specify our username
outProps.put(WSHandlerConstants.USER, user.getUsername());
// Password type : plain text
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
outProps.put("password", user.getPassword());
//Add the interceptor
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
But the request does not contain any WS-Security headers.
I have the same problem adding WS-A headers. Based on this I wanted to add a < To > and < ReplyTo > tag:
//WS-A
Map<String, Object> reqCtx = client.getRequestContext();
AddressingProperties addrProperties = new AddressingProperties();
EndpointReferenceType endpointRef = new EndpointReferenceType();
AttributedURIType address = new AttributedURIType();
address.setValue("http://www.w3.org/2005/08/addressing/anonymous");
endpointRef.setAddress(address);
ReferenceParametersType refParams = new ReferenceParametersType();
refParams.getAny().add(new JAXBElement<String>(new QName("ServiceGroupId"), String.class, sessionId));
endpointRef.setReferenceParameters(refParams);
addrProperties.setReplyTo(endpointRef);
endpointRef = new EndpointReferenceType();
address.setValue(endpointUrl);
endpointRef.setAddress(address);
addrProperties.setTo(endpointRef);
reqCtx.put("javax.xml.ws.addressing.context", addrProperties);
I expected something like this:
<h:ReplyTo xmlns:h="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
<ReferenceParameters>
<ServiceGroupId>urn:uuid:8f27332c08854fb09989b2d</ServiceGroupId>
</ReferenceParameters>
</h:ReplyTo>
<h:To xmlns:h="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">
http://...
</h:To>
But again, there was nothing in my SOAP request. What am I missing/doing wrong?
At this point I would also be happy if I could modify the SOAP headers directly and add them by hand. Can I modify the headers before the message is sent using an interceptor?
I'm using CXF 3.1.2, wss4j 2.1.2, Java 1.8 and Spring Boot 1.2.5.
Thank you!