0

Is there a way to nest/add child elements to SoapHeaderElement? I have looked around to no avail. Need to add a security soap header with the standard Security, UsernameToken, Username and Password.

Similar posts I have looked at:

Add child elements to custom SOAP header in Spring-WS

How to add child element in soap header in java

What I need to add to the SOAP envelope:

<soapenv:Header>
    <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:UsernameToken wsu:Id="">
            <wsse:Username></wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"></wsse:Password>
        </wsse:UsernameToken>
    </wsse:Security>
</soapenv:Header>

I have tried casting to SOAPHeaderElement instead, since that actually has an addChild method, but get a casting error:

java.lang.ClassCastException: org.springframework.ws.soap.axiom.AxiomSoapHeaderElement cannot be cast to javax.xml.soap.SOAPHeaderElement

Any fix to this casting error or workaround otherwise?

user7674254
  • 87
  • 1
  • 3
  • 15
  • 1
    Assuming you are using Spring-WS you should be configuring the security interceptor correctly and these will be added automatically. You shouldn't be manually messing around with adding headers in general. – M. Deinum Aug 28 '19 at 13:49
  • Configured a Wss4jSecurityInterceptor to handle the additional security headers. Much more clean cut than manual entries. Thanks. – user7674254 Sep 30 '19 at 18:11

0 Answers0