I am pulling my hair out because of this, and I just can't get it to work. I have a web service that I call that generates a security token, which then needs to be passed to subsequent service calls inside the SOAP header. I got this part working fine, but the header part disables me (I created the client using cxf wsdl2java). This is the part to be added:
<wsse:BinarySecurityToken ValueType="XXXX" EncodingType="wsse:Base64Binary" wsu:Id="SecurityToken"> My token </wsse:BinarySecurityToken>
I tried using WSS4JOutInterceptor as follows:
Endpoint endpoint = client.getEndpoint(); Map<String, Object> outProps = new HashMap<String, Object>(); outProps.put("SecurityToken", MY-TOKEN); endpoint.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
but it didnβt work. And I tried directly adding it to the header like this (like this question ):
List<Header> headers = new ArrayList<Header>(); SOAPFactory sf = SOAPFactory.newInstance(); SOAPElement authElement = sf.createElement(new QName(null, "wsse:BinarySecurityToken")); authElement.setAttribute("ValueType", "XXXX"); authElement.setAttribute("EncodingType", "wsse:Base64Binary"); authElement.setAttribute("wsu:Id", "SecurityToken"); authElement.addTextNode(MY-TOKEN); SoapHeader tokenHeader = new SoapHeader( new QName(null, "wsse:BinarySecurityToken"), authElement); headers.add(tokenHeader); ((BindingProvider) service).getRequestContext().put(Header.HEADER_LIST, headers);
and looks almost normal
<soap:Header><BinarySecurityToken EncodingType="wsse:Base64Binary" ValueType="XXXX" wsu:Id="SecurityToken">MY-TOKEN</BinarySecurityToken></soap:Header>
In the BinarySecurityToken part, the wsse: while prefix is ββmissing, and the call fails.
Has anyone gotten something like work - or am I doing this completely wrong?
source share