I am pretty new to SOAP and I would like to learn how to customize SOAP header. More specifically, I am trying to configure my outbound message SOAP header to be compliant with the expected format. The header is going to be used for authentication purposes.
This is what I have so far.
I have set up a method to add the security deader where I am trying to format the header as per specification.
private void addSecurityHeader(SOAPMessageContext messageContext) throws SOAPException {
public static final String WSSE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
public static final String WSSE_SECURITY_NAME = "Security";
public static final String WSSE_NS_PREFIX = "wsse";
public static final String SOAPENV_NS_PREFIX = "soapenv";
SOAPEnvelope envelope = messageContext.getMessage().getSOAPPart().getEnvelope();
SOAPHeader header = messageContext.getMessage().getSOAPPart().getEnvelope().getHeader();
SOAPBody body = messageContext.getMessage().getSOAPPart().getEnvelope().getBody();
// changing prefix to soapenv
envelope.setPrefix(SOAPENV_NS_PREFIX);
header.setPrefix(SOAPENV_NS_PREFIX);
body.setPrefix(SOAPENV_NS_PREFIX);
// adding security Element
Name securityName = soapFactory.createName(WSSE_SECURITY_NAME, WSSE_NS_PREFIX, WSSE_NS);
SOAPHeaderElement securityElement = header.addHeaderElement(securityName);
When I print out the message in Eclipse console, the Security element is in the following format:
<wsse:Security xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1">
But this is the desired format of the Security format:
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
To summarize the issues that I need to address:
1) I need to change the SOAP-ENV to soapenv.
SOAP-ENV:mustUnderstand="1"
should be
soapenv:mustUnderstand="1"
2) I need to remove
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
as it's not needed in this element.
Any tips how to accomplish it would be greatly appreciated.